2 * ============LICENSE_START==========================================
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
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============================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.champcore.ie;
24 import static org.junit.Assert.assertTrue;
26 import java.util.Collections;
27 import java.util.Optional;
29 import org.junit.Test;
30 import org.onap.aai.champcore.ChampAPI;
31 import org.onap.aai.champcore.ChampGraph;
32 import org.onap.aai.champcore.exceptions.ChampTransactionException;
34 public class ImportTest {
36 private final String GRAPH_NAME = "unit-test";
39 public void testGraphMLImport() throws ChampTransactionException, AssertionError {
41 final GraphMLImporterExporter importer = new GraphMLImporterExporter();
42 final ChampAPI api = ChampAPI.Factory.newInstance("IN_MEMORY");
44 importer.importData(api, getClass().getClassLoader().getResourceAsStream("import-test.graphml"));
46 final ChampGraph graph = api.getGraph(GRAPH_NAME);
48 graph.queryObjects(Collections.emptyMap(), Optional.empty()).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");
57 final String name = nameOpt.get();
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"));
88 throw new AssertionError("Unknown object " + name + " - update unit test");