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.AAISetup;
50 import org.onap.aai.DataLinkSetup;
51 import org.onap.aai.db.props.AAIProperties;
52 import org.onap.aai.exceptions.AAIException;
53 import org.onap.aai.introspection.ModelType;
54 import org.onap.aai.rest.RestTokens;
55 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
56 import org.onap.aai.serialization.engines.QueryStyle;
57 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
58 import org.springframework.test.annotation.DirtiesContext;
60 @RunWith(value = Parameterized.class)
61 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
62 public class GraphTraversalTest extends DataLinkSetup {
64 private TransactionalGraphEngine dbEngine;
65 private TransactionalGraphEngine dbEngineDepthVersion;
67 @Parameterized.Parameter(value = 0)
68 public QueryStyle queryStyle;
70 @Parameterized.Parameters(name = "QueryStyle.{0}")
71 public static Collection<Object[]> data() {
72 return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
76 public ExpectedException thrown = ExpectedException.none();
82 * @throws SecurityException
83 * @throws NoSuchFieldException
86 public void configure() throws Exception {
87 dbEngine = new JanusGraphDBEngine(queryStyle,
88 loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()), false);
90 dbEngineDepthVersion = new JanusGraphDBEngine(queryStyle,
91 loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()), false);
97 * @throws UnsupportedEncodingException the unsupported encoding exception
98 * @throws AAIException the AAI exception
101 public void parentQuery() throws UnsupportedEncodingException, AAIException {
102 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1").build();
104 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
106 GraphTraversal<Vertex, Vertex> expected =
107 __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
108 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
109 query.getQueryBuilder().getQuery().toString());
110 assertEquals("parent gremlin query should be equal to normal query", expected.toString(),
111 query.getQueryBuilder().getParentQuery().getQuery().toString());
112 assertEquals("result type should be complex", "complex", query.getResultType());
113 assertEquals("result type should be empty", "", query.getParentResultType());
114 assertEquals("dependent", false, query.isDependent());
121 * @throws UnsupportedEncodingException the unsupported encoding exception
122 * @throws AAIException the AAI exception
125 public void childQuery() throws UnsupportedEncodingException, AAIException {
126 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3")
128 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
129 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1")
130 .has("aai-node-type", "complex").in("org.onap.relationships.inventory.BelongsTo")
131 .has("aai-node-type", "ctag-pool").has("target-pe", "key2").has("availability-zone-name", "key3");
132 GraphTraversal<Vertex, Vertex> expectedParent =
133 __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
134 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
135 query.getQueryBuilder().getQuery().toString());
136 assertEquals("parent gremlin query should be equal the query for complex", expectedParent.toString(),
137 query.getQueryBuilder().getParentQuery().getQuery().toString());
138 assertEquals("result type should be complex", "complex", query.getParentResultType());
139 assertEquals("result type should be ctag-pool", "ctag-pool", query.getResultType());
140 assertEquals("dependent", true, query.isDependent());
147 * @throws UnsupportedEncodingException the unsupported encoding exception
148 * @throws AAIException the AAI exception
151 public void namingExceptions() throws UnsupportedEncodingException, AAIException {
152 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655")
154 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
155 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "vce")
156 .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "port-group")
157 .has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
158 .has("aai-node-type", "cvlan-tag").has("cvlan-tag", 655);
159 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("vnf-id", "key1")
160 .has("aai-node-type", "vce").in("org.onap.relationships.inventory.BelongsTo")
161 .has("aai-node-type", "port-group").has("interface-id", "key2");
162 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
163 query.getQueryBuilder().getQuery().toString());
164 assertEquals("parent gremlin query should be equal the query for port group", expectedParent.toString(),
165 query.getQueryBuilder().getParentQuery().getQuery().toString());
166 assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
167 assertEquals("result type should be port-group", "port-group", query.getParentResultType());
168 assertEquals("contaner type should be empty", "", query.getContainerType());
169 assertEquals("dependent", true, query.isDependent());
177 * @throws UnsupportedEncodingException the unsupported encoding exception
178 * @throws AAIException the AAI exception
181 public void getAll() throws UnsupportedEncodingException, AAIException {
182 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags").build();
183 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
184 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "vce")
185 .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "port-group")
186 .has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
187 .has("aai-node-type", "cvlan-tag");
188 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("vnf-id", "key1")
189 .has("aai-node-type", "vce").in("org.onap.relationships.inventory.BelongsTo")
190 .has("aai-node-type", "port-group").has("interface-id", "key2");
191 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
192 query.getQueryBuilder().getQuery().toString());
193 assertEquals("parent gremlin query should be equal the query for port group", expectedParent.toString(),
194 query.getQueryBuilder().getParentQuery().getQuery().toString());
195 assertEquals("result type should be port-group", "port-group", query.getParentResultType());
196 assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
197 assertEquals("container type should be cvlan-tags", "cvlan-tags", query.getContainerType());
198 assertEquals("dependent", true, query.isDependent());
203 public void getAllParent() throws UnsupportedEncodingException, AAIException {
204 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers").build();
205 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
206 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-node-type", "pserver");
207 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "pserver");
208 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
209 query.getQueryBuilder().getQuery().toString());
210 assertEquals("parent gremlin query should be equal the query for pserver", expectedParent.toString(),
211 query.getQueryBuilder().getParentQuery().getQuery().toString());
212 assertEquals("parent result type should be empty", "", query.getParentResultType());
213 assertEquals("result type should be pserver", "pserver", query.getResultType());
214 assertEquals("container type should be pservers", "pservers", query.getContainerType());
215 assertEquals("dependent", false, query.isDependent());
220 * Gets the via query param.
222 * @return the via query param
223 * @throws UnsupportedEncodingException the unsupported encoding exception
224 * @throws AAIException the AAI exception
227 public void getViaQueryParam() throws UnsupportedEncodingException, AAIException {
229 .fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant")
231 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
232 map.putSingle("tenant-name", "Tenant1");
233 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
234 GraphTraversal<Vertex, Vertex> expected =
235 __.<Vertex>start().has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
236 .has("aai-node-type", "cloud-region").in("org.onap.relationships.inventory.BelongsTo")
237 .has("aai-node-type", "tenant").has("tenant-name", "Tenant1");
239 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("cloud-owner", "mycloudowner")
240 .has("cloud-region-id", "mycloudregionid").has("aai-node-type", "cloud-region");
242 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
243 query.getQueryBuilder().getQuery().toString());
244 assertEquals("parent gremlin query should be equal the query for cloud-region", expectedParent.toString(),
245 query.getQueryBuilder().getParentQuery().getQuery().toString());
246 assertEquals("result type should be cloud-region", "cloud-region", query.getParentResultType());
247 assertEquals("result type should be tenant", "tenant", query.getResultType());
248 assertEquals("container type should be empty", "", query.getContainerType());
249 assertEquals("dependent", true, query.isDependent());
254 public void getViaDuplicateQueryParam() throws UnsupportedEncodingException, AAIException {
256 .fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant")
258 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
259 List<String> values = new ArrayList<>();
260 values.add("Tenant1");
261 values.add("Tenant2");
262 map.put("tenant-name", values);
263 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
264 GraphTraversal<Vertex, Vertex> expected =
265 __.<Vertex>start().has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
266 .has("aai-node-type", "cloud-region").in("org.onap.relationships.inventory.BelongsTo")
267 .has("aai-node-type", "tenant").has("tenant-name", P.within(values));
269 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("cloud-owner", "mycloudowner")
270 .has("cloud-region-id", "mycloudregionid").has("aai-node-type", "cloud-region");
272 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
273 query.getQueryBuilder().getQuery().toString());
274 assertEquals("parent gremlin query should be equal the query for cloud-region", expectedParent.toString(),
275 query.getQueryBuilder().getParentQuery().getQuery().toString());
276 assertEquals("result type should be cloud-region", "cloud-region", query.getParentResultType());
277 assertEquals("result type should be tenant", "tenant", query.getResultType());
278 assertEquals("container type should be empty", "", query.getContainerType());
279 assertEquals("dependent", true, query.isDependent());
284 * Gets the plural via query param.
286 * @return the plural via query param
287 * @throws UnsupportedEncodingException the unsupported encoding exception
288 * @throws AAIException the AAI exception
291 public void getPluralViaQueryParam() throws UnsupportedEncodingException, AAIException {
292 URI uri = UriBuilder.fromPath("network/vnfcs").build();
293 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
294 map.putSingle("prov-status", "up");
295 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
296 GraphTraversal<Vertex, Vertex> expected =
297 __.<Vertex>start().has("aai-node-type", "vnfc").has("prov-status", "up");
299 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "vnfc");
301 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
302 query.getQueryBuilder().getQuery().toString());
303 assertEquals("parent", expectedParent.toString(),
304 query.getQueryBuilder().getParentQuery().getQuery().toString());
305 assertEquals("parent result type should be empty", "", query.getParentResultType());
306 assertEquals("result type should be vnfc", "vnfc", query.getResultType());
307 assertEquals("container type should be empty", "vnfcs", query.getContainerType());
308 assertEquals("dependent", true, query.isDependent());
313 * Gets the all query param naming exception.
315 * @return the all query param naming exception
316 * @throws UnsupportedEncodingException the unsupported encoding exception
317 * @throws AAIException the AAI exception
320 public void getAllQueryParamNamingException() throws UnsupportedEncodingException, AAIException {
321 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags").build();
322 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
323 map.putSingle("cvlan-tag", "333");
324 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
326 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "vce")
327 .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "port-group")
328 .has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
329 .has("aai-node-type", "cvlan-tag").has("cvlan-tag", 333);
330 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("vnf-id", "key1")
331 .has("aai-node-type", "vce").in("org.onap.relationships.inventory.BelongsTo")
332 .has("aai-node-type", "port-group").has("interface-id", "key2");
333 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
334 query.getQueryBuilder().getQuery().toString());
335 assertEquals("parent gremlin query should be equal the query for port group", expectedParent.toString(),
336 query.getQueryBuilder().getParentQuery().getQuery().toString());
337 assertEquals("result type should be port-group", "port-group", query.getParentResultType());
338 assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
339 assertEquals("container type should be cvlan-tags", "cvlan-tags", query.getContainerType());
340 assertEquals("dependent", true, query.isDependent());
347 * @throws UnsupportedEncodingException the unsupported encoding exception
348 * @throws AAIException the AAI exception
351 public void abstractType() throws UnsupportedEncodingException, AAIException {
352 URI uri = UriBuilder.fromPath("vnf/key1").build();
354 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
356 GraphTraversal<Vertex, Vertex> expected =
357 __.<Vertex>start().has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"));
359 GraphTraversal<Vertex, Vertex> expectedParent = expected;
360 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
361 query.getQueryBuilder().getQuery().toString());
362 assertEquals("parent gremlin query should be equal the query for port group", expectedParent.toString(),
363 query.getQueryBuilder().getParentQuery().getQuery().toString());
364 assertEquals("result type should be empty", "", query.getParentResultType());
365 assertEquals("result type should be vnf", "vnf", query.getResultType());
367 assertEquals("dependent", false, query.isDependent());
372 * Non parent abstract type.
374 * @throws UnsupportedEncodingException the unsupported encoding exception
375 * @throws AAIException the AAI exception
378 public void nonParentAbstractType() throws UnsupportedEncodingException, AAIException {
379 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key2/vnf/key1").build();
380 thrown.expect(AAIException.class);
381 thrown.expectMessage(containsString("not a valid path"));
382 dbEngine.getQueryBuilder().createQueryFromURI(uri);
386 public void parentAbstractTypeWithNesting() throws UnsupportedEncodingException, AAIException {
387 URI uri = UriBuilder.fromPath("vnf/key1/vf-modules/vf-module/key2").build();
389 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
391 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1")
392 .has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"))
393 .union(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "vf-module"))
394 .has("vf-module-id", "key2");
396 GraphTraversal<Vertex, Vertex> expectedParent =
397 __.<Vertex>start().has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"));
398 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
399 query.getQueryBuilder().getQuery().toString());
400 assertEquals("parent gremlin query should be equal the query for ", expectedParent.toString(),
401 query.getQueryBuilder().getParentQuery().getQuery().toString());
402 assertEquals("result type should be vnf", "vnf", query.getParentResultType());
403 assertEquals("result type should be vf-module", "vf-module", query.getResultType());
405 assertEquals("dependent", true, query.isDependent());
410 public void getViaBadQueryParam() throws UnsupportedEncodingException, AAIException {
411 URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/a/b/tenants/tenant").build();
412 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
413 map.putSingle("tenant-n231ame", "Tenant1");
414 thrown.expect(AAIException.class);
415 thrown.expect(hasProperty("code", is("AAI_3000")));
417 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
422 public void getPluralViaBadQueryParam() throws UnsupportedEncodingException, AAIException {
423 URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/a/b/tenants").build();
424 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
425 map.putSingle("tenant-n231ame", "Tenant1");
426 thrown.expect(AAIException.class);
427 thrown.expect(hasProperty("code", is("AAI_3000")));
429 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
434 public void getPluralViaDuplicateQueryParam() throws UnsupportedEncodingException, AAIException {
435 URI uri = UriBuilder.fromPath("network/vnfcs").build();
436 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
437 List<String> values = new ArrayList<>();
443 map.put("prov-status", values);
444 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
445 GraphTraversal<Vertex, Vertex> expected =
446 __.<Vertex>start().has("aai-node-type", "vnfc").has("prov-status", P.within(values));
448 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "vnfc");
450 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
451 query.getQueryBuilder().getQuery().toString());
452 assertEquals("parent", expectedParent.toString(),
453 query.getQueryBuilder().getParentQuery().getQuery().toString());
454 assertEquals("parent result type should be empty", "", query.getParentResultType());
455 assertEquals("result type should be vnfc", "vnfc", query.getResultType());
456 assertEquals("container type should be empty", "vnfcs", query.getContainerType());
457 assertEquals("dependent", true, query.isDependent());
462 public void dbAliasedSearch() throws UnsupportedEncodingException, AAIException {
463 URI uri = UriBuilder.fromPath("network/generic-vnfs").build();
464 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
465 map.putSingle("persona-model-customization-id", "key2");
466 QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri, map);
467 GraphTraversal<Vertex, Vertex> expected =
468 __.<Vertex>start().has("aai-node-type", "generic-vnf").has("model-customization-id", "key2");
469 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "generic-vnf");
471 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
472 query.getQueryBuilder().getQuery().toString());
473 assertEquals("parent", expectedParent.toString(),
474 query.getQueryBuilder().getParentQuery().getQuery().toString());
476 assertEquals("result type should be", "generic-vnf", query.getResultType());
477 assertEquals("result type should be empty", "", query.getParentResultType());
478 assertEquals("dependent", true, query.isDependent());
483 public void dataLinkedSearch() throws UnsupportedEncodingException, AAIException {
484 URI uri = UriBuilder.fromPath("network/vpn-bindings").build();
485 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
486 map.putSingle("global-route-target", "key2");
487 QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri, map);
488 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-node-type", "vpn-binding")
489 .where(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "route-target")
490 .has("global-route-target", "key2"));
491 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "vpn-binding");
493 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
494 query.getQueryBuilder().getQuery().toString());
495 assertEquals("parent", expectedParent.toString(),
496 query.getQueryBuilder().getParentQuery().getQuery().toString());
498 assertEquals("result type should be", "vpn-binding", query.getResultType());
499 assertEquals("result type should be empty", "", query.getParentResultType());
500 assertEquals("dependent", true, query.isDependent());
504 public void pluralCousin() throws UnsupportedEncodingException, AAIException {
505 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers").build();
507 QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
508 GraphTraversal<Vertex, Vertex> expected =
509 __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex")
510 .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver");
511 GraphTraversal<Vertex, Vertex> expectedParent =
512 __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
514 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
515 query.getQueryBuilder().getQuery().toString());
516 assertEquals("parent", expectedParent.toString(),
517 query.getQueryBuilder().getParentQuery().getQuery().toString());
519 assertEquals("result type should be", "pserver", query.getResultType());
520 assertEquals("result type should be", "complex", query.getParentResultType());
521 // this is controversial but we're not allowing writes on this currently
522 assertEquals("dependent", true, query.isDependent());
526 public void specificCousin() throws UnsupportedEncodingException, AAIException {
527 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2")
530 QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
531 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1")
532 .has("aai-node-type", "complex").in("org.onap.relationships.inventory.LocatedIn")
533 .has("aai-node-type", "pserver").has("hostname", "key2");
534 GraphTraversal<Vertex, Vertex> expectedParent =
535 __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
537 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
538 query.getQueryBuilder().getQuery().toString());
539 assertEquals("parent", expectedParent.toString(),
540 query.getQueryBuilder().getParentQuery().getQuery().toString());
542 assertEquals("result type should be", "pserver", query.getResultType());
543 assertEquals("result type should be", "complex", query.getParentResultType());
544 // this is controversial but we're not allowing writes on this currently
545 assertEquals("dependent", true, query.isDependent());
549 public void doubleSpecificCousin() throws UnsupportedEncodingException, AAIException {
550 URI uri = UriBuilder.fromPath(
551 "cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2/related-to/vservers/vserver/key3")
554 QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
555 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1")
556 .has("aai-node-type", "complex").in("org.onap.relationships.inventory.LocatedIn")
557 .has("aai-node-type", "pserver").has("hostname", "key2").in("tosca.relationships.HostedOn")
558 .has("aai-node-type", "vserver").has("vserver-id", "key3");
559 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("physical-location-id", "key1")
560 .has("aai-node-type", "complex").in("org.onap.relationships.inventory.LocatedIn")
561 .has("aai-node-type", "pserver").has("hostname", "key2");
563 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
564 query.getQueryBuilder().getQuery().toString());
565 assertEquals("parent", expectedParent.toString(),
566 query.getQueryBuilder().getParentQuery().getQuery().toString());
568 assertEquals("result type should be", "vserver", query.getResultType());
569 assertEquals("result type should be", "pserver", query.getParentResultType());
570 // this is controversial but we're not allowing writes on this currently
571 assertEquals("dependent", true, query.isDependent());
575 public void traversalEndsInRelatedTo() throws UnsupportedEncodingException, AAIException {
576 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to").build();
578 thrown.expect(AAIException.class);
579 thrown.expectMessage(containsString(RestTokens.COUSIN.toString()));
580 QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
585 public void pluralCousinToPluralCousin() throws UnsupportedEncodingException, AAIException {
586 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/related-to/pservers").build();
588 thrown.expect(AAIException.class);
589 thrown.expectMessage(containsString("chain plurals"));
590 QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);