Merge "Added @Override annotation above signature"
[aai/champ.git] / src / test / java / org / openecomp / aai / champ / ie / ImportTest.java
1 /**
2  * ============LICENSE_START==========================================
3  * org.onap.aai
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 Amdocs
7  * ===================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *        http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.openecomp.aai.champ.ie;
23
24 import static org.junit.Assert.assertTrue;
25
26 import java.util.Collections;
27 import java.util.Optional;
28
29 import org.junit.Test;
30 import org.openecomp.aai.champ.ChampAPI;
31 import org.openecomp.aai.champ.ChampGraph;
32
33 public class ImportTest {
34
35         private final String GRAPH_NAME = "unit-test";
36
37         @Test
38         public void testGraphMLImport() {
39
40                 final GraphMLImporterExporter importer = new GraphMLImporterExporter();
41                 final ChampAPI api = ChampAPI.Factory.newInstance(ChampGraph.Type.IN_MEMORY);
42
43                 importer.importData(api, getClass().getClassLoader().getResourceAsStream("import-test.graphml"));
44
45                 final ChampGraph graph = api.getGraph(GRAPH_NAME);
46
47                 graph.queryObjects(Collections.emptyMap()).forEach(object -> {
48                         final Optional<String> nameOpt = object.getProperty("name");
49                         final Optional<Boolean> studentOpt = object.getProperty("student");
50                         final Optional<Long> worthOpt = object.getProperty("worth");
51                         final Optional<Integer> ageOpt = object.getProperty("age");
52                         final Optional<Float> heightOpt = object.getProperty("height");
53                         final Optional<Double> weightOpt = object.getProperty("weight");
54                         final Optional<String> favoriteColorOpt = object.getProperty("favoriteColor");
55
56                         final String name = nameOpt.get();
57
58                         if (name.equals("Champ")) {
59                                 assertTrue(!studentOpt.isPresent());
60                                 assertTrue(!ageOpt.isPresent());
61                                 assertTrue(!worthOpt.isPresent());
62                                 assertTrue(!heightOpt.isPresent());
63                                 assertTrue(!weightOpt.isPresent());
64                                 assertTrue(favoriteColorOpt.get().equals("green"));
65                         } else if (name.equals("Max")) {
66                                 assertTrue(!studentOpt.isPresent());
67                                 assertTrue(!ageOpt.isPresent());
68                                 assertTrue(!worthOpt.isPresent());
69                                 assertTrue(!heightOpt.isPresent());
70                                 assertTrue(!weightOpt.isPresent());
71                                 assertTrue(favoriteColorOpt.get().equals("red"));
72                         } else if (name.equals("Ace")) {
73                                 assertTrue(studentOpt.get());
74                                 assertTrue(worthOpt.get().equals(50000L));
75                                 assertTrue(ageOpt.get().equals(21));
76                                 assertTrue(heightOpt.get().equals(72.5f));
77                                 assertTrue(weightOpt.get().equals(180.5d));
78                                 assertTrue(favoriteColorOpt.get().equals("yellow"));
79                         } else if (name.equals("Fido")) {
80                                 assertTrue(!studentOpt.isPresent());
81                                 assertTrue(!ageOpt.isPresent());
82                                 assertTrue(!worthOpt.isPresent());
83                                 assertTrue(!heightOpt.isPresent());
84                                 assertTrue(!weightOpt.isPresent());
85                                 assertTrue(favoriteColorOpt.get().equals("blue"));
86                         } else {
87                                 throw new AssertionError("Unknown object " + name + " - update unit test");
88                         }
89                 });
90
91                 api.shutdown();
92         }
93 }