Change openecomp to onap and update license
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / query / builder / TraversalQueryTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  *
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.query.builder;
23
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;
38
39 import java.io.UnsupportedEncodingException;
40 import java.net.URI;
41 import java.net.URISyntaxException;
42
43 import static org.junit.Assert.assertEquals;
44
45 public class TraversalQueryTest extends AAISetup {
46
47         private Loader loader;
48
49         @Mock
50         private GraphTraversalSource g;
51
52         @Before
53         public void configure() throws Exception {
54                 loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST);
55         }
56         
57         @Test
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);
62                 tQ.union(
63                                 tQ2.getVerticesByProperty("test1", "value1"),
64                                 tQ3.getVerticesByIndexedProperty("test2", "value2"));
65                 
66                 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
67                                 .union(__.has("test1", "value1"),__.has("test2", "value2"));
68                 
69                 assertEquals("they are equal", expected, tQ.getQuery());
70                 
71         }
72
73         @Ignore
74         @Test
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");
80                 
81                 assertEquals("query object", expected.toString(), builder.getQuery().toString());
82                 assertEquals("container query object", containerExpected.toString(), builder.getContainerQuery().getQuery().toString());
83                 
84         }
85
86         @Ignore
87         @Test
88         public void nestedTraversalClones() throws UnsupportedEncodingException, AAIException, URISyntaxException {
89                 
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");
94                 
95                 assertEquals("query object", expected.toString(), builder.getQuery().toString());
96                 assertEquals("container query object", containerExpected.toString(), builder.getContainerQuery().getQuery().toString());
97                 
98         }
99         
100         
101         
102 }