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.parsers.query;
24 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
25 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
26 import org.apache.tinkerpop.gremlin.structure.Vertex;
27 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
28 import org.junit.Ignore;
29 import org.junit.Test;
30 import org.onap.aai.AAISetup;
31 import org.onap.aai.exceptions.AAIException;
32 import org.onap.aai.introspection.LoaderFactory;
33 import org.onap.aai.introspection.ModelInjestor;
34 import org.onap.aai.introspection.ModelType;
35 import org.onap.aai.introspection.Version;
36 import org.onap.aai.serialization.engines.QueryStyle;
37 import org.onap.aai.serialization.engines.TitanDBEngine;
38 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
40 import javax.ws.rs.core.UriBuilder;
41 import java.io.UnsupportedEncodingException;
44 import static org.junit.Assert.assertEquals;
47 public class UniqueURIQueryTest extends AAISetup {
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);
60 * @throws UnsupportedEncodingException the unsupported encoding exception
61 * @throws AAIException the AAI exception
64 public void parentQuery() throws UnsupportedEncodingException, AAIException {
65 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1").build();
66 String key = "complex/key1";
67 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
68 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
69 String parentResultType = "";
70 String resultType = "complex";
71 String containerType = "";
73 testSet(query, expected, expected, parentResultType, resultType, containerType);
78 * Parent plural query.
80 * @throws UnsupportedEncodingException the unsupported encoding exception
81 * @throws AAIException the AAI exception
84 public void parentPluralQuery() throws UnsupportedEncodingException, AAIException {
85 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes").build();
86 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
87 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-node-type", "complex");
88 String parentResultType = "";
89 String resultType = "complex";
90 String containerType = "complexes";
92 testSet(query, expected, expected, parentResultType, resultType, containerType);
99 * @throws UnsupportedEncodingException the unsupported encoding exception
100 * @throws AAIException the AAI exception
103 public void childQuery() throws UnsupportedEncodingException, AAIException {
104 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3").build();
105 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
106 String parentKey = "complex/key1";
107 String key = parentKey + "/ctag-pool/key2/key3";
108 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
109 GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", parentKey);
110 String parentResultType = "complex";
111 String resultType = "ctag-pool";
112 String containerType = "";
114 testSet(query, expected, parentExpected, parentResultType, resultType, containerType);
121 * @throws UnsupportedEncodingException the unsupported encoding exception
122 * @throws AAIException the AAI exception
125 public void namingExceptions() throws UnsupportedEncodingException, AAIException {
126 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
127 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
128 String parentKey = "vce/key1/port-group/key2";
129 String key = parentKey + "/cvlan-tag/655";
130 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
131 GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", parentKey);
132 String parentResultType = "port-group";
133 String resultType = "cvlan-tag";
134 String containerType = "";
136 testSet(query, expected, parentExpected, parentResultType, resultType, containerType);
144 * @throws UnsupportedEncodingException the unsupported encoding exception
145 * @throws AAIException the AAI exception
148 public void getAll() throws UnsupportedEncodingException, AAIException {
149 String parentURI = "network/vces/vce/key1/port-groups/port-group/key2";
150 String parentKey = "vce/key1/port-group/key2";
151 URI uri = UriBuilder.fromPath(parentURI + "/cvlan-tags").build();
152 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
153 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", parentKey).in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "cvlan-tag");
154 GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key",parentKey);
155 String parentResultType = "port-group";
156 String resultType = "cvlan-tag";
157 String containerType = "cvlan-tags";
159 testSet(query, expected, parentExpected, parentResultType, resultType, containerType);
166 * @param query the query
167 * @param expected the expected
168 * @param parentExpected the parent expected
169 * @param parentResultType the parent result type
170 * @param resultType the result type
171 * @param containerType the container type
173 public void testSet(QueryParser query, GraphTraversal<Vertex, Vertex> expected, GraphTraversal<Vertex, Vertex> parentExpected, String parentResultType, String resultType, String containerType) {
175 "gremlin query should be " + expected,
177 query.getQueryBuilder().getQuery());
179 "parent gremlin query should be " + parentExpected,
181 query.getQueryBuilder().getParentQuery().getQuery());
183 "parent result type should be " + parentResultType,
185 query.getParentResultType());
187 "result type should be " + resultType,
189 query.getResultType());
191 "container type should be " + containerType,
193 query.getContainerType());