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.experimental.categories.Category;
47 import org.junit.rules.ExpectedException;
48 import org.junit.runner.RunWith;
49 import org.junit.runners.Parameterized;
50 import org.onap.aai.DataLinkSetup;
51 import org.onap.aai.TinkerpopUpgrade;
52 import org.onap.aai.db.props.AAIProperties;
53 import org.onap.aai.exceptions.AAIException;
54 import org.onap.aai.introspection.ModelType;
55 import org.onap.aai.rest.RestTokens;
56 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
57 import org.onap.aai.serialization.engines.QueryStyle;
58 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
59 import org.springframework.test.annotation.DirtiesContext;
61 @Category(TinkerpopUpgrade.class)
62 @RunWith(value = Parameterized.class)
63 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
64 public class GraphTraversalTest extends DataLinkSetup {
66 private TransactionalGraphEngine dbEngine;
67 private TransactionalGraphEngine dbEngineDepthVersion;
69 @Parameterized.Parameter(value = 0)
70 public QueryStyle queryStyle;
72 @Parameterized.Parameters(name = "QueryStyle.{0}")
73 public static Collection<Object[]> data() {
74 return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
78 public ExpectedException thrown = ExpectedException.none();
84 * @throws SecurityException
85 * @throws NoSuchFieldException
88 public void configure() throws Exception {
89 dbEngine = new JanusGraphDBEngine(queryStyle,
90 loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()), false);
92 dbEngineDepthVersion = new JanusGraphDBEngine(queryStyle,
93 loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()), false);
99 * @throws UnsupportedEncodingException the unsupported encoding exception
100 * @throws AAIException the AAI exception
103 public void parentQuery() throws UnsupportedEncodingException, AAIException {
104 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1").build();
106 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
108 GraphTraversal<Vertex, Vertex> expected =
109 __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
110 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
111 query.getQueryBuilder().getQuery().toString());
112 assertEquals("parent gremlin query should be equal to normal query", expected.toString(),
113 query.getQueryBuilder().getParentQuery().getQuery().toString());
114 assertEquals("result type should be complex", "complex", query.getResultType());
115 assertEquals("result type should be empty", "", query.getParentResultType());
116 assertEquals("dependent", false, query.isDependent());
123 * @throws UnsupportedEncodingException the unsupported encoding exception
124 * @throws AAIException the AAI exception
127 public void childQuery() throws UnsupportedEncodingException, AAIException {
128 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3")
130 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
131 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1")
132 .has("aai-node-type", "complex").in("org.onap.relationships.inventory.BelongsTo")
133 .has("aai-node-type", "ctag-pool").has("target-pe", "key2").has("availability-zone-name", "key3");
134 GraphTraversal<Vertex, Vertex> expectedParent =
135 __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
136 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
137 query.getQueryBuilder().getQuery().toString());
138 assertEquals("parent gremlin query should be equal the query for complex", expectedParent.toString(),
139 query.getQueryBuilder().getParentQuery().getQuery().toString());
140 assertEquals("result type should be complex", "complex", query.getParentResultType());
141 assertEquals("result type should be ctag-pool", "ctag-pool", query.getResultType());
142 assertEquals("dependent", true, query.isDependent());
149 * @throws UnsupportedEncodingException the unsupported encoding exception
150 * @throws AAIException the AAI exception
153 public void namingExceptions() throws UnsupportedEncodingException, AAIException {
154 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655")
156 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
157 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "vce")
158 .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "port-group")
159 .has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
160 .has("aai-node-type", "cvlan-tag").has("cvlan-tag", 655);
161 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("vnf-id", "key1")
162 .has("aai-node-type", "vce").in("org.onap.relationships.inventory.BelongsTo")
163 .has("aai-node-type", "port-group").has("interface-id", "key2");
164 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
165 query.getQueryBuilder().getQuery().toString());
166 assertEquals("parent gremlin query should be equal the query for port group", expectedParent.toString(),
167 query.getQueryBuilder().getParentQuery().getQuery().toString());
168 assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
169 assertEquals("result type should be port-group", "port-group", query.getParentResultType());
170 assertEquals("contaner type should be empty", "", query.getContainerType());
171 assertEquals("dependent", true, query.isDependent());
179 * @throws UnsupportedEncodingException the unsupported encoding exception
180 * @throws AAIException the AAI exception
183 public void getAll() throws UnsupportedEncodingException, AAIException {
184 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags").build();
185 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
186 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "vce")
187 .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "port-group")
188 .has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
189 .has("aai-node-type", "cvlan-tag");
190 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("vnf-id", "key1")
191 .has("aai-node-type", "vce").in("org.onap.relationships.inventory.BelongsTo")
192 .has("aai-node-type", "port-group").has("interface-id", "key2");
193 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
194 query.getQueryBuilder().getQuery().toString());
195 assertEquals("parent gremlin query should be equal the query for port group", expectedParent.toString(),
196 query.getQueryBuilder().getParentQuery().getQuery().toString());
197 assertEquals("result type should be port-group", "port-group", query.getParentResultType());
198 assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
199 assertEquals("container type should be cvlan-tags", "cvlan-tags", query.getContainerType());
200 assertEquals("dependent", true, query.isDependent());
205 public void getAllParent() throws UnsupportedEncodingException, AAIException {
206 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers").build();
207 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
208 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-node-type", "pserver");
209 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "pserver");
210 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
211 query.getQueryBuilder().getQuery().toString());
212 assertEquals("parent gremlin query should be equal the query for pserver", expectedParent.toString(),
213 query.getQueryBuilder().getParentQuery().getQuery().toString());
214 assertEquals("parent result type should be empty", "", query.getParentResultType());
215 assertEquals("result type should be pserver", "pserver", query.getResultType());
216 assertEquals("container type should be pservers", "pservers", query.getContainerType());
217 assertEquals("dependent", false, query.isDependent());
222 * Gets the via query param.
224 * @return the via query param
225 * @throws UnsupportedEncodingException the unsupported encoding exception
226 * @throws AAIException the AAI exception
229 public void getViaQueryParam() throws UnsupportedEncodingException, AAIException {
231 .fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant")
233 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
234 map.putSingle("tenant-name", "Tenant1");
235 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
236 GraphTraversal<Vertex, Vertex> expected =
237 __.<Vertex>start().has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
238 .has("aai-node-type", "cloud-region").in("org.onap.relationships.inventory.BelongsTo")
239 .has("aai-node-type", "tenant").has("tenant-name", "Tenant1");
241 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("cloud-owner", "mycloudowner")
242 .has("cloud-region-id", "mycloudregionid").has("aai-node-type", "cloud-region");
244 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
245 query.getQueryBuilder().getQuery().toString());
246 assertEquals("parent gremlin query should be equal the query for cloud-region", expectedParent.toString(),
247 query.getQueryBuilder().getParentQuery().getQuery().toString());
248 assertEquals("result type should be cloud-region", "cloud-region", query.getParentResultType());
249 assertEquals("result type should be tenant", "tenant", query.getResultType());
250 assertEquals("container type should be empty", "", query.getContainerType());
251 assertEquals("dependent", true, query.isDependent());
256 public void getViaDuplicateQueryParam() throws UnsupportedEncodingException, AAIException {
258 .fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant")
260 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
261 List<String> values = new ArrayList<>();
262 values.add("Tenant1");
263 values.add("Tenant2");
264 map.put("tenant-name", values);
265 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
266 GraphTraversal<Vertex, Vertex> expected =
267 __.<Vertex>start().has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
268 .has("aai-node-type", "cloud-region").in("org.onap.relationships.inventory.BelongsTo")
269 .has("aai-node-type", "tenant").has("tenant-name", P.within(values));
271 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("cloud-owner", "mycloudowner")
272 .has("cloud-region-id", "mycloudregionid").has("aai-node-type", "cloud-region");
274 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
275 query.getQueryBuilder().getQuery().toString());
276 assertEquals("parent gremlin query should be equal the query for cloud-region", expectedParent.toString(),
277 query.getQueryBuilder().getParentQuery().getQuery().toString());
278 assertEquals("result type should be cloud-region", "cloud-region", query.getParentResultType());
279 assertEquals("result type should be tenant", "tenant", query.getResultType());
280 assertEquals("container type should be empty", "", query.getContainerType());
281 assertEquals("dependent", true, query.isDependent());
286 * Gets the plural via query param.
288 * @return the plural via query param
289 * @throws UnsupportedEncodingException the unsupported encoding exception
290 * @throws AAIException the AAI exception
293 public void getPluralViaQueryParam() throws UnsupportedEncodingException, AAIException {
294 URI uri = UriBuilder.fromPath("network/vnfcs").build();
295 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
296 map.putSingle("prov-status", "up");
297 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
298 GraphTraversal<Vertex, Vertex> expected =
299 __.<Vertex>start().has("aai-node-type", "vnfc").has("prov-status", "up");
301 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "vnfc");
303 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
304 query.getQueryBuilder().getQuery().toString());
305 assertEquals("parent", expectedParent.toString(),
306 query.getQueryBuilder().getParentQuery().getQuery().toString());
307 assertEquals("parent result type should be empty", "", query.getParentResultType());
308 assertEquals("result type should be vnfc", "vnfc", query.getResultType());
309 assertEquals("container type should be empty", "vnfcs", query.getContainerType());
310 assertEquals("dependent", true, query.isDependent());
315 * Gets the all query param naming exception.
317 * @return the all query param naming exception
318 * @throws UnsupportedEncodingException the unsupported encoding exception
319 * @throws AAIException the AAI exception
322 public void getAllQueryParamNamingException() throws UnsupportedEncodingException, AAIException {
323 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags").build();
324 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
325 map.putSingle("cvlan-tag", "333");
326 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
328 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "vce")
329 .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "port-group")
330 .has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
331 .has("aai-node-type", "cvlan-tag").has("cvlan-tag", 333);
332 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("vnf-id", "key1")
333 .has("aai-node-type", "vce").in("org.onap.relationships.inventory.BelongsTo")
334 .has("aai-node-type", "port-group").has("interface-id", "key2");
335 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
336 query.getQueryBuilder().getQuery().toString());
337 assertEquals("parent gremlin query should be equal the query for port group", expectedParent.toString(),
338 query.getQueryBuilder().getParentQuery().getQuery().toString());
339 assertEquals("result type should be port-group", "port-group", query.getParentResultType());
340 assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
341 assertEquals("container type should be cvlan-tags", "cvlan-tags", query.getContainerType());
342 assertEquals("dependent", true, query.isDependent());
349 * @throws UnsupportedEncodingException the unsupported encoding exception
350 * @throws AAIException the AAI exception
353 public void abstractType() throws UnsupportedEncodingException, AAIException {
354 URI uri = UriBuilder.fromPath("vnf/key1").build();
356 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
358 GraphTraversal<Vertex, Vertex> expected =
359 __.<Vertex>start().has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"));
361 GraphTraversal<Vertex, Vertex> expectedParent = expected;
362 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
363 query.getQueryBuilder().getQuery().toString());
364 assertEquals("parent gremlin query should be equal the query for port group", expectedParent.toString(),
365 query.getQueryBuilder().getParentQuery().getQuery().toString());
366 assertEquals("result type should be empty", "", query.getParentResultType());
367 assertEquals("result type should be vnf", "vnf", query.getResultType());
369 assertEquals("dependent", false, query.isDependent());
374 * Non parent abstract type.
376 * @throws UnsupportedEncodingException the unsupported encoding exception
377 * @throws AAIException the AAI exception
380 public void nonParentAbstractType() throws UnsupportedEncodingException, AAIException {
381 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key2/vnf/key1").build();
382 thrown.expect(AAIException.class);
383 thrown.expectMessage(containsString("not a valid path"));
384 dbEngine.getQueryBuilder().createQueryFromURI(uri);
388 public void parentAbstractTypeWithNesting() throws UnsupportedEncodingException, AAIException {
389 URI uri = UriBuilder.fromPath("vnf/key1/vf-modules/vf-module/key2").build();
391 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
393 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1")
394 .has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"))
395 .union(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "vf-module"))
396 .has("vf-module-id", "key2");
398 GraphTraversal<Vertex, Vertex> expectedParent =
399 __.<Vertex>start().has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"));
400 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
401 query.getQueryBuilder().getQuery().toString());
402 assertEquals("parent gremlin query should be equal the query for ", expectedParent.toString(),
403 query.getQueryBuilder().getParentQuery().getQuery().toString());
404 assertEquals("result type should be vnf", "vnf", query.getParentResultType());
405 assertEquals("result type should be vf-module", "vf-module", query.getResultType());
407 assertEquals("dependent", true, query.isDependent());
412 public void getViaBadQueryParam() throws UnsupportedEncodingException, AAIException {
413 URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/a/b/tenants/tenant").build();
414 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
415 map.putSingle("tenant-n231ame", "Tenant1");
416 thrown.expect(AAIException.class);
417 thrown.expect(hasProperty("code", is("AAI_3000")));
419 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
424 public void getPluralViaBadQueryParam() throws UnsupportedEncodingException, AAIException {
425 URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/a/b/tenants").build();
426 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
427 map.putSingle("tenant-n231ame", "Tenant1");
428 thrown.expect(AAIException.class);
429 thrown.expect(hasProperty("code", is("AAI_3000")));
431 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
436 public void getPluralViaDuplicateQueryParam() throws UnsupportedEncodingException, AAIException {
437 URI uri = UriBuilder.fromPath("network/vnfcs").build();
438 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
439 List<String> values = new ArrayList<>();
445 map.put("prov-status", values);
446 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
447 GraphTraversal<Vertex, Vertex> expected =
448 __.<Vertex>start().has("aai-node-type", "vnfc").has("prov-status", P.within(values));
450 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "vnfc");
452 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
453 query.getQueryBuilder().getQuery().toString());
454 assertEquals("parent", expectedParent.toString(),
455 query.getQueryBuilder().getParentQuery().getQuery().toString());
456 assertEquals("parent result type should be empty", "", query.getParentResultType());
457 assertEquals("result type should be vnfc", "vnfc", query.getResultType());
458 assertEquals("container type should be empty", "vnfcs", query.getContainerType());
459 assertEquals("dependent", true, query.isDependent());
464 public void dbAliasedSearch() throws UnsupportedEncodingException, AAIException {
465 URI uri = UriBuilder.fromPath("network/generic-vnfs").build();
466 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
467 map.putSingle("persona-model-customization-id", "key2");
468 QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri, map);
469 GraphTraversal<Vertex, Vertex> expected =
470 __.<Vertex>start().has("aai-node-type", "generic-vnf").has("model-customization-id", "key2");
471 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "generic-vnf");
473 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
474 query.getQueryBuilder().getQuery().toString());
475 assertEquals("parent", expectedParent.toString(),
476 query.getQueryBuilder().getParentQuery().getQuery().toString());
478 assertEquals("result type should be", "generic-vnf", query.getResultType());
479 assertEquals("result type should be empty", "", query.getParentResultType());
480 assertEquals("dependent", true, query.isDependent());
485 public void dataLinkedSearch() throws UnsupportedEncodingException, AAIException {
486 URI uri = UriBuilder.fromPath("network/vpn-bindings").build();
487 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
488 map.putSingle("global-route-target", "key2");
489 QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri, map);
490 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-node-type", "vpn-binding")
491 .where(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "route-target")
492 .has("global-route-target", "key2"));
493 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "vpn-binding");
495 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
496 query.getQueryBuilder().getQuery().toString());
497 assertEquals("parent", expectedParent.toString(),
498 query.getQueryBuilder().getParentQuery().getQuery().toString());
500 assertEquals("result type should be", "vpn-binding", query.getResultType());
501 assertEquals("result type should be empty", "", query.getParentResultType());
502 assertEquals("dependent", true, query.isDependent());
506 public void pluralCousin() throws UnsupportedEncodingException, AAIException {
507 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers").build();
509 QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
510 GraphTraversal<Vertex, Vertex> expected =
511 __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex")
512 .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver");
513 GraphTraversal<Vertex, Vertex> expectedParent =
514 __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
516 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
517 query.getQueryBuilder().getQuery().toString());
518 assertEquals("parent", expectedParent.toString(),
519 query.getQueryBuilder().getParentQuery().getQuery().toString());
521 assertEquals("result type should be", "pserver", query.getResultType());
522 assertEquals("result type should be", "complex", query.getParentResultType());
523 // this is controversial but we're not allowing writes on this currently
524 assertEquals("dependent", true, query.isDependent());
528 public void specificCousin() throws UnsupportedEncodingException, AAIException {
529 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2")
532 QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
533 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1")
534 .has("aai-node-type", "complex").in("org.onap.relationships.inventory.LocatedIn")
535 .has("aai-node-type", "pserver").has("hostname", "key2");
536 GraphTraversal<Vertex, Vertex> expectedParent =
537 __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
539 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
540 query.getQueryBuilder().getQuery().toString());
541 assertEquals("parent", expectedParent.toString(),
542 query.getQueryBuilder().getParentQuery().getQuery().toString());
544 assertEquals("result type should be", "pserver", query.getResultType());
545 assertEquals("result type should be", "complex", query.getParentResultType());
546 // this is controversial but we're not allowing writes on this currently
547 assertEquals("dependent", true, query.isDependent());
551 public void doubleSpecificCousin() throws UnsupportedEncodingException, AAIException {
552 URI uri = UriBuilder.fromPath(
553 "cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2/related-to/vservers/vserver/key3")
556 QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
557 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1")
558 .has("aai-node-type", "complex").in("org.onap.relationships.inventory.LocatedIn")
559 .has("aai-node-type", "pserver").has("hostname", "key2").in("tosca.relationships.HostedOn")
560 .has("aai-node-type", "vserver").has("vserver-id", "key3");
561 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("physical-location-id", "key1")
562 .has("aai-node-type", "complex").in("org.onap.relationships.inventory.LocatedIn")
563 .has("aai-node-type", "pserver").has("hostname", "key2");
565 assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
566 query.getQueryBuilder().getQuery().toString());
567 assertEquals("parent", expectedParent.toString(),
568 query.getQueryBuilder().getParentQuery().getQuery().toString());
570 assertEquals("result type should be", "vserver", query.getResultType());
571 assertEquals("result type should be", "pserver", query.getParentResultType());
572 // this is controversial but we're not allowing writes on this currently
573 assertEquals("dependent", true, query.isDependent());
577 public void traversalEndsInRelatedTo() throws UnsupportedEncodingException, AAIException {
578 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to").build();
580 thrown.expect(AAIException.class);
581 thrown.expectMessage(containsString(RestTokens.COUSIN.toString()));
582 QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
587 public void pluralCousinToPluralCousin() throws UnsupportedEncodingException, AAIException {
588 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/related-to/pservers").build();
590 thrown.expect(AAIException.class);
591 thrown.expectMessage(containsString("chain plurals"));
592 QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);