2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.edges;
25 import static org.junit.Assert.*;
27 import java.util.Collection;
29 import org.apache.tinkerpop.gremlin.structure.Direction;
30 import org.junit.Rule;
31 import org.junit.Test;
32 import org.junit.rules.ExpectedException;
33 import org.junit.runner.RunWith;
34 import org.onap.aai.edges.enums.AAIDirection;
35 import org.onap.aai.edges.enums.MultiplicityRule;
36 import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException;
37 import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
38 import org.onap.aai.setup.SchemaLocationsBean;
39 import org.onap.aai.setup.Version;
40 import org.onap.aai.testutils.TestUtilConfigTranslator;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.boot.test.context.SpringBootTest;
43 import org.springframework.test.context.ContextConfiguration;
44 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
46 import com.google.common.collect.Multimap;
48 @RunWith(SpringJUnit4ClassRunner.class)
49 @ContextConfiguration(classes = {SchemaLocationsBean.class, TestUtilConfigTranslator.class, EdgeIngestor.class})
51 public class EdgeIngestorTest {
56 public ExpectedException thrown = ExpectedException.none();
59 public void getRulesTest1() throws EdgeRuleNotFoundException {
60 EdgeRuleQuery q = new EdgeRuleQuery.Builder("foo").build();
61 Multimap<String, EdgeRule> results = ei.getRules(q);
62 assertTrue(results.size() == 5);
63 assertTrue(results.containsKey("bar|foo"));
65 assertTrue(2 == results.get("bar|foo").size());
66 boolean seenLabel1 = false;
67 boolean seenLabel2 = false;
68 for(EdgeRule r : results.get("bar|foo")) {
69 if ("eats".equals(r.getLabel())) {
72 if ("eatz".equals(r.getLabel())) {
76 assertTrue(seenLabel1 && seenLabel2);
78 assertTrue(results.containsKey("baz|foo"));
79 assertTrue(results.containsKey("foo|quux"));
80 assertTrue(results.containsKey("dog|foo"));
84 public void getRulesTest2() throws EdgeRuleNotFoundException {
85 EdgeRuleQuery q = new EdgeRuleQuery.Builder("puppy", "dog").build();
86 Multimap<String, EdgeRule> results = ei.getRules(q);
87 assertTrue(results.size() == 1);
88 assertTrue(results.containsKey("dog|puppy"));
89 Collection<EdgeRule> cr = results.get("dog|puppy");
90 for (EdgeRule r : cr) {
91 assertTrue("dog".equals(r.getFrom()));
92 assertTrue("puppy".equals(r.getTo()));
93 assertTrue("caresFor".equals(r.getLabel()));
94 assertTrue(Direction.OUT.equals(r.getDirection()));
95 assertTrue("One2Many".equalsIgnoreCase(r.getMultiplicityRule().toString()));
96 assertTrue("NONE".equals(r.getContains()));
97 assertTrue("OUT".equals(r.getDeleteOtherV()));
98 assertTrue("NONE".equals(r.getPreventDelete()));
99 assertTrue(r.isDefault());
104 public void getRulesTest3() throws EdgeRuleNotFoundException {
105 EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface").version(Version.V11).build();
106 Multimap<String, EdgeRule> results = ei.getRules(q);
107 assertTrue(results.size() == 4);
108 assertTrue(results.containsKey("lag-interface|l-interface"));
109 assertTrue(results.containsKey("l-interface|logical-link"));
110 assertTrue(results.get("l-interface|logical-link").size() == 3);
114 public void getRulesNoneFound() throws EdgeRuleNotFoundException {
115 thrown.expect(EdgeRuleNotFoundException.class);
116 thrown.expectMessage("No rules found for");
117 EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface").build();
122 public void getRuleSimpleTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
123 EdgeRuleQuery q = new EdgeRuleQuery.Builder("notation", "parent").build();
124 EdgeRule result = ei.getRule(q);
125 assertTrue("parent".equals(result.getFrom()));
126 assertTrue("notation".equals(result.getTo()));
127 assertTrue("has".equals(result.getLabel()));
128 assertTrue(Direction.OUT.equals(result.getDirection()));
129 assertTrue(MultiplicityRule.MANY2MANY.equals(result.getMultiplicityRule()));
130 assertTrue(AAIDirection.OUT.toString().equals(result.getContains()));
131 assertTrue(AAIDirection.NONE.toString().equals(result.getDeleteOtherV()));
132 assertTrue(AAIDirection.NONE.toString().equals(result.getPreventDelete()));
133 assertTrue("parent contains notation".equals(result.getDescription()));
137 public void getRuleWithDefaultTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
138 EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface","logical-link").version(Version.V11).build();
139 EdgeRule res = ei.getRule(q);
140 assertTrue(res.isDefault());
141 assertTrue("tosca.relationships.network.LinksTo".equals(res.getLabel()));
145 public void getRuleWithNonDefault() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
146 EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface","logical-link").label("org.onap.relationships.inventory.Source").version(Version.V11).build();
147 EdgeRule res = ei.getRule(q);
148 assertFalse(res.isDefault());
149 assertTrue("org.onap.relationships.inventory.Source".equals(res.getLabel()));
153 public void getRuleNoneFoundTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
154 thrown.expect(EdgeRuleNotFoundException.class);
155 thrown.expectMessage("No rule found for");
156 EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface","nonexistent").build();
161 public void getRuleTooManyPairsTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
162 thrown.expect(AmbiguousRuleChoiceException.class);
163 thrown.expectMessage("No way to select single rule from these pairs:");
164 EdgeRuleQuery q = new EdgeRuleQuery.Builder("foo").build();
169 public void getRuleAmbiguousDefaultTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
170 thrown.expect(AmbiguousRuleChoiceException.class);
171 thrown.expectMessage("Multiple defaults found.");
172 EdgeRuleQuery q = new EdgeRuleQuery.Builder("seed","plant").version(Version.V11).build();
177 public void getRuleNoDefaultTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
178 thrown.expect(AmbiguousRuleChoiceException.class);
179 thrown.expectMessage("No default found.");
180 EdgeRuleQuery q = new EdgeRuleQuery.Builder("apple", "orange").version(Version.V11).build();
185 public void hasRuleTest() {
186 assertTrue(ei.hasRule(new EdgeRuleQuery.Builder("l-interface").version(Version.V11).build()));
187 assertFalse(ei.hasRule(new EdgeRuleQuery.Builder("l-interface").build()));
191 public void getCousinRulesTest() {
192 Multimap<String, EdgeRule> results = ei.getCousinRules("dog");
193 assertTrue(results.size() == 2);
194 assertTrue(results.containsKey("dog|puppy"));
195 assertTrue(results.containsKey("dog|foo"));
199 public void getCousinRulesWithVersionTest() {
200 Multimap<String, EdgeRule> results = ei.getCousinRules("foo", Version.V10);
201 assertTrue(results.size() == 2);
202 assertTrue(results.containsKey("bar|foo"));
203 assertTrue(results.get("bar|foo").size() == 2);
207 public void getCousinsNoneInVersionTest() {
208 Multimap<String, EdgeRule> results = ei.getCousinRules("foo", Version.V11);
209 assertTrue(results.isEmpty());
213 public void hasCousinTest() {
214 assertTrue(ei.hasCousinRule("foo"));
215 assertTrue(ei.hasCousinRule("foo", Version.V10));
216 assertFalse(ei.hasCousinRule("parent"));
217 assertFalse(ei.hasCousinRule("foo", Version.V11));
221 public void getChildRulesTest() {
222 Multimap<String, EdgeRule> results = ei.getChildRules("parent");
223 assertTrue(results.size() == 6);
224 assertTrue(results.containsKey("notation|parent"));
225 assertTrue(results.containsKey("not-notation|parent"));
226 assertTrue(results.containsKey("out-out|parent"));
227 assertTrue(results.containsKey("in-in|parent"));
228 assertTrue(results.containsKey("in-out|parent"));
229 assertTrue(results.containsKey("out-in|parent"));
233 public void getChildRulesWithVersionTest() {
234 Multimap<String, EdgeRule> results = ei.getChildRules("foo", Version.V10);
235 assertTrue(results.size() == 2);
236 assertTrue(results.containsKey("baz|foo"));
237 assertTrue(results.containsKey("foo|quux"));
241 public void getChildRulesNoneInVersionTest() {
242 Multimap<String, EdgeRule> results = ei.getChildRules("foo", Version.V11);
243 assertTrue(results.isEmpty());
247 public void hasChildTest() {
248 assertTrue(ei.hasChildRule("foo"));
249 assertTrue(ei.hasChildRule("foo", Version.V10));
250 assertFalse(ei.hasChildRule("puppy"));
251 assertFalse(ei.hasChildRule("foo", Version.V11));
255 public void getParentRulesTest() {
256 Multimap<String, EdgeRule> results = ei.getParentRules("parent");
257 assertTrue(results.size() == 6);
258 assertTrue(results.containsKey("grandparent1|parent"));
259 assertTrue(results.containsKey("grandparent2|parent"));
260 assertTrue(results.containsKey("grandparent3|parent"));
261 assertTrue(results.containsKey("grandparent4|parent"));
262 assertTrue(results.containsKey("grandparent5|parent"));
263 assertTrue(results.containsKey("grandparent6|parent"));
267 public void getParentRulesWithVersionTest() {
268 Multimap<String, EdgeRule> results = ei.getParentRules("baz", Version.V10);
269 assertTrue(results.size() == 1);
270 assertTrue(results.containsKey("baz|foo"));
274 public void getParentRulesNoneInVersionTest() {
275 Multimap<String, EdgeRule> results = ei.getParentRules("baz", Version.V11);
276 assertTrue(results.isEmpty());
280 public void hasParentTest() {
281 assertTrue(ei.hasParentRule("parent"));
282 assertTrue(ei.hasParentRule("quux", Version.V10));
283 assertFalse(ei.hasParentRule("puppy"));
284 assertFalse(ei.hasParentRule("foo", Version.V11));
288 public void getAllCurrentRulesTest() throws EdgeRuleNotFoundException {
289 Multimap<String, EdgeRule> res = ei.getAllCurrentRules();
290 assertTrue(res.size() == 18);
294 public void getAllRulesTest() throws EdgeRuleNotFoundException {
295 Multimap<String, EdgeRule> res = ei.getAllRules(Version.V10);
296 assertTrue(res.size() == 4);
297 assertTrue(res.containsKey("bar|foo"));
298 assertTrue(res.get("bar|foo").size() == 2);
299 assertTrue(res.containsKey("baz|foo"));
300 assertTrue(res.containsKey("foo|quux"));
302 thrown.expect(EdgeRuleNotFoundException.class);
303 thrown.expectMessage("No rules found for version V9.");
304 ei.getAllRules(Version.V9);