Add to aai-common query builder get parent step
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / query / builder / QueryBuilderTestAbstraction.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.query.builder;
21
22 import org.apache.tinkerpop.gremlin.process.traversal.Path;
23 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
24 import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet;
25 import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
26 import org.apache.tinkerpop.gremlin.structure.Edge;
27 import org.apache.tinkerpop.gremlin.structure.Graph;
28 import org.apache.tinkerpop.gremlin.structure.Vertex;
29 import org.janusgraph.core.JanusGraphFactory;
30 import org.junit.*;
31 import org.onap.aai.AAISetup;
32 import org.onap.aai.db.props.AAIProperties;
33 import org.onap.aai.exceptions.AAIException;
34 import org.onap.aai.introspection.Loader;
35 import org.onap.aai.introspection.LoaderFactory;
36 import org.onap.aai.introspection.ModelType;
37 import org.onap.aai.serialization.db.EdgeRules;
38 import org.onap.aai.serialization.db.EdgeType;
39 import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException;
40
41 import java.util.ArrayList;
42 import java.util.Arrays;
43 import java.util.Collections;
44 import java.util.List;
45
46 import static org.hamcrest.CoreMatchers.is;
47 import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
48 import static org.junit.Assert.*;
49
50 public abstract class QueryBuilderTestAbstraction extends AAISetup {
51
52         protected static Loader loader;
53         protected static Graph graph;
54         protected GraphTraversalSource g;
55
56         protected EdgeRules testEdgeRules = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_TraversalQueryTest.json");
57
58
59         @BeforeClass
60         public static void setup() throws Exception {
61                 loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST);
62                 graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
63         }
64
65         @Before
66         public void configure() throws Exception {
67                 g = graph.traversal();
68         }
69
70         @After
71         public void deConfigure() throws Exception {
72                 g.tx().rollback();
73         }
74
75         @AfterClass
76         public static void teardown() throws Exception {
77                 graph.close();
78         }
79         
80         @Test
81         public void createEdgeGVnfToVnfcTraversal() throws AAIException {
82                                 
83                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","myvnf").next();
84                 Vertex vnfc = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
85                 testEdgeRules.addEdge(g, gvnf, vnfc, "uses");
86                 
87                 QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(gvnf);
88                 tQ.createEdgeTraversal(EdgeType.COUSIN, "generic-vnf", "vnfc");
89                 
90                 assertEquals(vnfc, tQ.next());
91                 
92
93         }
94         
95         @Test
96         public void createEdgeLinterfaceToLogicalLinkTraversal() throws AAIException {
97                                 
98                 Vertex lInterface = g.addV("aai-node-type","l-interface","interface-name","l-interface-a").next();
99                 Vertex logicalLink = g.addV("aai-node-type","logical-link","link-name","logical-link-a").next();
100                 testEdgeRules.addEdge(g, lInterface, logicalLink, "sourceLInterface");
101                 
102                 QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(lInterface);
103                 tQ.createEdgeTraversal(EdgeType.COUSIN, "l-interface", "logical-link");
104                 
105                 Vertex next = tQ.next();
106                 
107                 assertEquals(logicalLink, next);
108                 
109
110         }
111         
112         @SuppressWarnings("rawtypes")
113         @Test
114         public void createEdgeLinterfaceToLogicalLinkTraversal_Path() throws AAIException {
115                 Vertex pInterface = g.addV("aai-node-type","p-interface","interface-name","p-interface-a").next();
116                 Vertex lInterface = g.addV("aai-node-type","l-interface","interface-name","l-interface-a").next();
117                 Vertex logicalLink = g.addV("aai-node-type","logical-link","link-name","logical-link-a").next();
118                 testEdgeRules.addEdge(g, lInterface, logicalLink);
119                 testEdgeRules.addTreeEdge(g, pInterface, lInterface);
120
121                 QueryBuilder<Path> tQ = getNewPathTraversalWithTestEdgeRules(pInterface).createEdgeTraversal(EdgeType.TREE,
122                                 loader.introspectorFromName("p-interface" ), loader.introspectorFromName("l-interface")).createEdgeTraversal(EdgeType.COUSIN,
123                                 loader.introspectorFromName("l-interface" ), loader.introspectorFromName("logical-link")).path();
124
125                 Path path = tQ.next();
126                 assertThat(path.objects(), contains(pInterface, lInterface, logicalLink));
127         }
128
129         @SuppressWarnings("rawtypes")
130         @Test
131         public void parentVertexTest() throws AAIException {
132                 Vertex pInterface = g.addV("aai-node-type","p-interface","interface-name","p-interface-a").next();
133                 Vertex lInterface = g.addV("aai-node-type","l-interface","interface-name","l-interface-a").next();
134
135                 testEdgeRules.addTreeEdge(g, pInterface, lInterface);
136
137                 QueryBuilder<Vertex> tQ = getNewEdgeTraversalWithTestEdgeRules(lInterface).getParentVertex();
138
139                 Vertex parent = tQ.next();
140                 assertThat(parent, is(pInterface));
141         }
142
143
144         @Test
145         public void createEdgeLinterfaceToLogicalLinkIntrospectorTraversal() throws AAIException {
146                                 
147                 Vertex lInterface = g.addV("aai-node-type","l-interface","interface-name","l-interface-a").next();
148                 Vertex logicalLink = g.addV("aai-node-type","logical-link","link-name","logical-link-a").next();
149                 testEdgeRules.addEdge(g, lInterface, logicalLink, "sourceLInterface");
150                 
151                 QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(lInterface);
152                 tQ.createEdgeTraversal(EdgeType.COUSIN, loader.introspectorFromName("l-interface"), loader.introspectorFromName("logical-link"));
153                 
154                 Vertex next = tQ.next();
155                 
156                 assertEquals(logicalLink, next);
157                 
158
159         }
160         
161         @Test
162         public void createEdgeLinterfaceToLogicalLinkVertexToIntrospectorTraversal() throws AAIException {
163                                 
164                 Vertex lInterface = g.addV("aai-node-type","l-interface","interface-name","l-interface-a").next();
165                 Vertex logicalLink = g.addV("aai-node-type","logical-link","link-name","logical-link-a").next();
166                 testEdgeRules.addEdge(g, lInterface, logicalLink, "sourceLInterface");
167                 
168                 QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(lInterface);
169                 tQ.createEdgeTraversal(EdgeType.COUSIN, lInterface, loader.introspectorFromName("logical-link"));
170                 
171                 Vertex next = tQ.next();
172                 
173                 assertEquals(logicalLink, next);
174                 
175
176         }
177         
178         @Test
179         public void edgeToVertexTraversalTest() throws AAIException {
180                                 
181                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
182                 Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
183                 
184                 testEdgeRules.addEdge(g, gvnf, vnfc1);
185                 
186                 QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(gvnf);
187                 tQ.createEdgeTraversal(EdgeType.COUSIN, "generic-vnf", "vnfc");
188                 
189                 List<Vertex> list = tQ.toList();
190
191                 assertEquals("Has 1 vertexes ", 1, list.size());
192                 assertTrue("Has vertex on the default edge ", list.contains(vnfc1));
193                 
194
195         }
196         
197         @Test
198         public void edgeToVertexTraversalSingleOutRuleTest() throws AAIException {
199                                 
200                 Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next();
201                 Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
202                 
203                 testEdgeRules.addEdge(g, vce, vnfc1);
204                 
205                 QueryBuilder<Vertex> tQ1 = getNewVertexTraversalWithTestEdgeRules(vce);
206                 tQ1.createEdgeTraversal(EdgeType.COUSIN, "vce", "vnfc");
207                 
208                 QueryBuilder<Vertex> tQ2 = getNewVertexTraversalWithTestEdgeRules(vnfc1);
209                 tQ2.createEdgeTraversal(EdgeType.COUSIN, "vnfc", "vce");
210                 
211                 List<Vertex> list1 = tQ1.toList();
212                 List<Vertex> list2 = tQ2.toList();
213                 
214                 assertEquals("1 - Has 1 vertexes ", 1, list1.size());
215                 assertTrue("1 - traversal results in vnfc ", list1.contains(vnfc1));
216                 assertEquals("2 - Has 1 vertexes ", 1, list2.size());
217                 assertTrue("2 - traversal results in vce ", list2.contains(vce));
218                 
219
220         }
221         
222         @Test
223         public void edgeToVertexTraversalSingleInRuleTest() throws AAIException {
224                                 
225                 Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next();
226                 Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
227                 
228                 testEdgeRules.addEdge(g, vce, pserver);
229                 
230                 QueryBuilder<Vertex> tQ1 = getNewVertexTraversalWithTestEdgeRules(vce);
231                 tQ1.createEdgeTraversal(EdgeType.COUSIN, "vce", "pserver");
232                 
233                 List<Vertex> list = tQ1.toList();
234
235                 assertEquals("1 - Has 1 vertexes ", 1, list.size());
236                 assertTrue("1 - traversal results in vnfc ", list.contains(pserver));
237                 
238
239         }
240         
241         @Test
242         public void edgeToVertexMultiRuleTraversalTest() throws AAIException {
243                                 
244                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
245                 Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
246                 Vertex vnfc2 = g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
247                 
248                 testEdgeRules.addEdge(g, gvnf, vnfc1);
249                 testEdgeRules.addEdge(g, gvnf, vnfc2, "re-uses");
250                 
251                 QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(gvnf);
252                 tQ.createEdgeTraversal(EdgeType.COUSIN, "generic-vnf", "vnfc");
253                 
254                 List<Vertex> list = tQ.toList();
255
256                 assertEquals("Has 2 vertexes ", 2, list.size());
257                 assertTrue("Has vertex on the default edge ", list.contains(vnfc1));
258                 assertTrue("Has vertex on the re-uses edge ", list.contains(vnfc2));
259                 
260
261         }
262         
263         @Test
264         public void edgeToVertexMultiLabelTest() throws AAIException {
265                                 
266                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
267                 Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
268                 Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
269                 
270                 testEdgeRules.addEdge(g, gvnf, vnfc1);
271                 testEdgeRules.addEdge(g, pserver, vnfc1);
272                 
273                 QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(vnfc1);
274                 tQ.createEdgeTraversal(EdgeType.COUSIN, "vnfc", "generic-vnf");
275                 
276                 List<Vertex> list = tQ.toList();
277
278                 assertEquals("Has 1 vertexes ", 1, list.size());
279                 assertTrue("Only returns the generic vnf vertex", list.contains(gvnf));
280                 
281
282         }
283         
284         @Test
285         public void limitTraversalTest() throws AAIException {
286                                 
287                 g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
288                 g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
289                 
290                 QueryBuilder<Vertex> tQ = new GremlinTraversal<>(loader, g, testEdgeRules);
291                 tQ.getVerticesByProperty("aai-node-type","vnfc").limit(1);
292                 
293                 List<Vertex> list = tQ.toList();
294
295                 assertEquals("Has 1 vertexes ", 1, list.size());
296         
297
298         }
299         
300         @Test
301         public void getVertexesByPropertiesTraversalTest() throws AAIException {
302                                 
303                 g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
304                 g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
305                 
306                 QueryBuilder<Vertex> tQ = new GremlinTraversal<>(loader, g, testEdgeRules);
307                 tQ.getVerticesByProperty("vnfc-name", Arrays.asList("a-name", "b-name"));
308                 
309                 List<Vertex> list = tQ.toList();
310
311                 assertEquals("Has 2 vertexes ", 2, list.size());
312         
313
314         }
315         
316         @Test
317         public void getVertexesByIndexedPropertyTraversalTest() throws AAIException {
318                                 
319                 g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
320                 g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
321                 
322                 QueryBuilder<Vertex> tQ = new GremlinTraversal<>(loader, g, testEdgeRules);
323                 tQ.getVerticesByIndexedProperty("aai-node-type","vnfc");
324                 
325                 List<Vertex> list = tQ.toList();
326
327                 assertEquals("Has 2 vertexes ", 2, list.size());
328         
329
330         }
331         
332         @Test
333         public void dedupTraversalTest() throws AAIException {
334                         
335                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
336                 Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
337                 
338                 testEdgeRules.addEdge(g, gvnf, pserver);
339                 testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
340                 
341                 QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(gvnf);
342                 tQ.createEdgeTraversal(EdgeType.COUSIN, "generic-vnf", "pserver").dedup();
343                 
344                 List<Vertex> list = tQ.toList();
345         
346                 assertEquals("Has 2 vertexes ", 1, list.size());
347                 assertTrue("result has pserver ", list.contains(pserver));
348                 
349
350         }
351         
352         @Test
353         public void storeCapTraversalTest() throws AAIException {
354                         
355                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
356                 Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
357                 
358                 testEdgeRules.addEdge(g, gvnf, pserver);
359                 testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
360                 
361                 GremlinTraversal<BulkSet<Vertex>> tQ = new GremlinTraversal<>(loader, g, gvnf, testEdgeRules);
362                 tQ.createEdgeTraversal(EdgeType.COUSIN, "generic-vnf", "pserver").store("x").cap("x");
363                 
364                 List<BulkSet<Vertex>> list = tQ.toList();
365         
366                 assertEquals("Has 2 vertexes ", 1, list.size());
367                 assertEquals("result has pserver ",pserver, list.get(0).iterator().next());
368                 
369
370         }
371         
372         @Test
373         public void storeCapUnfoldTraversalTest() throws AAIException {
374                         
375                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
376                 Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
377                 
378                 testEdgeRules.addEdge(g, gvnf, pserver);
379                 testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
380                 
381                 QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(gvnf);
382                 tQ.createEdgeTraversal(EdgeType.COUSIN, "generic-vnf", "pserver").store("x").cap("x").unfold();
383                 
384                 List<Vertex> list = tQ.toList();
385         
386                 assertEquals("Has 2 vertexes ", 2, list.size());
387                 assertTrue("result has pserver ", list.contains(pserver));
388                 
389
390         }
391         
392         @Test
393         public void nextAndHasNextTraversalTest() throws AAIException {
394                                 
395                 Vertex v1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
396                 Vertex v2 = g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
397                 
398                 QueryBuilder<Vertex> tQ = new GremlinTraversal<>(loader, g, testEdgeRules);
399                 tQ.getVerticesByProperty("aai-node-type","vnfc");
400                 
401                 List<Vertex> list = new ArrayList<>();
402                 
403                 assertTrue("Has next 1 ",tQ.hasNext());
404                 list.add(tQ.next());
405                 assertTrue("Has next 2 ",tQ.hasNext());
406                 list.add(tQ.next());
407                 assertFalse("Has next 3 ",tQ.hasNext());
408                 assertTrue("Has all the vertexes", list.contains(v1) && list.remove(v2));
409
410         }
411         
412         @Test
413         public void edgeToVertexMultiRuleOutTraversalTest() throws AAIException {
414                         
415                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
416                 Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
417                 
418                 testEdgeRules.addEdge(g, gvnf, pserver);
419                 testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
420                 
421                 QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(gvnf);
422                 tQ.createEdgeTraversal(EdgeType.COUSIN, "generic-vnf", "pserver");
423                 
424                 List<Vertex> list = tQ.toList();
425         
426                 assertEquals("Has 2 vertexes ", 2, list.size());
427                 assertTrue("result has pserver ", list.contains(pserver));
428                 
429
430         }
431         
432         @Test
433         public void edgeToVertexMultiRuleInTraversalTest() throws AAIException {
434                         
435                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
436                 Vertex complex = g.addV("aai-node-type","complex","physical-location-id","a-name").next();
437                 
438                 testEdgeRules.addEdge(g, gvnf, complex);
439                 testEdgeRules.addEdge(g, gvnf, complex, "complex-generic-vnf-B");
440                 
441                 QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(gvnf);
442                 tQ.createEdgeTraversal(EdgeType.COUSIN, "generic-vnf", "complex");
443                 
444                 List<Vertex> list = tQ.toList();
445         
446                 assertEquals("Has 2 vertexes ", 2, list.size());
447                 assertTrue("result has pserver ", list.contains(complex));
448                 
449
450         }
451
452         @Test
453         public void edgeTraversalSingleInRuleTest() throws AAIException {
454                                 
455                 Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next();
456                 Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
457                 
458                 Edge e = testEdgeRules.addEdge(g, vce, pserver);
459                 
460                 QueryBuilder<Edge> tQ1 = getNewEdgeTraversalWithTestEdgeRules(vce);
461                 tQ1.getEdgesBetween(EdgeType.COUSIN, "vce", "pserver");
462                 
463                 List<Edge> list = tQ1.toList();
464
465                 assertEquals("1 - Has 1 edge ", 1, list.size());
466                 assertTrue("1 - traversal results in edge ", list.contains(e));
467                 
468
469         }
470         
471         @Test
472         public void edgeTraversalSingleOutRuleTest() throws AAIException {
473                                 
474                 Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next();
475                 Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
476                 
477                 Edge e = testEdgeRules.addEdge(g, vce, vnfc1);
478                 
479                 QueryBuilder<Edge> tQ1 = getNewEdgeTraversalWithTestEdgeRules(vce);
480                 tQ1.getEdgesBetween(EdgeType.COUSIN, "vce", "vnfc");
481                 
482                 List<Edge> list1 = tQ1.toList();
483                 
484                 assertEquals("1 - Has 1 edge ", 1, list1.size());
485                 assertTrue("1 - traversal results in edge ", list1.contains(e));
486                 
487
488         }
489
490         @Test
491         public void edgeTraversalMultiRuleOutTraversalTest() throws AAIException {
492                         
493                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
494                 Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
495                 
496                 Edge e1 = testEdgeRules.addEdge(g, gvnf, pserver);
497                 Edge e2 = testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
498                 
499                 QueryBuilder<Edge> tQ = getNewEdgeTraversalWithTestEdgeRules(gvnf);
500                 tQ.getEdgesBetween(EdgeType.COUSIN, "generic-vnf", "pserver");
501                 
502                 List<Edge> list = tQ.toList();
503         
504                 assertEquals("Has 2 edges ", 2, list.size());
505                 assertTrue("result has default edge ", list.contains(e1));
506                 assertTrue("result has other edge ", list.contains(e2));
507                 
508
509         }
510         
511         @Test
512         public void edgeTraversalMultiRuleInTraversalTest() throws AAIException {
513                         
514                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
515                 Vertex complex = g.addV("aai-node-type","complex","physical-location-id","a-name").next();
516                 
517                 Edge e1 = testEdgeRules.addEdge(g, gvnf, complex);
518                 Edge e2 = testEdgeRules.addEdge(g, gvnf, complex, "complex-generic-vnf-B");
519                 
520                 QueryBuilder<Edge> tQ = getNewEdgeTraversalWithTestEdgeRules(gvnf);
521                 tQ.getEdgesBetween(EdgeType.COUSIN, "generic-vnf", "complex");
522                 
523                 List<Edge> list = tQ.toList();
524         
525                 assertEquals("Has 2 edges ", 2, list.size());
526                 assertTrue("result has default edge ", list.contains(e1));
527                 assertTrue("result has other edge ", list.contains(e2));
528                 
529
530         }
531         
532         @Test
533         public void edgeTraversalMultiRuleTraversalTest() throws AAIException {
534                                 
535                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
536                 Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
537                 Vertex vnfc2 = g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
538                 
539                 Edge e1 = testEdgeRules.addEdge(g, gvnf, vnfc1);
540                 Edge e2 = testEdgeRules.addEdge(g, gvnf, vnfc2, "re-uses");
541                 
542                 QueryBuilder<Edge> tQ = getNewEdgeTraversalWithTestEdgeRules(gvnf);
543                 tQ.getEdgesBetween(EdgeType.COUSIN, "generic-vnf", "vnfc");
544                 
545                 List<Edge> list = tQ.toList();
546
547                 assertEquals("Has 2 edges ", 2, list.size());
548                 assertTrue("result has default edge ", list.contains(e1));
549                 assertTrue("result has other edge ", list.contains(e2));
550                 
551
552         }
553
554         @Test (expected = NoEdgeRuleFoundException.class)
555         public void getEdgesBetweenWithLabelsEmptyListTest() throws AAIException {
556
557                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
558                 Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
559
560                 testEdgeRules.addEdge(g, gvnf, pserver);
561                 testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
562
563                 QueryBuilder<Edge> tQ = getNewEdgeTraversalWithTestEdgeRules(gvnf);
564                 tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Collections.emptyList());
565
566         }
567
568         @Test
569         public void getEdgesBetweenWithLabelsSingleItemTest() throws AAIException {
570
571                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
572                 Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
573
574                 Edge e1 = testEdgeRules.addEdge(g, gvnf, pserver);
575                 Edge e2 = testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
576
577                 QueryBuilder<Edge> tQ = getNewEdgeTraversalWithTestEdgeRules(gvnf);
578                 tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Collections.singletonList("generic-vnf-pserver-B"));
579
580                 List<Edge> list = tQ.toList();
581
582                 assertEquals("Has 1 edges ", 1, list.size());
583                 assertFalse("result does not have default edge ", list.contains(e1));
584                 assertTrue("result has other edge ", list.contains(e2));
585
586         }
587
588         @Test
589         public void getEdgesBetweenWithLabelsMultipleItemTest() throws AAIException {
590
591                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
592                 Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
593
594                 Edge e1 = testEdgeRules.addEdge(g, gvnf, pserver);
595                 Edge e2 = testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
596
597                 QueryBuilder<Edge> tQ = getNewEdgeTraversalWithTestEdgeRules(gvnf);
598                 tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Arrays.asList("generic-vnf-pserver-B", "generic-vnf-pserver-A"));
599
600                 List<Edge> list = tQ.toList();
601
602                 assertEquals("Has 2 edges ", 2, list.size());
603                 assertTrue("result has generic-vnf-pserver-A edge ", list.contains(e1));
604                 assertTrue("result has generic-vnf-pserver-B edge ", list.contains(e2));
605
606         }
607
608         @Test (expected = NoEdgeRuleFoundException.class)
609         public void createEdgeTraversalWithLabelsEmptyListTest() throws AAIException {
610
611                 Vertex gvnf = getVertex();
612
613                 QueryBuilder<Edge> tQ = getNewEdgeTraversalWithTestEdgeRules(gvnf);
614                 tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Collections.emptyList());
615
616                 tQ.toList();
617
618
619         }
620
621         private Vertex getVertex() throws AAIException {
622                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
623                 Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
624
625                 testEdgeRules.addEdge(g, gvnf, pserver);
626                 testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
627                 return gvnf;
628         }
629
630         @Test
631         public void createEdgeTraversalWithLabelsSingleItemTest() throws AAIException {
632
633                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
634                 Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
635
636                 Edge e1 = testEdgeRules.addEdge(g, gvnf, pserver);
637                 Edge e2 = testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
638
639                 QueryBuilder<Edge> tQ = getNewEdgeTraversalWithTestEdgeRules(gvnf);
640                 tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Collections.singletonList("generic-vnf-pserver-B"));
641
642                 List<Edge> list = tQ.toList();
643
644                 assertEquals("Has 1 edges ", 1, list.size());
645                 assertFalse("result does not have default edge ", list.contains(e1));
646                 assertTrue("result has other edge ", list.contains(e2));
647
648         }
649
650         @Test
651         public void createEdgeTraversalWithLabelsMultipleItemTest() throws AAIException {
652
653                 Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
654                 Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
655
656                 Edge e1 = testEdgeRules.addEdge(g, gvnf, pserver);
657                 Edge e2 = testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
658
659                 QueryBuilder<Edge> tQ = getNewEdgeTraversalWithTestEdgeRules(gvnf);
660                 tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Arrays.asList("generic-vnf-pserver-B", "generic-vnf-pserver-A"));
661
662                 List<Edge> list = tQ.toList();
663
664                 assertEquals("Has 2 edges ", 2, list.size());
665                 assertTrue("result has generic-vnf-pserver-A edge ", list.contains(e1));
666                 assertTrue("result has generic-vnf-pserver-B edge ", list.contains(e2));
667
668         }
669
670         protected abstract QueryBuilder<Edge> getNewEdgeTraversalWithTestEdgeRules(Vertex v);
671         
672         protected abstract QueryBuilder<Edge> getNewEdgeTraversalWithTestEdgeRules();
673         
674         protected abstract QueryBuilder<Vertex> getNewVertexTraversalWithTestEdgeRules(Vertex v);
675         
676         protected abstract QueryBuilder<Vertex> getNewVertexTraversalWithTestEdgeRules();
677
678         protected abstract QueryBuilder<Tree> getNewTreeTraversalWithTestEdgeRules(Vertex v);
679
680         protected abstract QueryBuilder<Tree> getNewTreeTraversalWithTestEdgeRules();
681
682         protected abstract QueryBuilder<Path> getNewPathTraversalWithTestEdgeRules(Vertex v);
683
684         protected abstract QueryBuilder<Path> getNewPathTraversalWithTestEdgeRules();
685                 
686 }