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=========================================================
21 package org.onap.aai.schemagen.genxsd;
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.junit.Assert.assertThat;
25 import static org.junit.Assert.assertTrue;
27 import com.google.common.collect.Multimap;
29 import java.io.BufferedWriter;
31 import java.io.FileWriter;
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.schemagen.testutils.TestUtilConfigTranslatorforEdges;
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.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 @RunWith(SpringJUnit4ClassRunner.class)
53 @ContextConfiguration(
54 classes = {SchemaVersions.class, SchemaLocationsBean.class,
55 TestUtilConfigTranslatorforEdges.class, EdgeIngestor.class})
58 "schemaIngestPropLoc = src/test/resources/schemaIngest/schemaIngestTest.properties"})
60 public class EdgeDescriptionTest {
61 private static final String EDGEFILENAME =
62 "src/test/resources/dbedgerules/EdgeDescriptionRules_test.json";
66 EdgeIngestor edgeIngestor;
67 String nodeName = "availability-zone";
68 String toNode = "complex";
69 SchemaVersion v10 = new SchemaVersion("v10");
72 public static void setUpBeforeClass() throws Exception {
73 String json = "{" + " \"rules\": [" + " {" + " \"from\": \"availability-zone\","
74 + " \"to\": \"complex\","
75 + " \"label\": \"org.onap.relationships.inventory.LocatedIn\","
76 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"MANY2ONE\","
77 + " \"contains-other-v\": \"NONE\"," + " \"delete-other-v\": \"NONE\","
78 + " \"SVC-INFRA\": \"NONE\"," + " \"prevent-delete\": \"!${direction}\","
79 + " \"default\": \"true\"," + " \"description\":\"this description\""
80 + " }," + " {" + " \"from\": \"availability-zone\","
81 + " \"to\": \"service-capability\","
82 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
83 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"MANY2MANY\","
84 + " \"contains-other-v\": \"NONE\"," + " \"delete-other-v\": \"NONE\","
85 + " \"SVC-INFRA\": \"NONE\"," + " \"prevent-delete\": \"!${direction}\","
86 + " \"default\": \"true\"," + " \"description\":\"\"" + " }," + " {"
87 + " \"from\": \"availability-zone\"," + " \"to\": \"cloud-region\","
88 + " \"label\": \"org.onap.relationships.inventory.BelongsTo\","
89 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"MANY2ONE\","
90 + " \"contains-other-v\": \"!${direction}\","
91 + " \"delete-other-v\": \"!${direction}\"," + " \"SVC-INFRA\": \"NONE\","
92 + " \"prevent-delete\": \"NONE\"," + " \"default\": \"true\","
93 + " \"description\":\"\"" + " }," + " {" + " \"from\": \"ctag-pool\","
94 + " \"to\": \"availability-zone\","
95 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
96 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"MANY2MANY\","
97 + " \"contains-other-v\": \"${direction}\","
98 + " \"delete-other-v\": \"NONE\"," + " \"SVC-INFRA\": \"NONE\","
99 + " \"prevent-delete\": \"!${direction}\"," + " \"default\": \"true\","
100 + " \"description\":\"\"" + " }," + " {" + " \"from\": \"dvs-switch\","
101 + " \"to\": \"availability-zone\","
102 + " \"label\": \"org.onap.relationships.inventory.AppliesTo\","
103 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"MANY2MANY\","
104 + " \"contains-other-v\": \"NONE\"," + " \"delete-other-v\": \"NONE\","
105 + " \"SVC-INFRA\": \"NONE\"," + " \"prevent-delete\": \"!${direction}\","
106 + " \"default\": \"true\"," + " \"description\":\"\"" + " }," + " {"
107 + " \"from\": \"generic-vnf\"," + " \"to\": \"availability-zone\","
108 + " \"label\": \"org.onap.relationships.inventory.Uses\","
109 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"MANY2MANY\","
110 + " \"contains-other-v\": \"NONE\"," + " \"delete-other-v\": \"NONE\","
111 + " \"SVC-INFRA\": \"${direction}\","
112 + " \"prevent-delete\": \"!${direction}\"," + " \"default\": \"true\","
113 + " \"description\":\"\"" + " }," + " {" + " \"from\": \"pserver\","
114 + " \"to\": \"availability-zone\","
115 + " \"label\": \"org.onap.relationships.inventory.MemberOf\","
116 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"MANY2ONE\","
117 + " \"contains-other-v\": \"NONE\"," + " \"delete-other-v\": \"NONE\","
118 + " \"SVC-INFRA\": \"${direction}\","
119 + " \"prevent-delete\": \"!${direction}\"," + " \"default\": \"true\","
120 + " \"description\":\"\"" + " }," + " {" + " \"from\": \"vce\","
121 + " \"to\": \"availability-zone\","
122 + " \"label\": \"org.onap.relationships.inventory.Uses\","
123 + " \"direction\": \"OUT\"," + " \"multiplicity\": \"MANY2MANY\","
124 + " \"contains-other-v\": \"NONE\"," + " \"delete-other-v\": \"NONE\","
125 + " \"SVC-INFRA\": \"NONE\"," + " \"prevent-delete\": \"!${direction}\","
126 + " \"default\": \"true\"," + " \"description\":\"\"" + " }," + " ]}";
127 BufferedWriter bw = new BufferedWriter(new FileWriter(EDGEFILENAME));
133 public static void tearDownAfterClass() throws Exception {
134 File edges = new File(EDGEFILENAME);
139 public void setUp() throws Exception {
146 Map<SchemaVersion, List<String>> edges = ct.getEdgeFiles();
147 assertTrue(edges.containsKey(v10));
148 assertTrue(1 == edges.get(v10).size());
149 assertTrue("src/test/resources/dbedgerules/DbEdgeBusinessRules_test.json"
150 .equals(edges.get(v10).get(0)));
154 public void testGetDeleteOtherV() throws EdgeRuleNotFoundException {
155 String target = "availability-zone" + "|" + toNode + "-" + "NONE";
156 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
157 SortedSet<String> ss = new TreeSet<String>(results.keySet());
158 for (String key : ss) {
159 results.get(key).stream()
160 .filter((i) -> (i.getTo().equals(toNode) && (!i.isPrivateEdge()))).forEach((i) -> {
161 EdgeDescription ed = new EdgeDescription(i);
162 assertThat(ed.getRuleKey() + "-" + ed.getDeleteOtherV(), is(target));
168 public void testGetPreventDelete() throws EdgeRuleNotFoundException {
169 String target = "availability-zone" + "|" + toNode + "-" + "IN";
170 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
171 SortedSet<String> ss = new TreeSet<String>(results.keySet());
172 for (String key : ss) {
173 results.get(key).stream()
174 .filter((i) -> (i.getTo().equals(toNode) && (!i.isPrivateEdge()))).forEach((i) -> {
175 EdgeDescription ed = new EdgeDescription(i);
176 assertThat(ed.getRuleKey() + "-" + ed.getPreventDelete(), is(target));
182 public void testGetAlsoDeleteFootnote() throws EdgeRuleNotFoundException {
183 // String toNode="cloud-region";
184 // String target = "availability-zone"+"|"+toNode+"-"+"(4)";
185 List<String> notedTypes = Arrays.asList("cloud-region", "ctag-pool");
186 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
187 SortedSet<String> ss = new TreeSet<String>(results.keySet());
188 for (String key : ss) {
189 results.get(key).stream()
190 .filter((i) -> (i.getTo().equals("availability-zone") && (!i.isPrivateEdge())))
192 EdgeDescription ed = new EdgeDescription(i);
194 ed.getRuleKey() + "-" + (notedTypes.contains(ed.getTo()) ? "(4)" : "");
195 assertThat(ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getFrom()),
200 * for (EdgeDescription ed : edges) {
201 * String modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getFrom());
202 * assertThat(modResult, is(target));
203 * ed.setDeleteOtherV("IN");
204 * target = "availability-zone"+"|"+"complex"+"-"+"(4)";
205 * modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getFrom());
206 * assertThat(modResult, is(target));
207 * target = "availability-zone"+"|"+"complex"+"-"+"(1)";
208 * modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getTo());
209 * assertThat(modResult, is(target));
210 * ed.setDeleteOtherV("OUT");
211 * target = "availability-zone"+"|"+"complex"+"-"+"(2)";
212 * modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getFrom());
213 * assertThat(modResult, is(target));
214 * target = "availability-zone"+"|"+"complex"+"-"+"(3)";
215 * modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getTo());
216 * assertThat(modResult, is(target));
222 public void testGetTo() throws EdgeRuleNotFoundException {
223 String target = "availability-zone" + "|" + toNode + "-" + toNode;
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()
228 .filter((i) -> (i.getTo().equals(toNode) && (!i.isPrivateEdge()))).forEach((i) -> {
229 EdgeDescription ed = new EdgeDescription(i);
230 assertThat(ed.getRuleKey() + "-" + ed.getTo(), is(target));
236 public void testGetFrom() throws EdgeRuleNotFoundException {
237 String target = "availability-zone" + "|" + toNode + "-" + "availability-zone";
238 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
239 SortedSet<String> ss = new TreeSet<String>(results.keySet());
240 for (String key : ss) {
241 results.get(key).stream()
242 .filter((i) -> (i.getTo().equals(toNode) && (!i.isPrivateEdge()))).forEach((i) -> {
243 EdgeDescription ed = new EdgeDescription(i);
244 assertThat(ed.getRuleKey() + "-" + ed.getFrom(), is(target));
250 public void testGetRuleKey() throws EdgeRuleNotFoundException {
251 String target = "availability-zone" + "|" + toNode;
252 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
253 SortedSet<String> ss = new TreeSet<String>(results.keySet());
254 for (String key : ss) {
255 results.get(key).stream()
256 .filter((i) -> (i.getTo().equals(toNode) && (!i.isPrivateEdge()))).forEach((i) -> {
257 EdgeDescription ed = new EdgeDescription(i);
258 assertThat(ed.getRuleKey(), is(target));
264 public void testGetMultiplicity() throws EdgeRuleNotFoundException {
265 String target = "availability-zone" + "|" + toNode + "-" + "MANY2ONE";
266 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
267 SortedSet<String> ss = new TreeSet<String>(results.keySet());
268 for (String key : ss) {
269 results.get(key).stream()
270 .filter((i) -> (i.getTo().equals(toNode) && (!i.isPrivateEdge()))).forEach((i) -> {
271 EdgeDescription ed = new EdgeDescription(i);
272 assertThat(ed.getRuleKey() + "-" + ed.getMultiplicity(), is(target));
278 public void testGetDirection() throws EdgeRuleNotFoundException {
279 String target = "availability-zone" + "|" + toNode + "-" + "OUT";
280 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
281 SortedSet<String> ss = new TreeSet<String>(results.keySet());
282 for (String key : ss) {
283 results.get(key).stream()
284 .filter((i) -> (i.getTo().equals(toNode) && (!i.isPrivateEdge()))).forEach((i) -> {
285 EdgeDescription ed = new EdgeDescription(i);
286 assertThat(ed.getRuleKey() + "-" + ed.getDirection(), is(target));
292 public void testGetDescription() throws EdgeRuleNotFoundException {
293 String target = "availability-zone" + "|" + toNode + "-" + "this description";
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()
298 .filter((i) -> (i.getTo().equals(toNode) && (!i.isPrivateEdge()))).forEach((i) -> {
299 EdgeDescription ed = new EdgeDescription(i);
300 assertThat(ed.getRuleKey() + "-" + ed.getDescription(), is(target));
306 public void testGetRelationshipDescription() throws EdgeRuleNotFoundException {
307 String target = "availability-zone" + "|" + toNode + "-" + "this description";
308 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
309 SortedSet<String> ss = new TreeSet<String>(results.keySet());
310 for (String key : ss) {
311 results.get(key).stream()
312 .filter((i) -> (i.getTo().equals(toNode) && (!i.isPrivateEdge()))).forEach((i) -> {
313 EdgeDescription ed = new EdgeDescription(i);
314 assertThat(ed.getRuleKey() + "-" + ed.getDescription(), is(target));
320 public void testGetType() throws EdgeRuleNotFoundException {
321 String toNode = "cloud-region";
322 String target = "availability-zone" + "|" + toNode + "-" + "PARENT";
323 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
324 SortedSet<String> ss = new TreeSet<String>(results.keySet());
325 for (String key : ss) {
326 results.get(key).stream()
327 .filter((i) -> (i.getTo().equals(toNode) && (!i.isPrivateEdge()))).forEach((i) -> {
328 EdgeDescription ed = new EdgeDescription(i);
329 assertThat(ed.getRuleKey() + "-" + ed.getType(), is(target));
335 public void testGetLabel() throws EdgeRuleNotFoundException {
337 "availability-zone" + "|" + toNode + "-" + "org.onap.relationships.inventory.LocatedIn";
338 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
339 SortedSet<String> ss = new TreeSet<String>(results.keySet());
340 for (String key : ss) {
341 results.get(key).stream()
342 .filter((i) -> (i.getTo().equals(toNode) && (!i.isPrivateEdge()))).forEach((i) -> {
343 EdgeDescription ed = new EdgeDescription(i);
344 assertThat(ed.getRuleKey() + "-" + ed.getLabel(), is(target));
350 public void testGetShortLabel() throws EdgeRuleNotFoundException {
351 String target = "availability-zone" + "|" + toNode + "-" + "LocatedIn";
352 Multimap<String, EdgeRule> results = edgeIngestor.getAllRules(v10);
353 SortedSet<String> ss = new TreeSet<String>(results.keySet());
354 for (String key : ss) {
355 results.get(key).stream()
356 .filter((i) -> (i.getTo().equals(toNode) && (!i.isPrivateEdge()))).forEach((i) -> {
357 EdgeDescription ed = new EdgeDescription(i);
358 assertThat(ed.getRuleKey() + "-" + ed.getShortLabel(), is(target));