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 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
24 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
25 import org.apache.tinkerpop.gremlin.structure.Vertex;
26 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
27 import org.junit.Ignore;
28 import org.junit.Test;
29 import org.openecomp.aai.AAISetup;
30 import org.openecomp.aai.exceptions.AAIException;
31 import org.openecomp.aai.introspection.LoaderFactory;
32 import org.openecomp.aai.introspection.ModelInjestor;
33 import org.openecomp.aai.introspection.ModelType;
34 import org.openecomp.aai.introspection.Version;
35 import org.openecomp.aai.serialization.engines.QueryStyle;
36 import org.openecomp.aai.serialization.engines.TitanDBEngine;
37 import org.openecomp.aai.serialization.engines.TransactionalGraphEngine;
39 import javax.ws.rs.core.UriBuilder;
40 import java.io.UnsupportedEncodingException;
43 import static org.junit.Assert.assertEquals;
46 public class UniqueURIQueryTest extends AAISetup {
48 private ModelInjestor injestor = ModelInjestor.getInstance();
49 private TransactionalGraphEngine dbEngine =
50 new TitanDBEngine(QueryStyle.GREMLIN_UNIQUE,
51 LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8),
53 private final Version version = Version.v8;
54 private DynamicJAXBContext context = injestor.getContextForVersion(version);
59 * @throws UnsupportedEncodingException the unsupported encoding exception
60 * @throws AAIException the AAI exception
63 public void parentQuery() throws UnsupportedEncodingException, AAIException {
64 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1").build();
65 String key = "complex/key1";
66 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
67 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
68 String parentResultType = "";
69 String resultType = "complex";
70 String containerType = "";
72 testSet(query, expected, expected, parentResultType, resultType, containerType);
77 * Parent plural query.
79 * @throws UnsupportedEncodingException the unsupported encoding exception
80 * @throws AAIException the AAI exception
83 public void parentPluralQuery() throws UnsupportedEncodingException, AAIException {
84 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes").build();
85 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
86 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-node-type", "complex");
87 String parentResultType = "";
88 String resultType = "complex";
89 String containerType = "complexes";
91 testSet(query, expected, expected, parentResultType, resultType, containerType);
98 * @throws UnsupportedEncodingException the unsupported encoding exception
99 * @throws AAIException the AAI exception
102 public void childQuery() throws UnsupportedEncodingException, AAIException {
103 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3").build();
104 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
105 String parentKey = "complex/key1";
106 String key = parentKey + "/ctag-pool/key2/key3";
107 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
108 GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", parentKey);
109 String parentResultType = "complex";
110 String resultType = "ctag-pool";
111 String containerType = "";
113 testSet(query, expected, parentExpected, parentResultType, resultType, containerType);
120 * @throws UnsupportedEncodingException the unsupported encoding exception
121 * @throws AAIException the AAI exception
124 public void namingExceptions() throws UnsupportedEncodingException, AAIException {
125 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
126 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
127 String parentKey = "vce/key1/port-group/key2";
128 String key = parentKey + "/cvlan-tag/655";
129 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
130 GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", parentKey);
131 String parentResultType = "port-group";
132 String resultType = "cvlan-tag";
133 String containerType = "";
135 testSet(query, expected, parentExpected, parentResultType, resultType, containerType);
143 * @throws UnsupportedEncodingException the unsupported encoding exception
144 * @throws AAIException the AAI exception
147 public void getAll() throws UnsupportedEncodingException, AAIException {
148 String parentURI = "network/vces/vce/key1/port-groups/port-group/key2";
149 String parentKey = "vce/key1/port-group/key2";
150 URI uri = UriBuilder.fromPath(parentURI + "/cvlan-tags").build();
151 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
152 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", parentKey).out("hasCTag").has("aai-node-type", "cvlan-tag");
153 GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key",parentKey);
154 String parentResultType = "port-group";
155 String resultType = "cvlan-tag";
156 String containerType = "cvlan-tags";
158 testSet(query, expected, parentExpected, parentResultType, resultType, containerType);
165 * @param query the query
166 * @param expected the expected
167 * @param parentExpected the parent expected
168 * @param parentResultType the parent result type
169 * @param resultType the result type
170 * @param containerType the container type
172 public void testSet(QueryParser query, GraphTraversal<Vertex, Vertex> expected, GraphTraversal<Vertex, Vertex> parentExpected, String parentResultType, String resultType, String containerType) {
174 "gremlin query should be " + expected,
176 query.getQueryBuilder().getQuery());
178 "parent gremlin query should be " + parentExpected,
180 query.getQueryBuilder().getParentQuery().getQuery());
182 "parent result type should be " + parentResultType,
184 query.getParentResultType());
186 "result type should be " + resultType,
188 query.getResultType());
190 "container type should be " + containerType,
192 query.getContainerType());