2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.query.builder;
24 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
25 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
26 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
27 import org.apache.tinkerpop.gremlin.structure.Vertex;
28 import org.junit.Before;
29 import org.junit.Ignore;
30 import org.junit.Test;
31 import org.mockito.Mock;
32 import org.onap.aai.AAISetup;
33 import org.onap.aai.db.props.AAIProperties;
34 import org.onap.aai.exceptions.AAIException;
35 import org.onap.aai.introspection.Loader;
36 import org.onap.aai.introspection.LoaderFactory;
37 import org.onap.aai.introspection.ModelType;
39 import java.io.UnsupportedEncodingException;
41 import java.net.URISyntaxException;
43 import static org.junit.Assert.assertEquals;
45 public class TraversalQueryTest extends AAISetup {
47 private Loader loader;
50 private GraphTraversalSource g;
53 public void configure() throws Exception {
54 loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST);
58 public void unionQuery() {
59 TraversalQuery<Vertex> tQ = new TraversalQuery<>(loader, g);
60 TraversalQuery<Vertex> tQ2 = new TraversalQuery<>(loader, g);
61 TraversalQuery<Vertex> tQ3 = new TraversalQuery<>(loader, g);
63 tQ2.getVerticesByProperty("test1", "value1"),
64 tQ3.getVerticesByIndexedProperty("test2", "value2"));
66 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
67 .union(__.has("test1", "value1"),__.has("test2", "value2"));
69 assertEquals("they are equal", expected, tQ.getQuery());
75 public void traversalClones() throws UnsupportedEncodingException, AAIException, URISyntaxException {
76 TraversalQuery<Vertex> tQ = new TraversalQuery<>(loader, g);
77 QueryBuilder<Vertex> builder = tQ.createQueryFromURI(new URI("network/test-objects/test-object/key1")).getQueryBuilder();
78 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "test-object");
79 GraphTraversal<Vertex, Vertex> containerExpected = __.<Vertex>start().has("aai-node-type", "test-object");
81 assertEquals("query object", expected.toString(), builder.getQuery().toString());
82 assertEquals("container query object", containerExpected.toString(), builder.getContainerQuery().getQuery().toString());
88 public void nestedTraversalClones() throws UnsupportedEncodingException, AAIException, URISyntaxException {
90 TraversalQuery<Vertex> tQ = new TraversalQuery<>(loader, g);
91 QueryBuilder<Vertex> builder = tQ.createQueryFromURI(new URI("network/generic-vnfs/generic-vnf/key1/l-interfaces/l-interface/key2")).getQueryBuilder();
92 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "generic-vnf").out("hasLInterface").has(AAIProperties.NODE_TYPE, "l-interface").has("interface-name", "key2");
93 GraphTraversal<Vertex, Vertex> containerExpected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "generic-vnf").out("hasLInterface").has(AAIProperties.NODE_TYPE, "l-interface");
95 assertEquals("query object", expected.toString(), builder.getQuery().toString());
96 assertEquals("container query object", containerExpected.toString(), builder.getContainerQuery().getQuery().toString());