Add plugin to check coverage
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / util / genxsd / EdgeDescriptionTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.aai.util.genxsd;
21
22 import com.jayway.jsonpath.DocumentContext;
23 import com.jayway.jsonpath.JsonPath;
24 import org.junit.Before;
25 import org.junit.BeforeClass;
26 import org.junit.Test;
27
28 import java.util.Collection;
29
30 import static org.hamcrest.CoreMatchers.*;
31 import static org.junit.Assert.assertThat;
32
33 public class EdgeDescriptionTest {
34         private DocumentContext jsonContext;
35         private EdgeRuleSet edgeSet;
36         private Collection<EdgeDescription>edges;
37         
38         @BeforeClass
39         public static void setUpBeforeClass() throws Exception {
40
41         }
42
43         @Before
44         public void setUp() throws Exception {
45                 String json = "{"
46                                 + "     \"rules\": ["
47                                 + "             {"
48                                 + "                     \"from\": \"availability-zone\","
49                                 + "                     \"to\": \"complex\","
50                                 + "                     \"label\": \"org.onap.relationships.inventory.LocatedIn\","
51                                 + "                     \"direction\": \"OUT\","
52                                 + "                     \"multiplicity\": \"MANY2ONE\","
53                                 + "                     \"contains-other-v\": \"NONE\","
54                                 + "                     \"delete-other-v\": \"NONE\","
55                                 + "                     \"SVC-INFRA\": \"NONE\","
56                                 + "                     \"prevent-delete\": \"!${direction}\","
57                                 + "                     \"default\": \"true\","
58                                 + "                     \"description\":\"this description\""
59                                 + "             },"
60 /*
61                                 + "    {"
62                                 + "                     \"from\": \"availability-zone\","
63                                 + "                     \"to\": \"service-capability\","
64                                 + "                     \"label\": \"org.onap.relationships.inventory.AppliesTo\","
65                                 + "                     \"direction\": \"OUT\","
66                                 + "                     \"multiplicity\": \"MANY2MANY\","
67                                 + "                     \"contains-other-v\": \"NONE\","
68                                 + "                     \"delete-other-v\": \"NONE\","
69                                 + "                     \"SVC-INFRA\": \"NONE\","
70                                 + "                     \"prevent-delete\": \"!${direction}\","
71                                 + "                     \"default\": \"true\","
72                                 + "                     \"description\":\"\""
73                                 + "             },"
74                                 + "             {"
75                                 + "                     \"from\": \"availability-zone\","
76                                 + "                     \"to\": \"cloud-region\","
77                                 + "                     \"label\": \"org.onap.relationships.inventory.BelongsTo\","
78                                 + "                     \"direction\": \"OUT\","
79                                 + "                     \"multiplicity\": \"MANY2ONE\","
80                                 + "                     \"contains-other-v\": \"!${direction}\","
81                                 + "                     \"delete-other-v\": \"!${direction}\","
82                                 + "                     \"SVC-INFRA\": \"NONE\","
83                                 + "                     \"prevent-delete\": \"NONE\","
84                                 + "                     \"default\": \"true\","
85                                 + "                     \"description\":\"\""
86                                 + "             },"
87                                 + "             {"
88                                 + "                     \"from\": \"ctag-pool\","
89                                 + "                     \"to\": \"availability-zone\","
90                                 + "                     \"label\": \"org.onap.relationships.inventory.AppliesTo\","
91                                 + "                     \"direction\": \"OUT\","
92                                 + "                     \"multiplicity\": \"MANY2MANY\","
93                                 + "                     \"contains-other-v\": \"NONE\","
94                                 + "                     \"delete-other-v\": \"NONE\","
95                                 + "                     \"SVC-INFRA\": \"NONE\","
96                                 + "                     \"prevent-delete\": \"!${direction}\","
97                                 + "                     \"default\": \"true\","
98                                 + "                     \"description\":\"\""
99                                 + "             },"
100                                 + "             {"
101                                 + "                     \"from\": \"dvs-switch\","
102                                 + "                     \"to\": \"availability-zone\","
103                                 + "                     \"label\": \"org.onap.relationships.inventory.AppliesTo\","
104                                 + "                     \"direction\": \"OUT\","
105                                 + "                     \"multiplicity\": \"MANY2MANY\","
106                                 + "                     \"contains-other-v\": \"NONE\","
107                                 + "                     \"delete-other-v\": \"NONE\","
108                                 + "                     \"SVC-INFRA\": \"NONE\","
109                                 + "                     \"prevent-delete\": \"!${direction}\","
110                                 + "                     \"default\": \"true\","
111                                 + "                     \"description\":\"\""
112                                 + "             },"
113                                 + "             {"
114                                 + "                     \"from\": \"generic-vnf\","
115                                 + "                     \"to\": \"availability-zone\","
116                                 + "                     \"label\": \"org.onap.relationships.inventory.Uses\","
117                                 + "                     \"direction\": \"OUT\","
118                                 + "                     \"multiplicity\": \"MANY2MANY\","
119                                 + "                     \"contains-other-v\": \"NONE\","
120                                 + "                     \"delete-other-v\": \"NONE\","
121                                 + "                     \"SVC-INFRA\": \"${direction}\","
122                                 + "                     \"prevent-delete\": \"!${direction}\","
123                                 + "                     \"default\": \"true\","
124                                 + "                     \"description\":\"\""
125                                 + "             },"
126                                 + "             {"
127                                 + "                     \"from\": \"pserver\","
128                                 + "                     \"to\": \"availability-zone\","
129                                 + "                     \"label\": \"org.onap.relationships.inventory.MemberOf\","
130                                 + "                     \"direction\": \"OUT\","
131                                 + "                     \"multiplicity\": \"MANY2ONE\","
132                                 + "                     \"contains-other-v\": \"NONE\","
133                                 + "                     \"delete-other-v\": \"NONE\","
134                                 + "                     \"SVC-INFRA\": \"${direction}\","
135                                 + "                     \"prevent-delete\": \"!${direction}\","
136                                 + "                     \"default\": \"true\","
137                                 + "                     \"description\":\"\""
138                                 + "             },"
139                                 + "             {"
140                                 + "                     \"from\": \"vce\","
141                                 + "                     \"to\": \"availability-zone\","
142                                 + "                     \"label\": \"org.onap.relationships.inventory.Uses\","
143                                 + "                     \"direction\": \"OUT\","
144                                 + "                     \"multiplicity\": \"MANY2MANY\","
145                                 + "                     \"contains-other-v\": \"NONE\","
146                                 + "                     \"delete-other-v\": \"NONE\","
147                                 + "                     \"SVC-INFRA\": \"NONE\","
148                                 + "                     \"prevent-delete\": \"!${direction}\","
149                                 + "                     \"default\": \"true\","
150                                 + "                     \"description\":\"\""
151                                 + "             },"
152 */
153                                 + "     ]}";
154                                 jsonContext = JsonPath.parse(json);
155                                 this.edgeSet = new EdgeRuleSet(jsonContext);
156                                 String nodeName = "availability-zone";
157                                 edges = edgeSet.getEdgeRules(nodeName);
158         }
159
160         @Test
161         public void testGetDeleteOtherV() {
162                 String target = "availability-zone"+"|"+"complex"+"-"+"NONE";
163                 for (EdgeDescription ed : edges) {
164                         String modResult = ed.getRuleKey() + "-" + ed.getDeleteOtherV();
165                         assertThat(modResult, is(target));
166                 }
167         }
168
169         @Test
170         public void testSetDeleteOtherV() {
171                 String target = "availability-zone"+"|"+"complex"+"-"+"IN";
172                 for (EdgeDescription ed : edges) {
173                         ed.setDeleteOtherV("IN");
174                         String modResult = ed.getRuleKey() + "-" + ed.getDeleteOtherV();
175                         assertThat(modResult, is(target));
176                 }
177         }
178
179         @Test
180         public void testGetPreventDelete() {
181                 String target = "availability-zone"+"|"+"complex"+"-"+"IN";
182                 for (EdgeDescription ed : edges) {
183                         String modResult = ed.getRuleKey() + "-" + ed.getPreventDelete();
184                         assertThat(modResult, is(target));
185                 }
186         }
187
188         @Test
189         public void testSetPreventDelete() {
190                 for (EdgeDescription ed : edges) {
191                         String target = "availability-zone"+"|"+"complex"+"-"+"OUT";
192                         ed.setPreventDelete("OUT");
193                         String modResult = ed.getRuleKey() + "-" + ed.getPreventDelete();
194                         assertThat(modResult, is(target));
195                 }
196         }
197
198         @Test
199         public void testGetAlsoDeleteFootnote() {
200                 String target = "availability-zone"+"|"+"complex"+"-"+"";
201                 for (EdgeDescription ed : edges) {
202                         String modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getFrom());
203                         assertThat(modResult, is(target));
204                         ed.setDeleteOtherV("IN");
205                         target = "availability-zone"+"|"+"complex"+"-"+"(4)";
206                         modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getFrom());
207                         assertThat(modResult, is(target));
208                         target = "availability-zone"+"|"+"complex"+"-"+"(1)";
209                         modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getTo());
210                         assertThat(modResult, is(target));
211                         ed.setDeleteOtherV("OUT");
212                         target = "availability-zone"+"|"+"complex"+"-"+"(2)";
213                         modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getFrom());
214                         assertThat(modResult, is(target));
215                         target = "availability-zone"+"|"+"complex"+"-"+"(3)";
216                         modResult = ed.getRuleKey() + "-" + ed.getAlsoDeleteFootnote(ed.getTo());
217                         assertThat(modResult, is(target));
218                 }
219         }
220
221         @Test
222         public void testGetTo() {
223                 String target = "availability-zone"+"|"+"complex"+"-"+"complex";
224                 for (EdgeDescription ed : edges) {
225                         String modResult = ed.getRuleKey() + "-" + ed.getTo();
226                         assertThat(modResult, is(target));
227                 }
228         }
229
230         @Test
231         public void testSetTo() {
232                 String target = "availability-zone"+"|"+"complex"+"-"+"jazz";
233                 for (EdgeDescription ed : edges) {
234                         ed.setTo("jazz");
235                         String modResult = ed.getRuleKey() + "-" + ed.getTo();
236                         assertThat(modResult, is(target));
237                 }
238         }
239
240         @Test
241         public void testGetFrom() {
242                 String target = "availability-zone"+"|"+"complex"+"-"+"availability-zone";
243                 for (EdgeDescription ed : edges) {
244                         String modResult = ed.getRuleKey() + "-" + ed.getFrom();
245                         assertThat(modResult, is(target));
246                 }
247         }
248
249         @Test
250         public void testSetFrom() {
251                 String target = "availability-zone"+"|"+"complex"+"-"+"jazz";
252                 for (EdgeDescription ed : edges) {
253                         ed.setFrom("jazz");
254                         String modResult = ed.getRuleKey() + "-" + ed.getFrom();
255                         assertThat(modResult, is(target));
256                 }
257         }
258
259         @Test
260         public void testGetRuleKey() {
261                 for (EdgeDescription ed : edges) {
262                         String target = ed.getFrom()+"|"+ed.getTo();
263                         String modResult = ed.getRuleKey();
264                         assertThat(modResult, is(target));
265                 }
266         }
267
268         @Test
269         public void testGetMultiplicity() {
270                 String target = "availability-zone"+"|"+"complex"+"-"+"MANY2ONE";
271                 for (EdgeDescription ed : edges) {
272                         String modResult = ed.getRuleKey() + "-" + ed.getMultiplicity();
273                         assertThat(modResult, is(target));
274                 }
275         }
276
277         @Test
278         public void testGetDirection() {
279                 for (EdgeDescription ed : edges) {
280                         String target = ed.getFrom()+"|"+ed.getTo()+"-"+"OUT";
281                         String modResult = ed.getRuleKey() + "-" + ed.getDirection();
282                         assertThat(modResult, is(target));
283                 }
284         }
285
286         @Test
287         public void testGetDescription() {
288                 for (EdgeDescription ed : edges) {
289                         String target = ed.getFrom()+"|"+ed.getTo()+"-"+"this description";
290                         String modResult = ed.getRuleKey() + "-" + ed.getDescription();
291                         assertThat(modResult, is(target));
292                 }
293         }
294
295         @Test
296         public void testSetRuleKey() {
297                 for (EdgeDescription ed : edges) {
298                         ed.setRuleKey("A|B");
299                         String target = "A|B";
300                         String modResult = ed.getRuleKey();
301                         assertThat(modResult, is(target));
302                 }       }
303
304         @Test
305         public void testSetType() {
306                 String target = "availability-zone"+"|"+"complex"+"-"+"CHILD";
307                 for (EdgeDescription ed : edges) {
308                         ed.setType(EdgeDescription.LineageType.CHILD);
309                         String modResult = ed.getRuleKey() + "-" + ed.getType();
310                         assertThat(modResult, is(target));
311                 }
312         }
313
314         @Test
315         public void testSetDirection() {
316                 String target = "availability-zone"+"|"+"complex"+"-"+"IN";
317                 for (EdgeDescription ed : edges) {
318                         ed.setDirection("IN");
319                         String modResult = ed.getRuleKey() + "-" + ed.getDirection();
320                         assertThat(modResult, is(target));
321                 }
322         }
323
324         @Test
325         public void testSetMultiplicity() {
326                 String target = "availability-zone"+"|"+"complex"+"-"+"ONE2MANY";
327                 for (EdgeDescription ed : edges) {
328                         ed.setTo("ONE2MANY");
329                         String modResult = ed.getRuleKey() + "-" + ed.getTo();
330                         assertThat(modResult, is(target));
331                 }
332         }
333
334         @Test
335         public void testSetDescription() {
336                 for (EdgeDescription ed : edges) {
337                         ed.setDescription("a new description");
338                         String target = ed.getFrom()+"|"+ed.getTo()+"-"+"a new description";
339                         String modResult = ed.getRuleKey() + "-" + ed.getDescription();
340                         assertThat(modResult, is(target));
341                 }
342         }
343
344         @Test
345         public void testGetRelationshipDescription() {
346                 for (EdgeDescription ed : edges) {
347                         String target = ed.getFrom()+"|"+ed.getTo()+"-"+"( availability-zone LocatedIn complex, MANY2ONE)\n      this description";
348                         String modResult = ed.getRuleKey() + "-" + ed.getRelationshipDescription("FROM",ed.getTo());
349                         assertThat(modResult, is(target));
350                 }
351         }
352
353         @Test
354         public void testGetType() {
355                 for (EdgeDescription ed : edges) {
356                         String target = ed.getFrom()+"|"+ed.getTo()+"-"+"UNRELATED";
357                         String modResult = ed.getRuleKey() + "-" + ed.getType();
358                         assertThat(modResult, is(target));
359                 }
360         }
361
362         @Test
363         public void testGetLabel() {
364                 for (EdgeDescription ed : edges) {
365                         String target = ed.getFrom()+"|"+ed.getTo()+"-"+"org.onap.relationships.inventory.LocatedIn";
366                         String modResult = ed.getRuleKey() + "-" + ed.getLabel();
367                         assertThat(modResult, is(target));
368                 }
369         }
370
371         @Test
372         public void testGetShortLabel() {
373                 for (EdgeDescription ed : edges) {
374                         String target = ed.getFrom()+"|"+ed.getTo()+"-"+"LocatedIn";
375                         String modResult = ed.getRuleKey() + "-" + ed.getShortLabel();
376                         assertThat(modResult, is(target));
377                 }
378         }
379
380         @Test
381         public void testSetLabel() {
382                 String newLabel = "New label";
383                 for (EdgeDescription ed : edges) {
384                         ed.setLabel(newLabel);
385                         String target = ed.getFrom()+"|"+ed.getTo()+"-"+newLabel;
386                         String modResult = ed.getRuleKey() + "-" + ed.getLabel();
387                         assertThat(modResult, not(equalTo("org.onap.relationships.inventory.LocatedIn")));
388                         assertThat(modResult, is(target));
389                 }
390         }
391
392 }