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