2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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 package org.onap.aai.schemagen.genxsd;
22 import com.google.common.collect.Multimap;
23 import org.junit.AfterClass;
24 import org.junit.Before;
25 import org.junit.BeforeClass;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.onap.aai.edges.EdgeIngestor;
29 import org.onap.aai.edges.EdgeRule;
30 import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
31 import org.onap.aai.schemagen.testutils.TestUtilConfigTranslatorforEdges;
32 import org.onap.aai.setup.ConfigTranslator;
33 import org.onap.aai.setup.SchemaLocationsBean;
34 import org.onap.aai.setup.SchemaVersion;
35 import org.onap.aai.setup.SchemaVersions;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.test.context.ContextConfiguration;
38 import org.springframework.test.context.TestPropertySource;
39 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
41 import java.io.BufferedWriter;
43 import java.io.FileWriter;
46 import static org.hamcrest.CoreMatchers.is;
47 import static org.junit.Assert.assertThat;
48 import static org.junit.Assert.assertTrue;
50 @RunWith(SpringJUnit4ClassRunner.class)
51 @ContextConfiguration(classes = {SchemaVersions.class, SchemaLocationsBean.class, TestUtilConfigTranslatorforEdges.class, EdgeIngestor.class})
52 @TestPropertySource(properties = {"schemaIngestPropLoc = src/test/resources/schemaIngest/schemaIngestTest.properties"})
55 public class EdgeDescriptionTest {
56 private static final String EDGEFILENAME = "src/test/resources/dbedgerules/EdgeDescriptionRules_test.json";
60 EdgeIngestor edgeIngestor;
61 String nodeName = "availability-zone";
62 String toNode = "complex";
63 SchemaVersion v10 = new SchemaVersion("v10");
65 public static void setUpBeforeClass() throws Exception {
69 + " \"from\": \"availability-zone\","
70 + " \"to\": \"complex\","
71 + " \"label\": \"org.onap.relationships.inventory.LocatedIn\","
72 + " \"direction\": \"OUT\","
73 + " \"multiplicity\": \"MANY2ONE\","
74 + " \"contains-other-v\": \"NONE\","
75 + " \"delete-other-v\": \"NONE\","
76 + " \"SVC-INFRA\": \"NONE\","
77 + " \"prevent-delete\": \"!${direction}\","
78 + " \"default\": \"true\","
79 + " \"description\":\"this description\""
82 + " \"from\": \"availability-zone\","
83 + " \"to\": \"service-capability\","
84 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
85 + " \"direction\": \"OUT\","
86 + " \"multiplicity\": \"MANY2MANY\","
87 + " \"contains-other-v\": \"NONE\","
88 + " \"delete-other-v\": \"NONE\","
89 + " \"SVC-INFRA\": \"NONE\","
90 + " \"prevent-delete\": \"!${direction}\","
91 + " \"default\": \"true\","
92 + " \"description\":\"\""
95 + " \"from\": \"availability-zone\","
96 + " \"to\": \"cloud-region\","
97 + " \"label\": \"org.onap.relationships.inventory.BelongsTo\","
98 + " \"direction\": \"OUT\","
99 + " \"multiplicity\": \"MANY2ONE\","
100 + " \"contains-other-v\": \"!${direction}\","
101 + " \"delete-other-v\": \"!${direction}\","
102 + " \"SVC-INFRA\": \"NONE\","
103 + " \"prevent-delete\": \"NONE\","
104 + " \"default\": \"true\","
105 + " \"description\":\"\""
108 + " \"from\": \"ctag-pool\","
109 + " \"to\": \"availability-zone\","
110 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
111 + " \"direction\": \"OUT\","
112 + " \"multiplicity\": \"MANY2MANY\","
113 + " \"contains-other-v\": \"${direction}\","
114 + " \"delete-other-v\": \"NONE\","
115 + " \"SVC-INFRA\": \"NONE\","
116 + " \"prevent-delete\": \"!${direction}\","
117 + " \"default\": \"true\","
118 + " \"description\":\"\""
121 + " \"from\": \"dvs-switch\","
122 + " \"to\": \"availability-zone\","
123 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
124 + " \"direction\": \"OUT\","
125 + " \"multiplicity\": \"MANY2MANY\","
126 + " \"contains-other-v\": \"NONE\","
127 + " \"delete-other-v\": \"NONE\","
128 + " \"SVC-INFRA\": \"NONE\","
129 + " \"prevent-delete\": \"!${direction}\","
130 + " \"default\": \"true\","
131 + " \"description\":\"\""
134 + " \"from\": \"generic-vnf\","
135 + " \"to\": \"availability-zone\","
136 + " \"label\": \"org.onap.relationships.inventory.Uses\","
137 + " \"direction\": \"OUT\","
138 + " \"multiplicity\": \"MANY2MANY\","
139 + " \"contains-other-v\": \"NONE\","
140 + " \"delete-other-v\": \"NONE\","
141 + " \"SVC-INFRA\": \"${direction}\","
142 + " \"prevent-delete\": \"!${direction}\","
143 + " \"default\": \"true\","
144 + " \"description\":\"\""
147 + " \"from\": \"pserver\","
148 + " \"to\": \"availability-zone\","
149 + " \"label\": \"org.onap.relationships.inventory.MemberOf\","
150 + " \"direction\": \"OUT\","
151 + " \"multiplicity\": \"MANY2ONE\","
152 + " \"contains-other-v\": \"NONE\","
153 + " \"delete-other-v\": \"NONE\","
154 + " \"SVC-INFRA\": \"${direction}\","
155 + " \"prevent-delete\": \"!${direction}\","
156 + " \"default\": \"true\","
157 + " \"description\":\"\""
160 + " \"from\": \"vce\","
161 + " \"to\": \"availability-zone\","
162 + " \"label\": \"org.onap.relationships.inventory.Uses\","
163 + " \"direction\": \"OUT\","
164 + " \"multiplicity\": \"MANY2MANY\","
165 + " \"contains-other-v\": \"NONE\","
166 + " \"delete-other-v\": \"NONE\","
167 + " \"SVC-INFRA\": \"NONE\","
168 + " \"prevent-delete\": \"!${direction}\","
169 + " \"default\": \"true\","
170 + " \"description\":\"\""
173 BufferedWriter bw = new BufferedWriter(new FileWriter(EDGEFILENAME));
178 public static void tearDownAfterClass() throws Exception {
179 File edges = new File(EDGEFILENAME);
183 public void setUp() throws Exception {
189 Map<SchemaVersion, List<String>> edges = ct.getEdgeFiles();
190 assertTrue(edges.containsKey(v10));
191 assertTrue(1 == edges.get(v10).size());
192 assertTrue("src/test/resources/dbedgerules/DbEdgeBusinessRules_test.json".equals(edges.get(v10).get(0)));
195 public void testGetDeleteOtherV() throws EdgeRuleNotFoundException {
196 String target = "availability-zone"+"|"+toNode+"-"+"NONE";
197 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
198 SortedSet<String> ss=new TreeSet<String>(results.keySet());
199 for(String key : ss) {
200 results.get(key).stream().filter((i) -> (i.getTo().equals(toNode) && (! i.isPrivateEdge()))).forEach((i) ->{ EdgeDescription ed = new EdgeDescription(i); assertThat(ed.getRuleKey()+"-"+ed.getDeleteOtherV(), is(target)); } );
205 public void testGetPreventDelete() throws EdgeRuleNotFoundException {
206 String target = "availability-zone"+"|"+toNode+"-"+"IN";
207 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
208 SortedSet<String> ss=new TreeSet<String>(results.keySet());
209 for(String key : ss) {
210 results.get(key).stream().filter((i) -> (i.getTo().equals(toNode) && (! i.isPrivateEdge()))).forEach((i) ->{ EdgeDescription ed = new EdgeDescription(i); assertThat(ed.getRuleKey()+"-"+ed.getPreventDelete(), is(target)); } );
215 public void testGetAlsoDeleteFootnote() throws EdgeRuleNotFoundException {
216 // String toNode="cloud-region";
217 // String target = "availability-zone"+"|"+toNode+"-"+"(4)";
218 List<String> notedTypes = Arrays.asList("cloud-region", "ctag-pool");
219 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
220 SortedSet<String> ss=new TreeSet<String>(results.keySet());
221 for(String key : ss) {
222 results.get(key).stream().filter((i) -> (i.getTo().equals("availability-zone") && (! i.isPrivateEdge()))).forEach((i) ->{ EdgeDescription ed = new EdgeDescription(i); String target = ed.getRuleKey()+"-"+(notedTypes.contains(ed.getTo()) ? "(4)" : ""); assertThat(ed.getRuleKey()+"-"+ed.getAlsoDeleteFootnote(ed.getFrom()), is(target)); } );
225 for (EdgeDescription ed : edges) {
226 String modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getFrom());
227 assertThat(modResult, is(target));
228 ed.setDeleteOtherV("IN");
229 target = "availability-zone"+"|"+"complex"+"-"+"(4)";
230 modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getFrom());
231 assertThat(modResult, is(target));
232 target = "availability-zone"+"|"+"complex"+"-"+"(1)";
233 modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getTo());
234 assertThat(modResult, is(target));
235 ed.setDeleteOtherV("OUT");
236 target = "availability-zone"+"|"+"complex"+"-"+"(2)";
237 modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getFrom());
238 assertThat(modResult, is(target));
239 target = "availability-zone"+"|"+"complex"+"-"+"(3)";
240 modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getTo());
241 assertThat(modResult, is(target));
247 public void testGetTo() throws EdgeRuleNotFoundException {
248 String target = "availability-zone"+"|"+toNode+"-"+toNode;
249 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
250 SortedSet<String> ss=new TreeSet<String>(results.keySet());
251 for(String key : ss) {
252 results.get(key).stream().filter((i) -> (i.getTo().equals(toNode) && (! i.isPrivateEdge()))).forEach((i) ->{ EdgeDescription ed = new EdgeDescription(i); assertThat(ed.getRuleKey()+"-"+ed.getTo(), is(target)); } );
257 public void testGetFrom() throws EdgeRuleNotFoundException {
258 String target = "availability-zone"+"|"+toNode+"-"+"availability-zone";
259 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
260 SortedSet<String> ss=new TreeSet<String>(results.keySet());
261 for(String key : ss) {
262 results.get(key).stream().filter((i) -> (i.getTo().equals(toNode) && (! i.isPrivateEdge()))).forEach((i) ->{ EdgeDescription ed = new EdgeDescription(i); assertThat(ed.getRuleKey()+"-"+ed.getFrom(), is(target)); } );
267 public void testGetRuleKey() throws EdgeRuleNotFoundException {
268 String target = "availability-zone"+"|"+toNode;
269 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
270 SortedSet<String> ss=new TreeSet<String>(results.keySet());
271 for(String key : ss) {
272 results.get(key).stream().filter((i) -> (i.getTo().equals(toNode) && (! i.isPrivateEdge()))).forEach((i) ->{ EdgeDescription ed = new EdgeDescription(i); assertThat(ed.getRuleKey(), is(target)); } );
277 public void testGetMultiplicity() throws EdgeRuleNotFoundException {
278 String target = "availability-zone"+"|"+toNode+"-"+"MANY2ONE";
279 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
280 SortedSet<String> ss=new TreeSet<String>(results.keySet());
281 for(String key : ss) {
282 results.get(key).stream().filter((i) -> (i.getTo().equals(toNode) && (! i.isPrivateEdge()))).forEach((i) ->{ EdgeDescription ed = new EdgeDescription(i); assertThat(ed.getRuleKey()+"-"+ed.getMultiplicity(), is(target)); } );
287 public void testGetDirection() throws EdgeRuleNotFoundException {
288 String target = "availability-zone"+"|"+toNode+"-"+"OUT";
289 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
290 SortedSet<String> ss=new TreeSet<String>(results.keySet());
291 for(String key : ss) {
292 results.get(key).stream().filter((i) -> (i.getTo().equals(toNode) && (! i.isPrivateEdge()))).forEach((i) ->{ EdgeDescription ed = new EdgeDescription(i); assertThat(ed.getRuleKey()+"-"+ed.getDirection(), is(target)); } );
297 public void testGetDescription() throws EdgeRuleNotFoundException {
298 String target = "availability-zone"+"|"+toNode+"-"+"this description";
299 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
300 SortedSet<String> ss=new TreeSet<String>(results.keySet());
301 for(String key : ss) {
302 results.get(key).stream().filter((i) -> (i.getTo().equals(toNode) && (! i.isPrivateEdge()))).forEach((i) ->{ EdgeDescription ed = new EdgeDescription(i); assertThat(ed.getRuleKey()+"-"+ed.getDescription(), is(target)); } );
307 public void testGetRelationshipDescription() throws EdgeRuleNotFoundException {
308 String target = "availability-zone"+"|"+toNode+"-"+"this description";
309 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
310 SortedSet<String> ss=new TreeSet<String>(results.keySet());
311 for(String key : ss) {
312 results.get(key).stream().filter((i) -> (i.getTo().equals(toNode) && (! i.isPrivateEdge()))).forEach((i) ->{ EdgeDescription ed = new EdgeDescription(i); assertThat(ed.getRuleKey()+"-"+ed.getDescription(), is(target)); } );
317 public void testGetType() throws EdgeRuleNotFoundException {
318 String toNode = "cloud-region";
319 String target = "availability-zone"+"|"+toNode+"-"+"PARENT";
320 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
321 SortedSet<String> ss=new TreeSet<String>(results.keySet());
322 for(String key : ss) {
323 results.get(key).stream().filter((i) -> (i.getTo().equals(toNode) && (! i.isPrivateEdge()))).forEach((i) ->{ EdgeDescription ed = new EdgeDescription(i); assertThat(ed.getRuleKey()+"-"+ed.getType(), is(target)); } );
328 public void testGetLabel() throws EdgeRuleNotFoundException {
329 String target = "availability-zone"+"|"+toNode+"-"+"org.onap.relationships.inventory.LocatedIn";
330 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
331 SortedSet<String> ss=new TreeSet<String>(results.keySet());
332 for(String key : ss) {
333 results.get(key).stream().filter((i) -> (i.getTo().equals(toNode) && (! i.isPrivateEdge()))).forEach((i) ->{ EdgeDescription ed = new EdgeDescription(i); assertThat(ed.getRuleKey()+"-"+ed.getLabel(), is(target)); } );
338 public void testGetShortLabel() throws EdgeRuleNotFoundException {
339 String target = "availability-zone"+"|"+toNode+"-"+"LocatedIn";
340 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
341 SortedSet<String> ss=new TreeSet<String>(results.keySet());
342 for(String key : ss) {
343 results.get(key).stream().filter((i) -> (i.getTo().equals(toNode) && (! i.isPrivateEdge()))).forEach((i) ->{ EdgeDescription ed = new EdgeDescription(i); assertThat(ed.getRuleKey()+"-"+ed.getShortLabel(), is(target)); } );