2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.parsers.query;
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;
28 import java.io.UnsupportedEncodingException;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.Collection;
33 import java.util.List;
35 import javax.ws.rs.core.MultivaluedHashMap;
36 import javax.ws.rs.core.MultivaluedMap;
37 import javax.ws.rs.core.UriBuilder;
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;
59 @RunWith(value = Parameterized.class)
60 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
61 public class GraphTraversalTest extends DataLinkSetup {
63 private TransactionalGraphEngine dbEngine;
64 private TransactionalGraphEngine dbEngineDepthVersion;
66 @Parameterized.Parameter(value = 0)
67 public QueryStyle queryStyle;
69 @Parameterized.Parameters(name = "QueryStyle.{0}")
70 public static Collection<Object[]> data() {
71 return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
75 public ExpectedException thrown = ExpectedException.none();
81 * @throws SecurityException
82 * @throws NoSuchFieldException
85 public void configure() throws Exception {
86 dbEngine = new JanusGraphDBEngine(queryStyle,
87 loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()), false);
89 dbEngineDepthVersion = new JanusGraphDBEngine(queryStyle,
90 loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()), false);
96 * @throws UnsupportedEncodingException the unsupported encoding exception
97 * @throws AAIException the AAI exception
100 public void parentQuery() throws UnsupportedEncodingException, AAIException {
101 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1").build();
103 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
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());
120 * @throws UnsupportedEncodingException the unsupported encoding exception
121 * @throws AAIException the AAI exception
124 public void childQuery() throws UnsupportedEncodingException, AAIException {
125 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3")
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());
146 * @throws UnsupportedEncodingException the unsupported encoding exception
147 * @throws AAIException the AAI exception
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")
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());
176 * @throws UnsupportedEncodingException the unsupported encoding exception
177 * @throws AAIException the AAI exception
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());
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());
219 * Gets the via query param.
221 * @return the via query param
222 * @throws UnsupportedEncodingException the unsupported encoding exception
223 * @throws AAIException the AAI exception
226 public void getViaQueryParam() throws UnsupportedEncodingException, AAIException {
228 .fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant")
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");
238 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("cloud-owner", "mycloudowner")
239 .has("cloud-region-id", "mycloudregionid").has("aai-node-type", "cloud-region");
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());
253 public void getViaDuplicateQueryParam() throws UnsupportedEncodingException, AAIException {
255 .fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant")
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));
268 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("cloud-owner", "mycloudowner")
269 .has("cloud-region-id", "mycloudregionid").has("aai-node-type", "cloud-region");
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());
283 * Gets the plural via query param.
285 * @return the plural via query param
286 * @throws UnsupportedEncodingException the unsupported encoding exception
287 * @throws AAIException the AAI exception
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");
298 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "vnfc");
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());
312 * Gets the all query param naming exception.
314 * @return the all query param naming exception
315 * @throws UnsupportedEncodingException the unsupported encoding exception
316 * @throws AAIException the AAI exception
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);
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());
346 * @throws UnsupportedEncodingException the unsupported encoding exception
347 * @throws AAIException the AAI exception
350 public void abstractType() throws UnsupportedEncodingException, AAIException {
351 URI uri = UriBuilder.fromPath("vnf/key1").build();
353 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
355 GraphTraversal<Vertex, Vertex> expected =
356 __.<Vertex>start().has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"));
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());
366 assertEquals("dependent", false, query.isDependent());
371 * Non parent abstract type.
373 * @throws UnsupportedEncodingException the unsupported encoding exception
374 * @throws AAIException the AAI exception
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);
385 public void parentAbstractTypeWithNesting() throws UnsupportedEncodingException, AAIException {
386 URI uri = UriBuilder.fromPath("vnf/key1/vf-modules/vf-module/key2").build();
388 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
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");
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());
404 assertEquals("dependent", true, query.isDependent());
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")));
416 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
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")));
428 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
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<>();
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));
447 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "vnfc");
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());
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");
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());
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());
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");
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());
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());
503 public void pluralCousin() throws UnsupportedEncodingException, AAIException {
504 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers").build();
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");
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());
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());
525 public void specificCousin() throws UnsupportedEncodingException, AAIException {
526 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2")
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");
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());
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());
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")
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");
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());
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());
574 public void traversalEndsInRelatedTo() throws UnsupportedEncodingException, AAIException {
575 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to").build();
577 thrown.expect(AAIException.class);
578 thrown.expectMessage(containsString(RestTokens.COUSIN.toString()));
579 QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
584 public void pluralCousinToPluralCousin() throws UnsupportedEncodingException, AAIException {
585 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/related-to/pservers").build();
587 thrown.expect(AAIException.class);
588 thrown.expectMessage(containsString("chain plurals"));
589 QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);