Merge "Added @Override annotation above signature"
[aai/champ.git] / src / test / java / org / onap / 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.onap.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.onap.aai.champ.ChampAPI;
31 import org.onap.aai.champ.ChampGraph;
32 import org.onap.aai.champ.ie.GraphMLImporterExporter;
33
34 public class ImportTest {
35
36         private final String GRAPH_NAME = "unit-test";
37
38         @Test
39         public void testGraphMLImport() {
40
41                 final GraphMLImporterExporter importer = new GraphMLImporterExporter();
42                 final ChampAPI api = ChampAPI.Factory.newInstance(ChampGraph.Type.IN_MEMORY);
43
44                 importer.importData(api, getClass().getClassLoader().getResourceAsStream("import-test.graphml"));
45
46                 final ChampGraph graph = api.getGraph(GRAPH_NAME);
47
48                 graph.queryObjects(Collections.emptyMap()).forEach(object -> {
49                         final Optional<String> nameOpt = object.getProperty("name");
50                         final Optional<Boolean> studentOpt = object.getProperty("student");
51                         final Optional<Long> worthOpt = object.getProperty("worth");
52                         final Optional<Integer> ageOpt = object.getProperty("age");
53                         final Optional<Float> heightOpt = object.getProperty("height");
54                         final Optional<Double> weightOpt = object.getProperty("weight");
55                         final Optional<String> favoriteColorOpt = object.getProperty("favoriteColor");
56
57                         final String name = nameOpt.get();
58
59                         if (name.equals("Champ")) {
60                                 assertTrue(!studentOpt.isPresent());
61                                 assertTrue(!ageOpt.isPresent());
62                                 assertTrue(!worthOpt.isPresent());
63                                 assertTrue(!heightOpt.isPresent());
64                                 assertTrue(!weightOpt.isPresent());
65                                 assertTrue(favoriteColorOpt.get().equals("green"));
66                         } else if (name.equals("Max")) {
67                                 assertTrue(!studentOpt.isPresent());
68                                 assertTrue(!ageOpt.isPresent());
69                                 assertTrue(!worthOpt.isPresent());
70                                 assertTrue(!heightOpt.isPresent());
71                                 assertTrue(!weightOpt.isPresent());
72                                 assertTrue(favoriteColorOpt.get().equals("red"));
73                         } else if (name.equals("Ace")) {
74                                 assertTrue(studentOpt.get());
75                                 assertTrue(worthOpt.get().equals(50000L));
76                                 assertTrue(ageOpt.get().equals(21));
77                                 assertTrue(heightOpt.get().equals(72.5f));
78                                 assertTrue(weightOpt.get().equals(180.5d));
79                                 assertTrue(favoriteColorOpt.get().equals("yellow"));
80                         } else if (name.equals("Fido")) {
81                                 assertTrue(!studentOpt.isPresent());
82                                 assertTrue(!ageOpt.isPresent());
83                                 assertTrue(!worthOpt.isPresent());
84                                 assertTrue(!heightOpt.isPresent());
85                                 assertTrue(!weightOpt.isPresent());
86                                 assertTrue(favoriteColorOpt.get().equals("blue"));
87                         } else {
88                                 throw new AssertionError("Unknown object " + name + " - update unit test");
89                         }
90                 });
91
92                 api.shutdown();
93         }
94 }