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.util.genxsd;
22 import static org.hamcrest.CoreMatchers.is;
23 import static org.junit.Assert.*;
25 import java.io.BufferedWriter;
27 import java.io.FileWriter;
28 import java.util.Arrays;
29 import java.util.List;
31 import java.util.SortedSet;
32 import java.util.TreeSet;
34 import org.junit.AfterClass;
35 import org.junit.Before;
36 import org.junit.BeforeClass;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.onap.aai.edges.EdgeIngestor;
40 import org.onap.aai.edges.EdgeRule;
41 import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
42 import org.onap.aai.setup.ConfigTranslator;
43 import org.onap.aai.setup.SchemaLocationsBean;
44 import org.onap.aai.setup.SchemaVersion;
45 import org.onap.aai.setup.SchemaVersions;
46 import org.onap.aai.testutils.TestUtilConfigTranslatorforEdges;
47 import org.springframework.beans.factory.annotation.Autowired;
48 import org.springframework.test.context.ContextConfiguration;
49 import org.springframework.test.context.TestPropertySource;
50 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
52 import com.google.common.collect.Multimap;
54 @RunWith(SpringJUnit4ClassRunner.class)
55 @ContextConfiguration(classes = {SchemaVersions.class, SchemaLocationsBean.class, TestUtilConfigTranslatorforEdges.class, EdgeIngestor.class})
56 @TestPropertySource(properties = {"schemaIngestPropLoc = src/test/resources/schemaIngest/schemaIngestTest.properties"})
59 public class EdgeDescriptionTest {
60 private static final String EDGEFILENAME = "src/test/resources/dbedgerules/EdgeDescriptionRules_test.json";
64 EdgeIngestor edgeIngestor;
65 String nodeName = "availability-zone";
66 String toNode = "complex";
67 SchemaVersion v10 = new SchemaVersion("v10");
69 public static void setUpBeforeClass() throws Exception {
73 + " \"from\": \"availability-zone\","
74 + " \"to\": \"complex\","
75 + " \"label\": \"org.onap.relationships.inventory.LocatedIn\","
76 + " \"direction\": \"OUT\","
77 + " \"multiplicity\": \"MANY2ONE\","
78 + " \"contains-other-v\": \"NONE\","
79 + " \"delete-other-v\": \"NONE\","
80 + " \"SVC-INFRA\": \"NONE\","
81 + " \"prevent-delete\": \"!${direction}\","
82 + " \"default\": \"true\","
83 + " \"description\":\"this description\""
86 + " \"from\": \"availability-zone\","
87 + " \"to\": \"service-capability\","
88 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
89 + " \"direction\": \"OUT\","
90 + " \"multiplicity\": \"MANY2MANY\","
91 + " \"contains-other-v\": \"NONE\","
92 + " \"delete-other-v\": \"NONE\","
93 + " \"SVC-INFRA\": \"NONE\","
94 + " \"prevent-delete\": \"!${direction}\","
95 + " \"default\": \"true\","
96 + " \"description\":\"\""
99 + " \"from\": \"availability-zone\","
100 + " \"to\": \"cloud-region\","
101 + " \"label\": \"org.onap.relationships.inventory.BelongsTo\","
102 + " \"direction\": \"OUT\","
103 + " \"multiplicity\": \"MANY2ONE\","
104 + " \"contains-other-v\": \"!${direction}\","
105 + " \"delete-other-v\": \"!${direction}\","
106 + " \"SVC-INFRA\": \"NONE\","
107 + " \"prevent-delete\": \"NONE\","
108 + " \"default\": \"true\","
109 + " \"description\":\"\""
112 + " \"from\": \"ctag-pool\","
113 + " \"to\": \"availability-zone\","
114 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
115 + " \"direction\": \"OUT\","
116 + " \"multiplicity\": \"MANY2MANY\","
117 + " \"contains-other-v\": \"${direction}\","
118 + " \"delete-other-v\": \"NONE\","
119 + " \"SVC-INFRA\": \"NONE\","
120 + " \"prevent-delete\": \"!${direction}\","
121 + " \"default\": \"true\","
122 + " \"description\":\"\""
125 + " \"from\": \"dvs-switch\","
126 + " \"to\": \"availability-zone\","
127 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
128 + " \"direction\": \"OUT\","
129 + " \"multiplicity\": \"MANY2MANY\","
130 + " \"contains-other-v\": \"NONE\","
131 + " \"delete-other-v\": \"NONE\","
132 + " \"SVC-INFRA\": \"NONE\","
133 + " \"prevent-delete\": \"!${direction}\","
134 + " \"default\": \"true\","
135 + " \"description\":\"\""
138 + " \"from\": \"generic-vnf\","
139 + " \"to\": \"availability-zone\","
140 + " \"label\": \"org.onap.relationships.inventory.Uses\","
141 + " \"direction\": \"OUT\","
142 + " \"multiplicity\": \"MANY2MANY\","
143 + " \"contains-other-v\": \"NONE\","
144 + " \"delete-other-v\": \"NONE\","
145 + " \"SVC-INFRA\": \"${direction}\","
146 + " \"prevent-delete\": \"!${direction}\","
147 + " \"default\": \"true\","
148 + " \"description\":\"\""
151 + " \"from\": \"pserver\","
152 + " \"to\": \"availability-zone\","
153 + " \"label\": \"org.onap.relationships.inventory.MemberOf\","
154 + " \"direction\": \"OUT\","
155 + " \"multiplicity\": \"MANY2ONE\","
156 + " \"contains-other-v\": \"NONE\","
157 + " \"delete-other-v\": \"NONE\","
158 + " \"SVC-INFRA\": \"${direction}\","
159 + " \"prevent-delete\": \"!${direction}\","
160 + " \"default\": \"true\","
161 + " \"description\":\"\""
164 + " \"from\": \"vce\","
165 + " \"to\": \"availability-zone\","
166 + " \"label\": \"org.onap.relationships.inventory.Uses\","
167 + " \"direction\": \"OUT\","
168 + " \"multiplicity\": \"MANY2MANY\","
169 + " \"contains-other-v\": \"NONE\","
170 + " \"delete-other-v\": \"NONE\","
171 + " \"SVC-INFRA\": \"NONE\","
172 + " \"prevent-delete\": \"!${direction}\","
173 + " \"default\": \"true\","
174 + " \"description\":\"\""
177 BufferedWriter bw = new BufferedWriter(new FileWriter(EDGEFILENAME));
182 public static void tearDownAfterClass() throws Exception {
183 File edges = new File(EDGEFILENAME);
187 public void setUp() throws Exception {
193 Map<SchemaVersion, List<String>> edges = ct.getEdgeFiles();
194 assertTrue(edges.containsKey(v10));
195 assertTrue(1 == edges.get(v10).size());
196 assertTrue("src/test/resources/dbedgerules/DbEdgeBusinessRules_test.json".equals(edges.get(v10).get(0)));
199 public void testGetDeleteOtherV() throws EdgeRuleNotFoundException {
200 String target = "availability-zone"+"|"+toNode+"-"+"NONE";
201 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
202 SortedSet<String> ss=new TreeSet<String>(results.keySet());
203 for(String key : ss) {
204 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)); } );
209 public void testGetPreventDelete() throws EdgeRuleNotFoundException {
210 String target = "availability-zone"+"|"+toNode+"-"+"IN";
211 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
212 SortedSet<String> ss=new TreeSet<String>(results.keySet());
213 for(String key : ss) {
214 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)); } );
219 public void testGetAlsoDeleteFootnote() throws EdgeRuleNotFoundException {
220 // String toNode="cloud-region";
221 // String target = "availability-zone"+"|"+toNode+"-"+"(4)";
222 List<String> notedTypes = Arrays.asList("cloud-region", "ctag-pool");
223 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
224 SortedSet<String> ss=new TreeSet<String>(results.keySet());
225 for(String key : ss) {
226 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)); } );
229 for (EdgeDescription ed : edges) {
230 String modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getFrom());
231 assertThat(modResult, is(target));
232 ed.setDeleteOtherV("IN");
233 target = "availability-zone"+"|"+"complex"+"-"+"(4)";
234 modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getFrom());
235 assertThat(modResult, is(target));
236 target = "availability-zone"+"|"+"complex"+"-"+"(1)";
237 modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getTo());
238 assertThat(modResult, is(target));
239 ed.setDeleteOtherV("OUT");
240 target = "availability-zone"+"|"+"complex"+"-"+"(2)";
241 modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getFrom());
242 assertThat(modResult, is(target));
243 target = "availability-zone"+"|"+"complex"+"-"+"(3)";
244 modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getTo());
245 assertThat(modResult, is(target));
251 public void testGetTo() throws EdgeRuleNotFoundException {
252 String target = "availability-zone"+"|"+toNode+"-"+toNode;
253 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
254 SortedSet<String> ss=new TreeSet<String>(results.keySet());
255 for(String key : ss) {
256 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)); } );
261 public void testGetFrom() throws EdgeRuleNotFoundException {
262 String target = "availability-zone"+"|"+toNode+"-"+"availability-zone";
263 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
264 SortedSet<String> ss=new TreeSet<String>(results.keySet());
265 for(String key : ss) {
266 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)); } );
271 public void testGetRuleKey() throws EdgeRuleNotFoundException {
272 String target = "availability-zone"+"|"+toNode;
273 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
274 SortedSet<String> ss=new TreeSet<String>(results.keySet());
275 for(String key : ss) {
276 results.get(key).stream().filter((i) -> (i.getTo().equals(toNode) && (! i.isPrivateEdge()))).forEach((i) ->{ EdgeDescription ed = new EdgeDescription(i); assertThat(ed.getRuleKey(), is(target)); } );
281 public void testGetMultiplicity() throws EdgeRuleNotFoundException {
282 String target = "availability-zone"+"|"+toNode+"-"+"MANY2ONE";
283 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
284 SortedSet<String> ss=new TreeSet<String>(results.keySet());
285 for(String key : ss) {
286 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)); } );
291 public void testGetDirection() throws EdgeRuleNotFoundException {
292 String target = "availability-zone"+"|"+toNode+"-"+"OUT";
293 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
294 SortedSet<String> ss=new TreeSet<String>(results.keySet());
295 for(String key : ss) {
296 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)); } );
301 public void testGetDescription() throws EdgeRuleNotFoundException {
302 String target = "availability-zone"+"|"+toNode+"-"+"this description";
303 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
304 SortedSet<String> ss=new TreeSet<String>(results.keySet());
305 for(String key : ss) {
306 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)); } );
311 public void testGetRelationshipDescription() throws EdgeRuleNotFoundException {
312 String target = "availability-zone"+"|"+toNode+"-"+"this description";
313 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
314 SortedSet<String> ss=new TreeSet<String>(results.keySet());
315 for(String key : ss) {
316 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)); } );
321 public void testGetType() throws EdgeRuleNotFoundException {
322 String toNode = "cloud-region";
323 String target = "availability-zone"+"|"+toNode+"-"+"PARENT";
324 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
325 SortedSet<String> ss=new TreeSet<String>(results.keySet());
326 for(String key : ss) {
327 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)); } );
332 public void testGetLabel() throws EdgeRuleNotFoundException {
333 String target = "availability-zone"+"|"+toNode+"-"+"org.onap.relationships.inventory.LocatedIn";
334 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
335 SortedSet<String> ss=new TreeSet<String>(results.keySet());
336 for(String key : ss) {
337 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)); } );
342 public void testGetShortLabel() throws EdgeRuleNotFoundException {
343 String target = "availability-zone"+"|"+toNode+"-"+"LocatedIn";
344 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
345 SortedSet<String> ss=new TreeSet<String>(results.keySet());
346 for(String key : ss) {
347 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)); } );