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