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