aboutsummaryrefslogtreecommitdiffstats
path: root/champ-lib/champ-core/src/test/java/org/onap/aai/champcore/ie/ImportTest.java
blob: 756d4ca2c24776ad7f3402b61fbf79407025e925 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
 * ============LICENSE_START==========================================
 * org.onap.aai
 * ===================================================================
 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
 * Copyright © 2017-2018 Amdocs
 * ===================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END============================================
 */
package org.onap.aai.champcore.ie;

import static org.junit.Assert.assertTrue;

import java.util.Collections;
import java.util.Optional;

import org.junit.Test;
import org.onap.aai.champcore.ChampAPI;
import org.onap.aai.champcore.ChampGraph;
import org.onap.aai.champcore.exceptions.ChampTransactionException;

public class ImportTest {

	private final String GRAPH_NAME = "unit-test";

	@Test
	public void testGraphMLImport() throws ChampTransactionException, AssertionError {

		final GraphMLImporterExporter importer = new GraphMLImporterExporter();
		final ChampAPI api = ChampAPI.Factory.newInstance("IN_MEMORY");

		importer.importData(api, getClass().getClassLoader().getResourceAsStream("import-test.graphml"));

		final ChampGraph graph = api.getGraph(GRAPH_NAME);

		graph.queryObjects(Collections.emptyMap(), Optional.empty()).forEach(object -> {
			final Optional<String> nameOpt = object.getProperty("name");
			final Optional<Boolean> studentOpt = object.getProperty("student");
			final Optional<Long> worthOpt = object.getProperty("worth");
			final Optional<Integer> ageOpt = object.getProperty("age");
			final Optional<Float> heightOpt = object.getProperty("height");
			final Optional<Double> weightOpt = object.getProperty("weight");
			final Optional<String> favoriteColorOpt = object.getProperty("favoriteColor");

			final String name = nameOpt.get();

			if (name.equals("Champ")) {
				assertTrue(!studentOpt.isPresent());
				assertTrue(!ageOpt.isPresent());
				assertTrue(!worthOpt.isPresent());
				assertTrue(!heightOpt.isPresent());
				assertTrue(!weightOpt.isPresent());
				assertTrue(favoriteColorOpt.get().equals("green"));
			} else if (name.equals("Max")) {
				assertTrue(!studentOpt.isPresent());
				assertTrue(!ageOpt.isPresent());
				assertTrue(!worthOpt.isPresent());
				assertTrue(!heightOpt.isPresent());
				assertTrue(!weightOpt.isPresent());
				assertTrue(favoriteColorOpt.get().equals("red"));
			} else if (name.equals("Ace")) {
				assertTrue(studentOpt.get());
				assertTrue(worthOpt.get().equals(50000L));
				assertTrue(ageOpt.get().equals(21));
				assertTrue(heightOpt.get().equals(72.5f));
				assertTrue(weightOpt.get().equals(180.5d));
				assertTrue(favoriteColorOpt.get().equals("yellow"));
			} else if (name.equals("Fido")) {
				assertTrue(!studentOpt.isPresent());
				assertTrue(!ageOpt.isPresent());
				assertTrue(!worthOpt.isPresent());
				assertTrue(!heightOpt.isPresent());
				assertTrue(!weightOpt.isPresent());
				assertTrue(favoriteColorOpt.get().equals("blue"));
			} else {
				throw new AssertionError("Unknown object " + name + " - update unit test");
			}
		});

		api.shutdown();
	}
	
	 @Test
	  public void testUndefinedEdgeSourceAndTarget() throws ChampTransactionException, AssertionError {

	    final GraphMLImporterExporter importer = new GraphMLImporterExporter();
	    final ChampAPI api = ChampAPI.Factory.newInstance("IN_MEMORY");

	    importer.importData(api, getClass().getClassLoader().getResourceAsStream("import-test2.graphml"));

	    final ChampGraph graph = api.getGraph(GRAPH_NAME);

	    graph.queryObjects(Collections.emptyMap(), Optional.empty()).forEach(object -> {
	      final Optional<String> nameOpt = object.getProperty("name");
	      assertTrue(!nameOpt.isPresent());
	    });

	    api.shutdown();
	  }
}