Reduce the number of problems in aai-common by removing unused imports
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / parsers / query / GraphTraversalTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.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.Arrays;
32 import java.util.Collection;
33 import java.util.List;
34
35 import javax.ws.rs.core.MultivaluedHashMap;
36 import javax.ws.rs.core.MultivaluedMap;
37 import javax.ws.rs.core.UriBuilder;
38
39 import org.apache.tinkerpop.gremlin.process.traversal.P;
40 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
41 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
42 import org.apache.tinkerpop.gremlin.structure.Vertex;
43 import org.junit.Before;
44 import org.junit.Rule;
45 import org.junit.Test;
46 import org.junit.rules.ExpectedException;
47 import org.junit.runner.RunWith;
48 import org.junit.runners.Parameterized;
49 import org.onap.aai.DataLinkSetup;
50 import org.onap.aai.db.props.AAIProperties;
51 import org.onap.aai.exceptions.AAIException;
52 import org.onap.aai.introspection.ModelType;
53 import org.onap.aai.rest.RestTokens;
54 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
55 import org.onap.aai.serialization.engines.QueryStyle;
56 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
57 import org.springframework.test.annotation.DirtiesContext;
58
59 @RunWith(value = Parameterized.class)
60 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
61 public class GraphTraversalTest extends DataLinkSetup {
62
63     private TransactionalGraphEngine dbEngine;
64     private TransactionalGraphEngine dbEngineDepthVersion;
65
66     @Parameterized.Parameter(value = 0)
67     public QueryStyle queryStyle;
68
69     @Parameterized.Parameters(name = "QueryStyle.{0}")
70     public static Collection<Object[]> data() {
71         return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
72     }
73
74     @Rule
75     public ExpectedException thrown = ExpectedException.none();
76
77     /**
78      * Configure.
79      * 
80      * @throws Exception
81      * @throws SecurityException
82      * @throws NoSuchFieldException
83      */
84     @Before
85     public void configure() throws Exception {
86         dbEngine = new JanusGraphDBEngine(queryStyle,
87                 loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()), false);
88
89         dbEngineDepthVersion = new JanusGraphDBEngine(queryStyle,
90                 loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()), false);
91     }
92
93     /**
94      * Parent query.
95      *
96      * @throws UnsupportedEncodingException the unsupported encoding exception
97      * @throws AAIException the AAI exception
98      */
99     @Test
100     public void parentQuery() throws UnsupportedEncodingException, AAIException {
101         URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1").build();
102
103         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
104
105         GraphTraversal<Vertex, Vertex> expected =
106                 __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
107         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
108                 query.getQueryBuilder().getQuery().toString());
109         assertEquals("parent gremlin query should be equal to normal query", expected.toString(),
110                 query.getQueryBuilder().getParentQuery().getQuery().toString());
111         assertEquals("result type should be complex", "complex", query.getResultType());
112         assertEquals("result type should be empty", "", query.getParentResultType());
113         assertEquals("dependent", false, query.isDependent());
114
115     }
116
117     /**
118      * Child query.
119      *
120      * @throws UnsupportedEncodingException the unsupported encoding exception
121      * @throws AAIException the AAI exception
122      */
123     @Test
124     public void childQuery() throws UnsupportedEncodingException, AAIException {
125         URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3")
126                 .build();
127         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
128         GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1")
129                 .has("aai-node-type", "complex").in("org.onap.relationships.inventory.BelongsTo")
130                 .has("aai-node-type", "ctag-pool").has("target-pe", "key2").has("availability-zone-name", "key3");
131         GraphTraversal<Vertex, Vertex> expectedParent =
132                 __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
133         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
134                 query.getQueryBuilder().getQuery().toString());
135         assertEquals("parent gremlin query should be equal the query for complex", expectedParent.toString(),
136                 query.getQueryBuilder().getParentQuery().getQuery().toString());
137         assertEquals("result type should be complex", "complex", query.getParentResultType());
138         assertEquals("result type should be ctag-pool", "ctag-pool", query.getResultType());
139         assertEquals("dependent", true, query.isDependent());
140
141     }
142
143     /**
144      * Naming exceptions.
145      *
146      * @throws UnsupportedEncodingException the unsupported encoding exception
147      * @throws AAIException the AAI exception
148      */
149     @Test
150     public void namingExceptions() throws UnsupportedEncodingException, AAIException {
151         URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655")
152                 .build();
153         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
154         GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "vce")
155                 .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "port-group")
156                 .has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
157                 .has("aai-node-type", "cvlan-tag").has("cvlan-tag", 655);
158         GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("vnf-id", "key1")
159                 .has("aai-node-type", "vce").in("org.onap.relationships.inventory.BelongsTo")
160                 .has("aai-node-type", "port-group").has("interface-id", "key2");
161         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
162                 query.getQueryBuilder().getQuery().toString());
163         assertEquals("parent gremlin query should be equal the query for port group", expectedParent.toString(),
164                 query.getQueryBuilder().getParentQuery().getQuery().toString());
165         assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
166         assertEquals("result type should be port-group", "port-group", query.getParentResultType());
167         assertEquals("contaner type should be empty", "", query.getContainerType());
168         assertEquals("dependent", true, query.isDependent());
169
170     }
171
172     /**
173      * Gets the all.
174      *
175      * @return the all
176      * @throws UnsupportedEncodingException the unsupported encoding exception
177      * @throws AAIException the AAI exception
178      */
179     @Test
180     public void getAll() throws UnsupportedEncodingException, AAIException {
181         URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags").build();
182         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
183         GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "vce")
184                 .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "port-group")
185                 .has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
186                 .has("aai-node-type", "cvlan-tag");
187         GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("vnf-id", "key1")
188                 .has("aai-node-type", "vce").in("org.onap.relationships.inventory.BelongsTo")
189                 .has("aai-node-type", "port-group").has("interface-id", "key2");
190         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
191                 query.getQueryBuilder().getQuery().toString());
192         assertEquals("parent gremlin query should be equal the query for port group", expectedParent.toString(),
193                 query.getQueryBuilder().getParentQuery().getQuery().toString());
194         assertEquals("result type should be port-group", "port-group", query.getParentResultType());
195         assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
196         assertEquals("container type should be cvlan-tags", "cvlan-tags", query.getContainerType());
197         assertEquals("dependent", true, query.isDependent());
198
199     }
200
201     @Test
202     public void getAllParent() throws UnsupportedEncodingException, AAIException {
203         URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers").build();
204         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
205         GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-node-type", "pserver");
206         GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "pserver");
207         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
208                 query.getQueryBuilder().getQuery().toString());
209         assertEquals("parent gremlin query should be equal the query for pserver", expectedParent.toString(),
210                 query.getQueryBuilder().getParentQuery().getQuery().toString());
211         assertEquals("parent result type should be empty", "", query.getParentResultType());
212         assertEquals("result type should be pserver", "pserver", query.getResultType());
213         assertEquals("container type should be pservers", "pservers", query.getContainerType());
214         assertEquals("dependent", false, query.isDependent());
215
216     }
217
218     /**
219      * Gets the via query param.
220      *
221      * @return the via query param
222      * @throws UnsupportedEncodingException the unsupported encoding exception
223      * @throws AAIException the AAI exception
224      */
225     @Test
226     public void getViaQueryParam() throws UnsupportedEncodingException, AAIException {
227         URI uri = UriBuilder
228                 .fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant")
229                 .build();
230         MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
231         map.putSingle("tenant-name", "Tenant1");
232         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
233         GraphTraversal<Vertex, Vertex> expected =
234                 __.<Vertex>start().has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
235                         .has("aai-node-type", "cloud-region").in("org.onap.relationships.inventory.BelongsTo")
236                         .has("aai-node-type", "tenant").has("tenant-name", "Tenant1");
237
238         GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("cloud-owner", "mycloudowner")
239                 .has("cloud-region-id", "mycloudregionid").has("aai-node-type", "cloud-region");
240
241         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
242                 query.getQueryBuilder().getQuery().toString());
243         assertEquals("parent gremlin query should be equal the query for cloud-region", expectedParent.toString(),
244                 query.getQueryBuilder().getParentQuery().getQuery().toString());
245         assertEquals("result type should be cloud-region", "cloud-region", query.getParentResultType());
246         assertEquals("result type should be tenant", "tenant", query.getResultType());
247         assertEquals("container type should be empty", "", query.getContainerType());
248         assertEquals("dependent", true, query.isDependent());
249
250     }
251
252     @Test
253     public void getViaDuplicateQueryParam() throws UnsupportedEncodingException, AAIException {
254         URI uri = UriBuilder
255                 .fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant")
256                 .build();
257         MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
258         List<String> values = new ArrayList<>();
259         values.add("Tenant1");
260         values.add("Tenant2");
261         map.put("tenant-name", values);
262         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
263         GraphTraversal<Vertex, Vertex> expected =
264                 __.<Vertex>start().has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
265                         .has("aai-node-type", "cloud-region").in("org.onap.relationships.inventory.BelongsTo")
266                         .has("aai-node-type", "tenant").has("tenant-name", P.within(values));
267
268         GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("cloud-owner", "mycloudowner")
269                 .has("cloud-region-id", "mycloudregionid").has("aai-node-type", "cloud-region");
270
271         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
272                 query.getQueryBuilder().getQuery().toString());
273         assertEquals("parent gremlin query should be equal the query for cloud-region", expectedParent.toString(),
274                 query.getQueryBuilder().getParentQuery().getQuery().toString());
275         assertEquals("result type should be cloud-region", "cloud-region", query.getParentResultType());
276         assertEquals("result type should be tenant", "tenant", query.getResultType());
277         assertEquals("container type should be empty", "", query.getContainerType());
278         assertEquals("dependent", true, query.isDependent());
279
280     }
281
282     /**
283      * Gets the plural via query param.
284      *
285      * @return the plural via query param
286      * @throws UnsupportedEncodingException the unsupported encoding exception
287      * @throws AAIException the AAI exception
288      */
289     @Test
290     public void getPluralViaQueryParam() throws UnsupportedEncodingException, AAIException {
291         URI uri = UriBuilder.fromPath("network/vnfcs").build();
292         MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
293         map.putSingle("prov-status", "up");
294         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
295         GraphTraversal<Vertex, Vertex> expected =
296                 __.<Vertex>start().has("aai-node-type", "vnfc").has("prov-status", "up");
297
298         GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "vnfc");
299
300         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
301                 query.getQueryBuilder().getQuery().toString());
302         assertEquals("parent", expectedParent.toString(),
303                 query.getQueryBuilder().getParentQuery().getQuery().toString());
304         assertEquals("parent result type should be empty", "", query.getParentResultType());
305         assertEquals("result type should be vnfc", "vnfc", query.getResultType());
306         assertEquals("container type should be empty", "vnfcs", query.getContainerType());
307         assertEquals("dependent", true, query.isDependent());
308
309     }
310
311     /**
312      * Gets the all query param naming exception.
313      *
314      * @return the all query param naming exception
315      * @throws UnsupportedEncodingException the unsupported encoding exception
316      * @throws AAIException the AAI exception
317      */
318     @Test
319     public void getAllQueryParamNamingException() throws UnsupportedEncodingException, AAIException {
320         URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags").build();
321         MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
322         map.putSingle("cvlan-tag", "333");
323         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
324
325         GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "vce")
326                 .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "port-group")
327                 .has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
328                 .has("aai-node-type", "cvlan-tag").has("cvlan-tag", 333);
329         GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("vnf-id", "key1")
330                 .has("aai-node-type", "vce").in("org.onap.relationships.inventory.BelongsTo")
331                 .has("aai-node-type", "port-group").has("interface-id", "key2");
332         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
333                 query.getQueryBuilder().getQuery().toString());
334         assertEquals("parent gremlin query should be equal the query for port group", expectedParent.toString(),
335                 query.getQueryBuilder().getParentQuery().getQuery().toString());
336         assertEquals("result type should be port-group", "port-group", query.getParentResultType());
337         assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
338         assertEquals("container type should be cvlan-tags", "cvlan-tags", query.getContainerType());
339         assertEquals("dependent", true, query.isDependent());
340
341     }
342
343     /**
344      * Abstract type.
345      *
346      * @throws UnsupportedEncodingException the unsupported encoding exception
347      * @throws AAIException the AAI exception
348      */
349     @Test
350     public void abstractType() throws UnsupportedEncodingException, AAIException {
351         URI uri = UriBuilder.fromPath("vnf/key1").build();
352
353         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
354
355         GraphTraversal<Vertex, Vertex> expected =
356                 __.<Vertex>start().has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"));
357
358         GraphTraversal<Vertex, Vertex> expectedParent = expected;
359         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
360                 query.getQueryBuilder().getQuery().toString());
361         assertEquals("parent gremlin query should be equal the query for port group", expectedParent.toString(),
362                 query.getQueryBuilder().getParentQuery().getQuery().toString());
363         assertEquals("result type should be empty", "", query.getParentResultType());
364         assertEquals("result type should be vnf", "vnf", query.getResultType());
365
366         assertEquals("dependent", false, query.isDependent());
367
368     }
369
370     /**
371      * Non parent abstract type.
372      *
373      * @throws UnsupportedEncodingException the unsupported encoding exception
374      * @throws AAIException the AAI exception
375      */
376     @Test
377     public void nonParentAbstractType() throws UnsupportedEncodingException, AAIException {
378         URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key2/vnf/key1").build();
379         thrown.expect(AAIException.class);
380         thrown.expectMessage(containsString("not a valid path"));
381         dbEngine.getQueryBuilder().createQueryFromURI(uri);
382     }
383
384     @Test
385     public void parentAbstractTypeWithNesting() throws UnsupportedEncodingException, AAIException {
386         URI uri = UriBuilder.fromPath("vnf/key1/vf-modules/vf-module/key2").build();
387
388         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
389
390         GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1")
391                 .has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"))
392                 .union(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "vf-module"))
393                 .has("vf-module-id", "key2");
394
395         GraphTraversal<Vertex, Vertex> expectedParent =
396                 __.<Vertex>start().has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"));
397         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
398                 query.getQueryBuilder().getQuery().toString());
399         assertEquals("parent gremlin query should be equal the query for ", expectedParent.toString(),
400                 query.getQueryBuilder().getParentQuery().getQuery().toString());
401         assertEquals("result type should be vnf", "vnf", query.getParentResultType());
402         assertEquals("result type should be vf-module", "vf-module", query.getResultType());
403
404         assertEquals("dependent", true, query.isDependent());
405
406     }
407
408     @Test
409     public void getViaBadQueryParam() throws UnsupportedEncodingException, AAIException {
410         URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/a/b/tenants/tenant").build();
411         MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
412         map.putSingle("tenant-n231ame", "Tenant1");
413         thrown.expect(AAIException.class);
414         thrown.expect(hasProperty("code", is("AAI_3000")));
415
416         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
417
418     }
419
420     @Test
421     public void getPluralViaBadQueryParam() throws UnsupportedEncodingException, AAIException {
422         URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/a/b/tenants").build();
423         MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
424         map.putSingle("tenant-n231ame", "Tenant1");
425         thrown.expect(AAIException.class);
426         thrown.expect(hasProperty("code", is("AAI_3000")));
427
428         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
429
430     }
431
432     @Test
433     public void getPluralViaDuplicateQueryParam() throws UnsupportedEncodingException, AAIException {
434         URI uri = UriBuilder.fromPath("network/vnfcs").build();
435         MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
436         List<String> values = new ArrayList<>();
437         values.add("up");
438         values.add("down");
439         values.add("left");
440         values.add("right");
441         values.add("start");
442         map.put("prov-status", values);
443         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
444         GraphTraversal<Vertex, Vertex> expected =
445                 __.<Vertex>start().has("aai-node-type", "vnfc").has("prov-status", P.within(values));
446
447         GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "vnfc");
448
449         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
450                 query.getQueryBuilder().getQuery().toString());
451         assertEquals("parent", expectedParent.toString(),
452                 query.getQueryBuilder().getParentQuery().getQuery().toString());
453         assertEquals("parent result type should be empty", "", query.getParentResultType());
454         assertEquals("result type should be vnfc", "vnfc", query.getResultType());
455         assertEquals("container type should be empty", "vnfcs", query.getContainerType());
456         assertEquals("dependent", true, query.isDependent());
457
458     }
459
460     @Test
461     public void dbAliasedSearch() throws UnsupportedEncodingException, AAIException {
462         URI uri = UriBuilder.fromPath("network/generic-vnfs").build();
463         MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
464         map.putSingle("persona-model-customization-id", "key2");
465         QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri, map);
466         GraphTraversal<Vertex, Vertex> expected =
467                 __.<Vertex>start().has("aai-node-type", "generic-vnf").has("model-customization-id", "key2");
468         GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "generic-vnf");
469
470         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
471                 query.getQueryBuilder().getQuery().toString());
472         assertEquals("parent", expectedParent.toString(),
473                 query.getQueryBuilder().getParentQuery().getQuery().toString());
474
475         assertEquals("result type should be", "generic-vnf", query.getResultType());
476         assertEquals("result type should be empty", "", query.getParentResultType());
477         assertEquals("dependent", true, query.isDependent());
478
479     }
480
481     @Test
482     public void dataLinkedSearch() throws UnsupportedEncodingException, AAIException {
483         URI uri = UriBuilder.fromPath("network/vpn-bindings").build();
484         MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
485         map.putSingle("global-route-target", "key2");
486         QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri, map);
487         GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-node-type", "vpn-binding")
488                 .where(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "route-target")
489                         .has("global-route-target", "key2"));
490         GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "vpn-binding");
491
492         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
493                 query.getQueryBuilder().getQuery().toString());
494         assertEquals("parent", expectedParent.toString(),
495                 query.getQueryBuilder().getParentQuery().getQuery().toString());
496
497         assertEquals("result type should be", "vpn-binding", query.getResultType());
498         assertEquals("result type should be empty", "", query.getParentResultType());
499         assertEquals("dependent", true, query.isDependent());
500     }
501
502     @Test
503     public void pluralCousin() throws UnsupportedEncodingException, AAIException {
504         URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers").build();
505
506         QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
507         GraphTraversal<Vertex, Vertex> expected =
508                 __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex")
509                         .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver");
510         GraphTraversal<Vertex, Vertex> expectedParent =
511                 __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
512
513         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
514                 query.getQueryBuilder().getQuery().toString());
515         assertEquals("parent", expectedParent.toString(),
516                 query.getQueryBuilder().getParentQuery().getQuery().toString());
517
518         assertEquals("result type should be", "pserver", query.getResultType());
519         assertEquals("result type should be", "complex", query.getParentResultType());
520         // this is controversial but we're not allowing writes on this currently
521         assertEquals("dependent", true, query.isDependent());
522     }
523
524     @Test
525     public void specificCousin() throws UnsupportedEncodingException, AAIException {
526         URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2")
527                 .build();
528
529         QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
530         GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1")
531                 .has("aai-node-type", "complex").in("org.onap.relationships.inventory.LocatedIn")
532                 .has("aai-node-type", "pserver").has("hostname", "key2");
533         GraphTraversal<Vertex, Vertex> expectedParent =
534                 __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
535
536         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
537                 query.getQueryBuilder().getQuery().toString());
538         assertEquals("parent", expectedParent.toString(),
539                 query.getQueryBuilder().getParentQuery().getQuery().toString());
540
541         assertEquals("result type should be", "pserver", query.getResultType());
542         assertEquals("result type should be", "complex", query.getParentResultType());
543         // this is controversial but we're not allowing writes on this currently
544         assertEquals("dependent", true, query.isDependent());
545     }
546
547     @Test
548     public void doubleSpecificCousin() throws UnsupportedEncodingException, AAIException {
549         URI uri = UriBuilder.fromPath(
550                 "cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2/related-to/vservers/vserver/key3")
551                 .build();
552
553         QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
554         GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1")
555                 .has("aai-node-type", "complex").in("org.onap.relationships.inventory.LocatedIn")
556                 .has("aai-node-type", "pserver").has("hostname", "key2").in("tosca.relationships.HostedOn")
557                 .has("aai-node-type", "vserver").has("vserver-id", "key3");
558         GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("physical-location-id", "key1")
559                 .has("aai-node-type", "complex").in("org.onap.relationships.inventory.LocatedIn")
560                 .has("aai-node-type", "pserver").has("hostname", "key2");
561
562         assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
563                 query.getQueryBuilder().getQuery().toString());
564         assertEquals("parent", expectedParent.toString(),
565                 query.getQueryBuilder().getParentQuery().getQuery().toString());
566
567         assertEquals("result type should be", "vserver", query.getResultType());
568         assertEquals("result type should be", "pserver", query.getParentResultType());
569         // this is controversial but we're not allowing writes on this currently
570         assertEquals("dependent", true, query.isDependent());
571     }
572
573     @Test
574     public void traversalEndsInRelatedTo() throws UnsupportedEncodingException, AAIException {
575         URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to").build();
576
577         thrown.expect(AAIException.class);
578         thrown.expectMessage(containsString(RestTokens.COUSIN.toString()));
579         QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
580
581     }
582
583     @Test
584     public void pluralCousinToPluralCousin() throws UnsupportedEncodingException, AAIException {
585         URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/related-to/pservers").build();
586
587         thrown.expect(AAIException.class);
588         thrown.expectMessage(containsString("chain plurals"));
589         QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
590
591     }
592 }