2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
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.openecomp.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.List;
33 import javax.ws.rs.core.MultivaluedHashMap;
34 import javax.ws.rs.core.MultivaluedMap;
35 import javax.ws.rs.core.UriBuilder;
37 import org.apache.tinkerpop.gremlin.process.traversal.P;
38 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
39 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
40 import org.apache.tinkerpop.gremlin.structure.Vertex;
41 import org.junit.BeforeClass;
42 import org.junit.Ignore;
43 import org.junit.Rule;
44 import org.junit.Test;
45 import org.junit.rules.ExpectedException;
47 import org.openecomp.aai.db.props.AAIProperties;
48 import org.openecomp.aai.exceptions.AAIException;
49 import org.openecomp.aai.introspection.LoaderFactory;
50 import org.openecomp.aai.introspection.ModelType;
51 import org.openecomp.aai.introspection.Version;
52 import org.openecomp.aai.rest.RestTokens;
53 import org.openecomp.aai.serialization.engines.QueryStyle;
54 import org.openecomp.aai.serialization.engines.TitanDBEngine;
55 import org.openecomp.aai.serialization.engines.TransactionalGraphEngine;
56 import org.openecomp.aai.serialization.queryformats.QueryFormatTestHelper;
57 import org.openecomp.aai.util.AAIConstants;
61 public class GraphTraversalTest {
63 private static TransactionalGraphEngine dbEngine;
65 private static TransactionalGraphEngine dbEnginev9;
68 public ExpectedException thrown = ExpectedException.none();
73 * @throws SecurityException
74 * @throws NoSuchFieldException
77 public static void configure() throws NoSuchFieldException, SecurityException, Exception {
78 System.setProperty("AJSC_HOME", ".");
79 System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
80 QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/org/openecomp/aai/introspection/");
82 new TitanDBEngine(QueryStyle.TRAVERSAL,
83 LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST),
87 new TitanDBEngine(QueryStyle.TRAVERSAL,
88 LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v9),
95 * @throws UnsupportedEncodingException the unsupported encoding exception
96 * @throws AAIException the AAI exception
99 public void parentQuery() throws UnsupportedEncodingException, AAIException {
100 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1").build();
102 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
104 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
106 "gremlin query should be " + expected.toString(),
108 query.getQueryBuilder().getQuery().toString());
110 "parent gremlin query should be equal to normal query",
112 query.getQueryBuilder().getParentQuery().getQuery().toString());
114 "result type should be complex",
116 query.getResultType());
118 "result type should be empty",
120 query.getParentResultType());
121 assertEquals("dependent",false, query.isDependent());
129 * @throws UnsupportedEncodingException the unsupported encoding exception
130 * @throws AAIException the AAI exception
133 public void childQuery() throws UnsupportedEncodingException, AAIException {
134 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3").build();
135 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
136 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
137 .has("physical-location-id", "key1").has("aai-node-type", "complex")
139 .has("aai-node-type", "ctag-pool")
140 .has("target-pe", "key2").has("availability-zone-name", "key3");
141 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
142 .has("physical-location-id", "key1").has("aai-node-type", "complex");
144 "gremlin query should be " + expected.toString(),
146 query.getQueryBuilder().getQuery().toString());
148 "parent gremlin query should be equal the query for complex",
149 expectedParent.toString(),
150 query.getQueryBuilder().getParentQuery().getQuery().toString());
152 "result type should be complex",
154 query.getParentResultType());
156 "result type should be ctag-pool",
158 query.getResultType());
159 assertEquals("dependent",true, query.isDependent());
167 * @throws UnsupportedEncodingException the unsupported encoding exception
168 * @throws AAIException the AAI exception
171 public void namingExceptions() throws UnsupportedEncodingException, AAIException {
172 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
173 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
174 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
175 .has("vnf-id", "key1").has("aai-node-type", "vce")
177 .has("aai-node-type", "port-group")
178 .has("interface-id", "key2").out("hasCTag")
179 .has("aai-node-type", "cvlan-tag")
180 .has("cvlan-tag", 655);
181 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
182 .has("vnf-id", "key1").has("aai-node-type", "vce")
184 .has("aai-node-type", "port-group")
185 .has("interface-id", "key2");
187 "gremlin query should be " + expected.toString(),
189 query.getQueryBuilder().getQuery().toString());
191 "parent gremlin query should be equal the query for port group",
192 expectedParent.toString(),
193 query.getQueryBuilder().getParentQuery().getQuery().toString());
195 "result type should be cvlan-tag",
197 query.getResultType());
199 "result type should be port-group",
201 query.getParentResultType());
203 "contaner type should be empty",
205 query.getContainerType());
206 assertEquals("dependent",true, query.isDependent());
215 * @throws UnsupportedEncodingException the unsupported encoding exception
216 * @throws AAIException the AAI exception
219 public void getAll() throws UnsupportedEncodingException, AAIException {
220 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags").build();
221 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
222 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
223 .has("vnf-id", "key1").has("aai-node-type", "vce")
225 .has("aai-node-type", "port-group")
226 .has("interface-id", "key2").out("hasCTag")
227 .has("aai-node-type", "cvlan-tag");
228 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
229 .has("vnf-id", "key1").has("aai-node-type", "vce")
231 .has("aai-node-type", "port-group")
232 .has("interface-id", "key2");
234 "gremlin query should be " + expected.toString(),
236 query.getQueryBuilder().getQuery().toString());
238 "parent gremlin query should be equal the query for port group",
239 expectedParent.toString(),
240 query.getQueryBuilder().getParentQuery().getQuery().toString());
242 "result type should be port-group",
244 query.getParentResultType());
246 "result type should be cvlan-tag",
248 query.getResultType());
250 "container type should be cvlan-tags",
252 query.getContainerType());
253 assertEquals("dependent",true, query.isDependent());
259 public void getAllParent() throws UnsupportedEncodingException, AAIException {
260 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers").build();
261 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
262 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
263 .has("aai-node-type", "pserver");
264 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
265 .has("aai-node-type", "pserver");
267 "gremlin query should be " + expected.toString(),
269 query.getQueryBuilder().getQuery().toString());
271 "parent gremlin query should be equal the query for pserver",
272 expectedParent.toString(),
273 query.getQueryBuilder().getParentQuery().getQuery().toString());
275 "parent result type should be empty",
277 query.getParentResultType());
279 "result type should be pserver",
281 query.getResultType());
283 "container type should be pservers",
285 query.getContainerType());
286 assertEquals("dependent",false, query.isDependent());
293 * Gets the via query param.
295 * @return the via query param
296 * @throws UnsupportedEncodingException the unsupported encoding exception
297 * @throws AAIException the AAI exception
300 public void getViaQueryParam() throws UnsupportedEncodingException, AAIException {
301 URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant").build();
302 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
303 map.putSingle("tenant-name", "Tenant1");
304 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
305 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
306 .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
307 .has("aai-node-type", "cloud-region")
309 .has("aai-node-type", "tenant")
310 .has("tenant-name", "Tenant1");
312 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
313 .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
314 .has("aai-node-type", "cloud-region");
317 "gremlin query should be " + expected.toString(),
319 query.getQueryBuilder().getQuery().toString());
321 "parent gremlin query should be equal the query for cloud-region",
322 expectedParent.toString(),
323 query.getQueryBuilder().getParentQuery().getQuery().toString());
325 "result type should be cloud-region",
327 query.getParentResultType());
329 "result type should be tenant",
331 query.getResultType());
333 "container type should be empty",
335 query.getContainerType());
336 assertEquals("dependent",true, query.isDependent());
341 public void getViaDuplicateQueryParam() throws UnsupportedEncodingException, AAIException {
342 URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant").build();
343 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
344 List<String> values = new ArrayList<>();
345 values.add("Tenant1");
346 values.add("Tenant2");
347 map.put("tenant-name", values);
348 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
349 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
350 .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
351 .has("aai-node-type", "cloud-region")
353 .has("aai-node-type", "tenant")
354 .has("tenant-name", P.within(values));
356 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
357 .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
358 .has("aai-node-type", "cloud-region");
361 "gremlin query should be " + expected.toString(),
363 query.getQueryBuilder().getQuery().toString());
365 "parent gremlin query should be equal the query for cloud-region",
366 expectedParent.toString(),
367 query.getQueryBuilder().getParentQuery().getQuery().toString());
369 "result type should be cloud-region",
371 query.getParentResultType());
373 "result type should be tenant",
375 query.getResultType());
377 "container type should be empty",
379 query.getContainerType());
380 assertEquals("dependent",true, query.isDependent());
385 * Gets the plural via query param.
387 * @return the plural via query param
388 * @throws UnsupportedEncodingException the unsupported encoding exception
389 * @throws AAIException the AAI exception
392 public void getPluralViaQueryParam() throws UnsupportedEncodingException, AAIException {
393 URI uri = UriBuilder.fromPath("network/vnfcs").build();
394 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
395 map.putSingle("prov-status", "up");
396 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
397 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
398 .has("aai-node-type", "vnfc")
399 .has("prov-status", "up");
401 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
402 .has("aai-node-type", "vnfc");
405 "gremlin query should be " + expected.toString(),
407 query.getQueryBuilder().getQuery().toString());
410 expectedParent.toString(),
411 query.getQueryBuilder().getParentQuery().getQuery().toString());
413 "parent result type should be empty",
415 query.getParentResultType());
417 "result type should be vnfc",
419 query.getResultType());
421 "container type should be empty",
423 query.getContainerType());
424 assertEquals("dependent",true, query.isDependent());
429 * Gets the all query param naming exception.
431 * @return the all query param naming exception
432 * @throws UnsupportedEncodingException the unsupported encoding exception
433 * @throws AAIException the AAI exception
436 public void getAllQueryParamNamingException() throws UnsupportedEncodingException, AAIException {
437 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags").build();
438 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
439 map.putSingle("cvlan-tag", "333");
440 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
442 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
443 .has("vnf-id", "key1").has("aai-node-type", "vce")
445 .has("aai-node-type", "port-group")
446 .has("interface-id", "key2").out("hasCTag")
447 .has("aai-node-type", "cvlan-tag")
448 .has("cvlan-tag", 333);
449 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
450 .has("vnf-id", "key1").has("aai-node-type", "vce")
452 .has("aai-node-type", "port-group")
453 .has("interface-id", "key2");
455 "gremlin query should be " + expected.toString(),
457 query.getQueryBuilder().getQuery().toString());
459 "parent gremlin query should be equal the query for port group",
460 expectedParent.toString(),
461 query.getQueryBuilder().getParentQuery().getQuery().toString());
463 "result type should be port-group",
465 query.getParentResultType());
467 "result type should be cvlan-tag",
469 query.getResultType());
471 "container type should be cvlan-tags",
473 query.getContainerType());
474 assertEquals("dependent",true, query.isDependent());
482 * @throws UnsupportedEncodingException the unsupported encoding exception
483 * @throws AAIException the AAI exception
486 public void abstractType() throws UnsupportedEncodingException, AAIException {
487 URI uri = UriBuilder.fromPath("vnf/key1").build();
489 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
491 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
492 .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "vpe", "generic-vnf"));
494 GraphTraversal<Vertex, Vertex> expectedParent = expected;
496 "gremlin query should be " + expected.toString(),
498 query.getQueryBuilder().getQuery().toString());
500 "parent gremlin query should be equal the query for port group",
501 expectedParent.toString(),
502 query.getQueryBuilder().getParentQuery().getQuery().toString());
504 "result type should be empty",
506 query.getParentResultType());
508 "result type should be vnf",
510 query.getResultType());
512 assertEquals("dependent",false, query.isDependent());
518 * Non parent abstract type.
520 * @throws UnsupportedEncodingException the unsupported encoding exception
521 * @throws AAIException the AAI exception
524 public void nonParentAbstractType() throws UnsupportedEncodingException, AAIException {
525 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key2/vnf/key1").build();
526 thrown.expect(AAIException.class);
527 thrown.expectMessage(containsString("not a valid path"));
528 dbEngine.getQueryBuilder().createQueryFromURI(uri);
532 public void parentAbstractTypeWithNesting() throws UnsupportedEncodingException, AAIException {
533 URI uri = UriBuilder.fromPath("vnf/key1/vf-modules/vf-module/key2").build();
535 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
537 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
538 .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "vpe", "generic-vnf"))
539 .union(__.out("has").has(AAIProperties.NODE_TYPE, "vf-module")).has("vf-module-id", "key2");
541 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
542 .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "vpe", "generic-vnf"));
544 "gremlin query should be " + expected.toString(),
546 query.getQueryBuilder().getQuery().toString());
548 "parent gremlin query should be equal the query for ",
549 expectedParent.toString(),
550 query.getQueryBuilder().getParentQuery().getQuery().toString());
552 "result type should be vnf",
554 query.getParentResultType());
556 "result type should be vf-module",
558 query.getResultType());
560 assertEquals("dependent",true, query.isDependent());
565 public void getViaBadQueryParam() throws UnsupportedEncodingException, AAIException {
566 URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/a/b/tenants/tenant").build();
567 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
568 map.putSingle("tenant-n231ame", "Tenant1");
569 thrown.expect(AAIException.class);
570 thrown.expect(hasProperty("code", is("AAI_3000")));
572 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
577 public void getPluralViaBadQueryParam() throws UnsupportedEncodingException, AAIException {
578 URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/a/b/tenants").build();
579 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
580 map.putSingle("tenant-n231ame", "Tenant1");
581 thrown.expect(AAIException.class);
582 thrown.expect(hasProperty("code", is("AAI_3000")));
584 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
589 public void getPluralViaDuplicateQueryParam() throws UnsupportedEncodingException, AAIException {
590 URI uri = UriBuilder.fromPath("network/vnfcs").build();
591 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
592 List<String> values = new ArrayList<>();
598 map.put("prov-status", values);
599 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
600 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
601 .has("aai-node-type", "vnfc")
602 .has("prov-status", P.within(values));
604 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
605 .has("aai-node-type", "vnfc");
608 "gremlin query should be " + expected.toString(),
610 query.getQueryBuilder().getQuery().toString());
613 expectedParent.toString(),
614 query.getQueryBuilder().getParentQuery().getQuery().toString());
616 "parent result type should be empty",
618 query.getParentResultType());
620 "result type should be vnfc",
622 query.getResultType());
624 "container type should be empty",
626 query.getContainerType());
627 assertEquals("dependent",true, query.isDependent());
632 public void dbAliasedSearch() throws UnsupportedEncodingException, AAIException {
633 URI uri = UriBuilder.fromPath("network/test-objects").build();
634 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
635 map.putSingle("persona-model-customization-id", "key2");
636 QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri, map);
637 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
638 .has("aai-node-type", "test-object")
639 .has("model-customization-id", "key2");
640 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
641 .has("aai-node-type", "test-object");
644 "gremlin query should be " + expected.toString(),
646 query.getQueryBuilder().getQuery().toString());
649 expectedParent.toString(),
650 query.getQueryBuilder().getParentQuery().getQuery().toString());
653 "result type should be",
655 query.getResultType());
657 "result type should be empty",
659 query.getParentResultType());
660 assertEquals("dependent",true, query.isDependent());
666 public void dataLinkedSearch() throws UnsupportedEncodingException, AAIException {
667 URI uri = UriBuilder.fromPath("network/vpn-bindings").build();
668 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
669 map.putSingle("global-route-target", "key2");
670 QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri, map);
671 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
672 .has("aai-node-type", "vpn-binding")
673 .where(__.out("has").has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "key2"));
674 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
675 .has("aai-node-type", "vpn-binding");
678 "gremlin query should be " + expected.toString(),
680 query.getQueryBuilder().getQuery().toString());
683 expectedParent.toString(),
684 query.getQueryBuilder().getParentQuery().getQuery().toString());
687 "result type should be",
689 query.getResultType());
691 "result type should be empty",
693 query.getParentResultType());
694 assertEquals("dependent",true, query.isDependent());
699 public void pluralCousin() throws UnsupportedEncodingException, AAIException {
700 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers").build();
702 QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri);
703 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
704 .has("physical-location-id", "key1")
705 .has("aai-node-type", "complex")
706 .in("locatedIn").has("aai-node-type", "pserver");
707 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
708 .has("physical-location-id", "key1")
709 .has("aai-node-type", "complex");
712 "gremlin query should be " + expected.toString(),
714 query.getQueryBuilder().getQuery().toString());
717 expectedParent.toString(),
718 query.getQueryBuilder().getParentQuery().getQuery().toString());
721 "result type should be",
723 query.getResultType());
725 "result type should be",
727 query.getParentResultType());
728 //this is controversial but we're not allowing writes on this currently
729 assertEquals("dependent",true, query.isDependent());
734 public void specificCousin() throws UnsupportedEncodingException, AAIException {
735 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2").build();
737 QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri);
738 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
739 .has("physical-location-id", "key1")
740 .has("aai-node-type", "complex")
741 .in("locatedIn").has("aai-node-type", "pserver")
742 .has("hostname", "key2");
743 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
744 .has("physical-location-id", "key1")
745 .has("aai-node-type", "complex");
748 "gremlin query should be " + expected.toString(),
750 query.getQueryBuilder().getQuery().toString());
753 expectedParent.toString(),
754 query.getQueryBuilder().getParentQuery().getQuery().toString());
757 "result type should be",
759 query.getResultType());
761 "result type should be",
763 query.getParentResultType());
764 //this is controversial but we're not allowing writes on this currently
765 assertEquals("dependent",true, query.isDependent());
770 public void doubleSpecificCousin() throws UnsupportedEncodingException, AAIException {
771 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2/related-to/vservers/vserver/key3").build();
773 QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri);
774 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
775 .has("physical-location-id", "key1")
776 .has("aai-node-type", "complex")
777 .in("locatedIn").has("aai-node-type", "pserver")
778 .has("hostname", "key2")
779 .in("runsOnPserver").has("aai-node-type", "vserver")
780 .has("vserver-id", "key3");
781 GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
782 .has("physical-location-id", "key1")
783 .has("aai-node-type", "complex")
784 .in("locatedIn").has("aai-node-type", "pserver")
785 .has("hostname", "key2");
788 "gremlin query should be " + expected.toString(),
790 query.getQueryBuilder().getQuery().toString());
793 expectedParent.toString(),
794 query.getQueryBuilder().getParentQuery().getQuery().toString());
797 "result type should be",
799 query.getResultType());
801 "result type should be",
803 query.getParentResultType());
804 //this is controversial but we're not allowing writes on this currently
805 assertEquals("dependent",true, query.isDependent());
810 public void traversalEndsInRelatedTo() throws UnsupportedEncodingException, AAIException {
811 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to").build();
813 thrown.expect(AAIException.class);
814 thrown.expectMessage(containsString(RestTokens.COUSIN.toString()));
815 QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri);
821 public void pluralCousinToPluralCousin() throws UnsupportedEncodingException, AAIException {
822 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/related-to/pservers").build();
824 thrown.expect(AAIException.class);
825 thrown.expectMessage(containsString("chain plurals"));
826 QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri);