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.junit.Assert.assertEquals;
25 import java.io.UnsupportedEncodingException;
28 import javax.ws.rs.core.UriBuilder;
30 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
31 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
32 import org.apache.tinkerpop.gremlin.structure.Vertex;
33 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
34 import org.junit.BeforeClass;
35 import org.junit.Ignore;
36 import org.junit.Test;
38 import org.openecomp.aai.exceptions.AAIException;
39 import org.openecomp.aai.introspection.LoaderFactory;
40 import org.openecomp.aai.introspection.ModelInjestor;
41 import org.openecomp.aai.introspection.ModelType;
42 import org.openecomp.aai.introspection.Version;
43 import org.openecomp.aai.serialization.engines.QueryStyle;
44 import org.openecomp.aai.serialization.engines.TitanDBEngine;
45 import org.openecomp.aai.serialization.engines.TransactionalGraphEngine;
48 public class UniqueURIQueryTest {
49 private ModelInjestor injestor = ModelInjestor.getInstance();
50 private TransactionalGraphEngine dbEngine =
51 new TitanDBEngine(QueryStyle.GREMLIN_UNIQUE,
52 LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8),
54 private final Version version = Version.v8;
55 private DynamicJAXBContext context = injestor.getContextForVersion(version);
61 public static void configure() {
62 System.setProperty("AJSC_HOME", ".");
63 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
70 * @throws UnsupportedEncodingException the unsupported encoding exception
71 * @throws AAIException the AAI exception
74 public void parentQuery() throws UnsupportedEncodingException, AAIException {
75 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1").build();
76 String key = "complex/key1";
77 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
78 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
79 String parentResultType = "";
80 String resultType = "complex";
81 String containerType = "";
83 testSet(query, expected, expected, parentResultType, resultType, containerType);
88 * Parent plural query.
90 * @throws UnsupportedEncodingException the unsupported encoding exception
91 * @throws AAIException the AAI exception
94 public void parentPluralQuery() throws UnsupportedEncodingException, AAIException {
95 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes").build();
96 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
97 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-node-type", "complex");
98 String parentResultType = "";
99 String resultType = "complex";
100 String containerType = "complexes";
102 testSet(query, expected, expected, parentResultType, resultType, containerType);
109 * @throws UnsupportedEncodingException the unsupported encoding exception
110 * @throws AAIException the AAI exception
113 public void childQuery() throws UnsupportedEncodingException, AAIException {
114 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3").build();
115 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
116 String parentKey = "complex/key1";
117 String key = parentKey + "/ctag-pool/key2/key3";
118 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
119 GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", parentKey);
120 String parentResultType = "complex";
121 String resultType = "ctag-pool";
122 String containerType = "";
124 testSet(query, expected, parentExpected, parentResultType, resultType, containerType);
131 * @throws UnsupportedEncodingException the unsupported encoding exception
132 * @throws AAIException the AAI exception
135 public void namingExceptions() throws UnsupportedEncodingException, AAIException {
136 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
137 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
138 String parentKey = "vce/key1/port-group/key2";
139 String key = parentKey + "/cvlan-tag/655";
140 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
141 GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", parentKey);
142 String parentResultType = "port-group";
143 String resultType = "cvlan-tag";
144 String containerType = "";
146 testSet(query, expected, parentExpected, parentResultType, resultType, containerType);
154 * @throws UnsupportedEncodingException the unsupported encoding exception
155 * @throws AAIException the AAI exception
158 public void getAll() throws UnsupportedEncodingException, AAIException {
159 String parentURI = "network/vces/vce/key1/port-groups/port-group/key2";
160 String parentKey = "vce/key1/port-group/key2";
161 URI uri = UriBuilder.fromPath(parentURI + "/cvlan-tags").build();
162 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
163 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", parentKey).out("hasCTag").has("aai-node-type", "cvlan-tag");
164 GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key",parentKey);
165 String parentResultType = "port-group";
166 String resultType = "cvlan-tag";
167 String containerType = "cvlan-tags";
169 testSet(query, expected, parentExpected, parentResultType, resultType, containerType);
176 * @param query the query
177 * @param expected the expected
178 * @param parentExpected the parent expected
179 * @param parentResultType the parent result type
180 * @param resultType the result type
181 * @param containerType the container type
183 public void testSet(QueryParser query, GraphTraversal<Vertex, Vertex> expected, GraphTraversal<Vertex, Vertex> parentExpected, String parentResultType, String resultType, String containerType) {
185 "gremlin query should be " + expected,
187 query.getQueryBuilder().getQuery());
189 "parent gremlin query should be " + parentExpected,
191 query.getQueryBuilder().getParentQuery().getQuery());
193 "parent result type should be " + parentResultType,
195 query.getParentResultType());
197 "result type should be " + resultType,
199 query.getResultType());
201 "container type should be " + containerType,
203 query.getContainerType());