EdgeRules throws descriptive error on invalid rule
[aai/aai-common.git] / aai-core / src / test / java / org / openecomp / aai / parsers / query / GraphTraversalTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.openecomp.aai
4  * ================================================================================
5  * Copyright (C) 2017 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
21 package org.openecomp.aai.parsers.query;
22
23 import org.apache.tinkerpop.gremlin.process.traversal.P;
24 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
25 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
26 import org.apache.tinkerpop.gremlin.structure.Vertex;
27 import org.junit.Before;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.rules.ExpectedException;
31 import org.openecomp.aai.AAISetup;
32 import org.openecomp.aai.db.props.AAIProperties;
33 import org.openecomp.aai.exceptions.AAIException;
34 import org.openecomp.aai.introspection.LoaderFactory;
35 import org.openecomp.aai.introspection.ModelType;
36 import org.openecomp.aai.introspection.Version;
37 import org.openecomp.aai.rest.RestTokens;
38 import org.openecomp.aai.serialization.engines.QueryStyle;
39 import org.openecomp.aai.serialization.engines.TitanDBEngine;
40 import org.openecomp.aai.serialization.engines.TransactionalGraphEngine;
41
42 import javax.ws.rs.core.MultivaluedHashMap;
43 import javax.ws.rs.core.MultivaluedMap;
44 import javax.ws.rs.core.UriBuilder;
45 import java.io.UnsupportedEncodingException;
46 import java.net.URI;
47 import java.util.ArrayList;
48 import java.util.List;
49
50 import static org.hamcrest.CoreMatchers.containsString;
51 import static org.hamcrest.Matchers.hasProperty;
52 import static org.hamcrest.Matchers.is;
53 import static org.junit.Assert.assertEquals;
54
55 public class GraphTraversalTest extends AAISetup {
56
57         private TransactionalGraphEngine dbEngine;
58         private TransactionalGraphEngine dbEnginev9;
59         
60         @Rule
61         public ExpectedException thrown = ExpectedException.none();
62         
63         /**
64          * Configure.
65          * @throws Exception 
66          * @throws SecurityException 
67          * @throws NoSuchFieldException 
68          */
69         @Before
70         public void configure() throws Exception {
71                 dbEngine =
72                                 new TitanDBEngine(QueryStyle.TRAVERSAL, 
73                                         LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST),
74                                         false);
75                 
76                 dbEnginev9 = 
77                                 new TitanDBEngine(QueryStyle.TRAVERSAL, 
78                                         LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v9),
79                                         false);
80         }
81         
82         /**
83          * Parent query.
84          *
85          * @throws UnsupportedEncodingException the unsupported encoding exception
86          * @throws AAIException the AAI exception
87          */
88         @Test
89     public void parentQuery() throws UnsupportedEncodingException, AAIException {
90                 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1").build();
91                 
92                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
93                 
94                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
95                 assertEquals(
96                                 "gremlin query should be " + expected.toString(),
97                                 expected.toString(),
98                                 query.getQueryBuilder().getQuery().toString());
99                 assertEquals(
100                                 "parent gremlin query should be equal to normal query",
101                                 expected.toString(),
102                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
103                 assertEquals(
104                                 "result type should be complex",
105                                 "complex",
106                                 query.getResultType());
107                 assertEquals(
108                                 "result type should be empty",
109                                 "",
110                                 query.getParentResultType());
111                 assertEquals("dependent",false, query.isDependent());
112
113                 
114     }
115
116         /**
117          * Child query.
118          *
119          * @throws UnsupportedEncodingException the unsupported encoding exception
120          * @throws AAIException the AAI exception
121          */
122         @Test
123     public void childQuery() throws UnsupportedEncodingException, AAIException {
124                 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3").build();
125                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
126                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
127                                 .has("physical-location-id", "key1").has("aai-node-type", "complex")
128                                 .out("hasCtagPool")
129                                 .has("aai-node-type", "ctag-pool")
130                                 .has("target-pe", "key2").has("availability-zone-name", "key3");
131                 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
132                                 .has("physical-location-id", "key1").has("aai-node-type", "complex");
133                 assertEquals(
134                                 "gremlin query should be " + expected.toString(),
135                                 expected.toString(),
136                                 query.getQueryBuilder().getQuery().toString());
137                 assertEquals(
138                                 "parent gremlin query should be equal the query for complex",
139                                 expectedParent.toString(),
140                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
141                 assertEquals(
142                                 "result type should be complex",
143                                 "complex",
144                                 query.getParentResultType());
145                 assertEquals(
146                                 "result type should be ctag-pool",
147                                 "ctag-pool",
148                                 query.getResultType());
149                 assertEquals("dependent",true, query.isDependent());
150
151                 
152     }
153         
154         /**
155          * Naming exceptions.
156          *
157          * @throws UnsupportedEncodingException the unsupported encoding exception
158          * @throws AAIException the AAI exception
159          */
160         @Test
161     public void namingExceptions() throws UnsupportedEncodingException, AAIException {
162                 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
163                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
164                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
165                                 .has("vnf-id", "key1").has("aai-node-type", "vce")
166                                 .out("hasPortGroup")
167                                 .has("aai-node-type", "port-group")
168                                 .has("interface-id", "key2").out("hasCTag")
169                                 .has("aai-node-type", "cvlan-tag")
170                                 .has("cvlan-tag", 655);
171                 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
172                                 .has("vnf-id", "key1").has("aai-node-type", "vce")
173                                 .out("hasPortGroup")
174                                 .has("aai-node-type", "port-group")
175                                 .has("interface-id", "key2");
176                 assertEquals(
177                                 "gremlin query should be " + expected.toString(),
178                                 expected.toString(),
179                                 query.getQueryBuilder().getQuery().toString());
180                 assertEquals(
181                                 "parent gremlin query should be equal the query for port group",
182                                 expectedParent.toString(),
183                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
184                 assertEquals(
185                                 "result type should be cvlan-tag",
186                                 "cvlan-tag",
187                                 query.getResultType());
188                 assertEquals(
189                                 "result type should be port-group",
190                                 "port-group",
191                                 query.getParentResultType());
192                 assertEquals(
193                                 "contaner type should be empty",
194                                 "",
195                                 query.getContainerType());
196                 assertEquals("dependent",true, query.isDependent());
197
198                 
199     }
200         
201         /**
202          * Gets the all.
203          *
204          * @return the all
205          * @throws UnsupportedEncodingException the unsupported encoding exception
206          * @throws AAIException the AAI exception
207          */
208         @Test
209     public void getAll() throws UnsupportedEncodingException, AAIException {
210                 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags").build();
211                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
212                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
213                                 .has("vnf-id", "key1").has("aai-node-type", "vce")
214                                 .out("hasPortGroup")
215                                 .has("aai-node-type", "port-group")
216                                 .has("interface-id", "key2").out("hasCTag")
217                                 .has("aai-node-type", "cvlan-tag");
218                 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
219                                 .has("vnf-id", "key1").has("aai-node-type", "vce")
220                                 .out("hasPortGroup")
221                                 .has("aai-node-type", "port-group")
222                                 .has("interface-id", "key2");
223                 assertEquals(
224                                 "gremlin query should be " + expected.toString(),
225                                 expected.toString(),
226                                 query.getQueryBuilder().getQuery().toString());
227                 assertEquals(
228                                 "parent gremlin query should be equal the query for port group",
229                                 expectedParent.toString(),
230                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
231                 assertEquals(
232                                 "result type should be port-group",
233                                 "port-group",
234                                 query.getParentResultType());
235                 assertEquals(
236                                 "result type should be cvlan-tag",
237                                 "cvlan-tag",
238                                 query.getResultType());
239                 assertEquals(
240                                 "container type should be cvlan-tags",
241                                 "cvlan-tags",
242                                 query.getContainerType());
243                 assertEquals("dependent",true, query.isDependent());
244
245                 
246     }
247         
248         @Test
249     public void getAllParent() throws UnsupportedEncodingException, AAIException {
250                 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers").build();
251                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
252                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
253                                 .has("aai-node-type", "pserver");
254                 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
255                                 .has("aai-node-type", "pserver");
256                 assertEquals(
257                                 "gremlin query should be " + expected.toString(),
258                                 expected.toString(),
259                                 query.getQueryBuilder().getQuery().toString());
260                 assertEquals(
261                                 "parent gremlin query should be equal the query for pserver",
262                                 expectedParent.toString(),
263                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
264                 assertEquals(
265                                 "parent result type should be empty",
266                                 "",
267                                 query.getParentResultType());
268                 assertEquals(
269                                 "result type should be pserver",
270                                 "pserver",
271                                 query.getResultType());
272                 assertEquals(
273                                 "container type should be pservers",
274                                 "pservers",
275                                 query.getContainerType());
276                 assertEquals("dependent",false, query.isDependent());
277
278                 
279     }
280         
281         
282         /**
283          * Gets the via query param.
284          *
285          * @return the via query param
286          * @throws UnsupportedEncodingException the unsupported encoding exception
287          * @throws AAIException the AAI exception
288          */
289         @Test
290         public void getViaQueryParam() throws UnsupportedEncodingException, AAIException {
291                 URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant").build();
292                 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
293                 map.putSingle("tenant-name", "Tenant1");
294                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
295                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
296                                 .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
297                                 .has("aai-node-type", "cloud-region")
298                                 .out("has")
299                                 .has("aai-node-type", "tenant")
300                                 .has("tenant-name", "Tenant1");
301
302                 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
303                                 .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
304                                 .has("aai-node-type", "cloud-region");
305                                                 
306                 assertEquals(
307                                 "gremlin query should be " + expected.toString(),
308                                 expected.toString(),
309                                 query.getQueryBuilder().getQuery().toString());
310                 assertEquals(
311                                 "parent gremlin query should be equal the query for cloud-region",
312                                 expectedParent.toString(),
313                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
314                 assertEquals(
315                                 "result type should be cloud-region",
316                                 "cloud-region",
317                                 query.getParentResultType());
318                 assertEquals(
319                                 "result type should be tenant",
320                                 "tenant",
321                                 query.getResultType());
322                 assertEquals(
323                                 "container type should be empty",
324                                 "",
325                                 query.getContainerType());
326                 assertEquals("dependent",true, query.isDependent());
327
328         }
329         
330         @Test
331         public void getViaDuplicateQueryParam() throws UnsupportedEncodingException, AAIException {
332                 URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant").build();
333                 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
334                 List<String> values = new ArrayList<>();
335                 values.add("Tenant1");
336                 values.add("Tenant2");
337                 map.put("tenant-name", values);
338                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
339                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
340                                 .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
341                                 .has("aai-node-type", "cloud-region")
342                                 .out("has")
343                                 .has("aai-node-type", "tenant")
344                                 .has("tenant-name", P.within(values));
345
346                 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
347                                 .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
348                                 .has("aai-node-type", "cloud-region");
349                                                 
350                 assertEquals(
351                                 "gremlin query should be " + expected.toString(),
352                                 expected.toString(),
353                                 query.getQueryBuilder().getQuery().toString());
354                 assertEquals(
355                                 "parent gremlin query should be equal the query for cloud-region",
356                                 expectedParent.toString(),
357                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
358                 assertEquals(
359                                 "result type should be cloud-region",
360                                 "cloud-region",
361                                 query.getParentResultType());
362                 assertEquals(
363                                 "result type should be tenant",
364                                 "tenant",
365                                 query.getResultType());
366                 assertEquals(
367                                 "container type should be empty",
368                                 "",
369                                 query.getContainerType());
370                 assertEquals("dependent",true, query.isDependent());
371
372         }
373         
374         /**
375          * Gets the plural via query param.
376          *
377          * @return the plural via query param
378          * @throws UnsupportedEncodingException the unsupported encoding exception
379          * @throws AAIException the AAI exception
380          */
381         @Test
382         public void getPluralViaQueryParam() throws UnsupportedEncodingException, AAIException {
383                 URI uri = UriBuilder.fromPath("network/vnfcs").build();
384                 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
385                 map.putSingle("prov-status", "up");
386                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
387                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
388                                 .has("aai-node-type", "vnfc")
389                                 .has("prov-status", "up");
390
391                 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
392                                 .has("aai-node-type", "vnfc");
393                                         
394                 assertEquals(
395                                 "gremlin query should be " + expected.toString(),
396                                 expected.toString(),
397                                 query.getQueryBuilder().getQuery().toString());
398                 assertEquals(
399                                 "parent",
400                                 expectedParent.toString(),
401                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
402                 assertEquals(
403                                 "parent result type should be empty",
404                                 "",
405                                 query.getParentResultType());
406                 assertEquals(
407                                 "result type should be vnfc",
408                                 "vnfc",
409                                 query.getResultType());
410                 assertEquals(
411                                 "container type should be empty",
412                                 "vnfcs",
413                                 query.getContainerType());
414                 assertEquals("dependent",true, query.isDependent());
415
416         }
417         
418         /**
419          * Gets the all query param naming exception.
420          *
421          * @return the all query param naming exception
422          * @throws UnsupportedEncodingException the unsupported encoding exception
423          * @throws AAIException the AAI exception
424          */
425         @Test
426     public void getAllQueryParamNamingException() throws UnsupportedEncodingException, AAIException {
427                 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags").build();
428                 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
429                 map.putSingle("cvlan-tag", "333");
430                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
431                 
432                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
433                                 .has("vnf-id", "key1").has("aai-node-type", "vce")
434                                 .out("hasPortGroup")
435                                 .has("aai-node-type", "port-group")
436                                 .has("interface-id", "key2").out("hasCTag")
437                                 .has("aai-node-type", "cvlan-tag")
438                                 .has("cvlan-tag", 333);
439                 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
440                                 .has("vnf-id", "key1").has("aai-node-type", "vce")
441                                 .out("hasPortGroup")
442                                 .has("aai-node-type", "port-group")
443                                 .has("interface-id", "key2");
444                 assertEquals(
445                                 "gremlin query should be " + expected.toString(),
446                                 expected.toString(),
447                                 query.getQueryBuilder().getQuery().toString());
448                 assertEquals(
449                                 "parent gremlin query should be equal the query for port group",
450                                 expectedParent.toString(),
451                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
452                 assertEquals(
453                                 "result type should be port-group",
454                                 "port-group",
455                                 query.getParentResultType());
456                 assertEquals(
457                                 "result type should be cvlan-tag",
458                                 "cvlan-tag",
459                                 query.getResultType());
460                 assertEquals(
461                                 "container type should be cvlan-tags",
462                                 "cvlan-tags",
463                                 query.getContainerType());
464                 assertEquals("dependent",true, query.isDependent());
465
466                 
467     }
468         
469         /**
470          * Abstract type.
471          *
472          * @throws UnsupportedEncodingException the unsupported encoding exception
473          * @throws AAIException the AAI exception
474          */
475         @Test
476     public void abstractType() throws UnsupportedEncodingException, AAIException {
477                 URI uri = UriBuilder.fromPath("vnf/key1").build();
478
479                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
480                 
481                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
482                                 .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"));
483                         
484                 GraphTraversal<Vertex, Vertex> expectedParent = expected;
485                 assertEquals(
486                                 "gremlin query should be " + expected.toString(),
487                                 expected.toString(),
488                                 query.getQueryBuilder().getQuery().toString());
489                 assertEquals(
490                                 "parent gremlin query should be equal the query for port group",
491                                 expectedParent.toString(),
492                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
493                 assertEquals(
494                                 "result type should be empty",
495                                 "",
496                                 query.getParentResultType());
497                 assertEquals(
498                                 "result type should be vnf",
499                                 "vnf",
500                                 query.getResultType());
501                 
502                 assertEquals("dependent",false, query.isDependent());
503
504                 
505     }
506         
507         /**
508          * Non parent abstract type.
509          *
510          * @throws UnsupportedEncodingException the unsupported encoding exception
511          * @throws AAIException the AAI exception
512          */
513         @Test
514     public void nonParentAbstractType() throws UnsupportedEncodingException, AAIException {
515                 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key2/vnf/key1").build();
516                 thrown.expect(AAIException.class);
517                 thrown.expectMessage(containsString("not a valid path"));
518                 dbEngine.getQueryBuilder().createQueryFromURI(uri);
519     }
520         
521         @Test
522         public void parentAbstractTypeWithNesting() throws UnsupportedEncodingException, AAIException {
523                 URI uri = UriBuilder.fromPath("vnf/key1/vf-modules/vf-module/key2").build();
524                 
525                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
526                 
527                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
528                                 .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"))
529                                 .union(__.out("has").has(AAIProperties.NODE_TYPE, "vf-module")).has("vf-module-id", "key2");
530                 
531                 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
532                                 .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"));
533                 assertEquals(
534                                 "gremlin query should be " + expected.toString(),
535                                 expected.toString(),
536                                 query.getQueryBuilder().getQuery().toString());
537                 assertEquals(
538                                 "parent gremlin query should be equal the query for ",
539                                 expectedParent.toString(),
540                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
541                 assertEquals(
542                                 "result type should be vnf",
543                                 "vnf",
544                                 query.getParentResultType());
545                 assertEquals(
546                                 "result type should be vf-module",
547                                 "vf-module",
548                                 query.getResultType());
549                 
550                 assertEquals("dependent",true, query.isDependent());
551                 
552         }
553         
554         @Test
555         public void getViaBadQueryParam() throws UnsupportedEncodingException, AAIException {
556                 URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/a/b/tenants/tenant").build();
557                 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
558                 map.putSingle("tenant-n231ame", "Tenant1");
559                 thrown.expect(AAIException.class);
560                 thrown.expect(hasProperty("code", is("AAI_3000")));
561                 
562                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
563
564         }
565         
566         @Test
567         public void getPluralViaBadQueryParam() throws UnsupportedEncodingException, AAIException {
568                 URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/a/b/tenants").build();
569                 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
570                 map.putSingle("tenant-n231ame", "Tenant1");
571                 thrown.expect(AAIException.class);
572                 thrown.expect(hasProperty("code", is("AAI_3000")));
573                 
574                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
575
576         }
577         
578         @Test
579         public void getPluralViaDuplicateQueryParam() throws UnsupportedEncodingException, AAIException {
580                 URI uri = UriBuilder.fromPath("network/vnfcs").build();
581                 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
582                 List<String> values = new ArrayList<>();
583                 values.add("up");
584                 values.add("down");
585                 values.add("left");
586                 values.add("right");
587                 values.add("start");
588                 map.put("prov-status", values);
589                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
590                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
591                                 .has("aai-node-type", "vnfc")
592                                 .has("prov-status", P.within(values));
593
594                 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
595                                 .has("aai-node-type", "vnfc");
596                                         
597                 assertEquals(
598                                 "gremlin query should be " + expected.toString(),
599                                 expected.toString(),
600                                 query.getQueryBuilder().getQuery().toString());
601                 assertEquals(
602                                 "parent",
603                                 expectedParent.toString(),
604                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
605                 assertEquals(
606                                 "parent result type should be empty",
607                                 "",
608                                 query.getParentResultType());
609                 assertEquals(
610                                 "result type should be vnfc",
611                                 "vnfc",
612                                 query.getResultType());
613                 assertEquals(
614                                 "container type should be empty",
615                                 "vnfcs",
616                                 query.getContainerType());
617                 assertEquals("dependent",true, query.isDependent());
618
619         }
620         
621         @Test
622         public void dbAliasedSearch() throws UnsupportedEncodingException, AAIException {
623                 URI uri = UriBuilder.fromPath("network/test-objects").build();
624                 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
625                 map.putSingle("persona-model-customization-id", "key2");
626                 QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri, map);
627                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
628                                 .has("aai-node-type", "test-object")
629                                 .has("model-customization-id", "key2");
630                 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
631                                 .has("aai-node-type", "test-object");
632                 
633                 assertEquals(
634                                 "gremlin query should be " + expected.toString(),
635                                 expected.toString(),
636                                 query.getQueryBuilder().getQuery().toString());
637                 assertEquals(
638                                 "parent",
639                                 expectedParent.toString(),
640                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
641                 
642                 assertEquals(
643                                 "result type should be",
644                                 "test-object",
645                                 query.getResultType());
646                 assertEquals(
647                                 "result type should be empty",
648                                 "",
649                                 query.getParentResultType());
650                 assertEquals("dependent",true, query.isDependent());
651                 
652         
653         }
654         
655         @Test
656         public void dataLinkedSearch() throws UnsupportedEncodingException, AAIException {
657                 URI uri = UriBuilder.fromPath("network/vpn-bindings").build();
658                 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
659                 map.putSingle("global-route-target", "key2");
660                 QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri, map);
661                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
662                                 .has("aai-node-type", "vpn-binding")
663                                 .where(__.out("has").has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "key2"));
664                 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
665                                 .has("aai-node-type", "vpn-binding");
666                 
667                 assertEquals(
668                                 "gremlin query should be " + expected.toString(),
669                                 expected.toString(),
670                                 query.getQueryBuilder().getQuery().toString());
671                 assertEquals(
672                                 "parent",
673                                 expectedParent.toString(),
674                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
675                 
676                 assertEquals(
677                                 "result type should be",
678                                 "vpn-binding",
679                                 query.getResultType());
680                 assertEquals(
681                                 "result type should be empty",
682                                 "",
683                                 query.getParentResultType());
684                 assertEquals("dependent",true, query.isDependent());
685         }
686
687         @Test
688         public void pluralCousin() throws UnsupportedEncodingException, AAIException {
689                 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers").build();
690
691                 QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri);
692                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
693                                 .has("physical-location-id", "key1")
694                                 .has("aai-node-type", "complex")
695                                 .in("locatedIn").has("aai-node-type", "pserver");
696                 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
697                                 .has("physical-location-id", "key1")
698                                 .has("aai-node-type", "complex");
699
700                 assertEquals(
701                                 "gremlin query should be " + expected.toString(),
702                                 expected.toString(),
703                                 query.getQueryBuilder().getQuery().toString());
704                 assertEquals(
705                                 "parent",
706                                 expectedParent.toString(),
707                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
708
709                 assertEquals(
710                                 "result type should be",
711                                 "pserver",
712                                 query.getResultType());
713                 assertEquals(
714                                 "result type should be",
715                                 "complex",
716                                 query.getParentResultType());
717                 //this is controversial but we're not allowing writes on this currently
718                 assertEquals("dependent",true, query.isDependent());
719         }
720
721         @Test
722         public void specificCousin() throws UnsupportedEncodingException, AAIException {
723                 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2").build();
724
725                 QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri);
726                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
727                                 .has("physical-location-id", "key1")
728                                 .has("aai-node-type", "complex")
729                                 .in("locatedIn").has("aai-node-type", "pserver")
730                                 .has("hostname", "key2");
731                 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
732                                 .has("physical-location-id", "key1")
733                                 .has("aai-node-type", "complex");
734
735                 assertEquals(
736                                 "gremlin query should be " + expected.toString(),
737                                 expected.toString(),
738                                 query.getQueryBuilder().getQuery().toString());
739                 assertEquals(
740                                 "parent",
741                                 expectedParent.toString(),
742                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
743
744                 assertEquals(
745                                 "result type should be",
746                                 "pserver",
747                                 query.getResultType());
748                 assertEquals(
749                                 "result type should be",
750                                 "complex",
751                                 query.getParentResultType());
752                 //this is controversial but we're not allowing writes on this currently
753                 assertEquals("dependent",true, query.isDependent());
754         }
755
756         @Test
757         public void doubleSpecificCousin() throws UnsupportedEncodingException, AAIException {
758                 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2/related-to/vservers/vserver/key3").build();
759
760                 QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri);
761                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
762                                 .has("physical-location-id", "key1")
763                                 .has("aai-node-type", "complex")
764                                 .in("locatedIn").has("aai-node-type", "pserver")
765                                 .has("hostname", "key2")
766                                 .in("runsOnPserver").has("aai-node-type", "vserver")
767                                 .has("vserver-id", "key3");
768                 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
769                                 .has("physical-location-id", "key1")
770                                 .has("aai-node-type", "complex")
771                                 .in("locatedIn").has("aai-node-type", "pserver")
772                                 .has("hostname", "key2");
773
774                 assertEquals(
775                                 "gremlin query should be " + expected.toString(),
776                                 expected.toString(),
777                                 query.getQueryBuilder().getQuery().toString());
778                 assertEquals(
779                                 "parent",
780                                 expectedParent.toString(),
781                                 query.getQueryBuilder().getParentQuery().getQuery().toString());
782
783                 assertEquals(
784                                 "result type should be",
785                                 "vserver",
786                                 query.getResultType());
787                 assertEquals(
788                                 "result type should be",
789                                 "pserver",
790                                 query.getParentResultType());
791                 //this is controversial but we're not allowing writes on this currently
792                 assertEquals("dependent",true, query.isDependent());
793         }
794
795         @Test
796         public void traversalEndsInRelatedTo() throws UnsupportedEncodingException, AAIException {
797                 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to").build();
798
799                 thrown.expect(AAIException.class);
800                 thrown.expectMessage(containsString(RestTokens.COUSIN.toString()));
801                 QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri);
802
803         }
804
805         @Test
806         public void pluralCousinToPluralCousin() throws UnsupportedEncodingException, AAIException {
807                 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/related-to/pservers").build();
808
809                 thrown.expect(AAIException.class);
810                 thrown.expectMessage(containsString("chain plurals"));
811                 QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri);
812         
813         }
814 }