2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 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
12 * http://www.apache.org/licenses/LICENSE-2.0
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============================================
21 package org.onap.aai.champcore.ie;
23 import static org.junit.Assert.assertTrue;
25 import java.util.Collections;
26 import java.util.Optional;
28 import org.junit.Test;
29 import org.onap.aai.champcore.ChampAPI;
30 import org.onap.aai.champcore.ChampGraph;
31 import org.onap.aai.champcore.exceptions.ChampTransactionException;
33 public class ImportTest {
35 private final String GRAPH_NAME = "unit-test";
38 public void testGraphMLImport() throws ChampTransactionException, AssertionError {
40 final GraphMLImporterExporter importer = new GraphMLImporterExporter();
41 final ChampAPI api = ChampAPI.Factory.newInstance("IN_MEMORY");
43 importer.importData(api, getClass().getClassLoader().getResourceAsStream("import-test.graphml"));
45 final ChampGraph graph = api.getGraph(GRAPH_NAME);
47 graph.queryObjects(Collections.emptyMap(), Optional.empty()).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");
56 final String name = nameOpt.get();
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"));
87 throw new AssertionError("Unknown object " + name + " - update unit test");
95 public void testUndefinedEdgeSourceAndTarget() throws ChampTransactionException, AssertionError {
97 final GraphMLImporterExporter importer = new GraphMLImporterExporter();
98 final ChampAPI api = ChampAPI.Factory.newInstance("IN_MEMORY");
100 importer.importData(api, getClass().getClassLoader().getResourceAsStream("import-test2.graphml"));
102 final ChampGraph graph = api.getGraph(GRAPH_NAME);
104 graph.queryObjects(Collections.emptyMap(), Optional.empty()).forEach(object -> {
105 final Optional<String> nameOpt = object.getProperty("name");
106 assertTrue(!nameOpt.isPresent());