2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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 package org.onap.aai.parsers.query;
22 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
23 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
24 import org.apache.tinkerpop.gremlin.structure.Vertex;
25 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
26 import org.junit.Ignore;
27 import org.junit.Test;
28 import org.onap.aai.AAISetup;
29 import org.onap.aai.exceptions.AAIException;
30 import org.onap.aai.introspection.LoaderFactory;
31 import org.onap.aai.introspection.ModelInjestor;
32 import org.onap.aai.introspection.ModelType;
33 import org.onap.aai.introspection.Version;
34 import org.onap.aai.serialization.engines.QueryStyle;
35 import org.onap.aai.serialization.engines.TitanDBEngine;
36 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
38 import javax.ws.rs.core.UriBuilder;
39 import java.io.UnsupportedEncodingException;
42 import static org.junit.Assert.assertEquals;
45 public class UniqueURIQueryTest extends AAISetup {
47 private ModelInjestor injestor = ModelInjestor.getInstance();
48 private TransactionalGraphEngine dbEngine =
49 new TitanDBEngine(QueryStyle.GREMLIN_UNIQUE,
50 LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8),
52 private final Version version = Version.v8;
53 private DynamicJAXBContext context = injestor.getContextForVersion(version);
58 * @throws UnsupportedEncodingException the unsupported encoding exception
59 * @throws AAIException the AAI exception
62 public void parentQuery() throws UnsupportedEncodingException, AAIException {
63 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1").build();
64 String key = "complex/key1";
65 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
66 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
67 String parentResultType = "";
68 String resultType = "complex";
69 String containerType = "";
71 testSet(query, expected, expected, parentResultType, resultType, containerType);
76 * Parent plural query.
78 * @throws UnsupportedEncodingException the unsupported encoding exception
79 * @throws AAIException the AAI exception
82 public void parentPluralQuery() throws UnsupportedEncodingException, AAIException {
83 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes").build();
84 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
85 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-node-type", "complex");
86 String parentResultType = "";
87 String resultType = "complex";
88 String containerType = "complexes";
90 testSet(query, expected, expected, parentResultType, resultType, containerType);
97 * @throws UnsupportedEncodingException the unsupported encoding exception
98 * @throws AAIException the AAI exception
101 public void childQuery() throws UnsupportedEncodingException, AAIException {
102 URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3").build();
103 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
104 String parentKey = "complex/key1";
105 String key = parentKey + "/ctag-pool/key2/key3";
106 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
107 GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", parentKey);
108 String parentResultType = "complex";
109 String resultType = "ctag-pool";
110 String containerType = "";
112 testSet(query, expected, parentExpected, parentResultType, resultType, containerType);
119 * @throws UnsupportedEncodingException the unsupported encoding exception
120 * @throws AAIException the AAI exception
123 public void namingExceptions() throws UnsupportedEncodingException, AAIException {
124 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
125 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
126 String parentKey = "vce/key1/port-group/key2";
127 String key = parentKey + "/cvlan-tag/655";
128 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
129 GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", parentKey);
130 String parentResultType = "port-group";
131 String resultType = "cvlan-tag";
132 String containerType = "";
134 testSet(query, expected, parentExpected, parentResultType, resultType, containerType);
142 * @throws UnsupportedEncodingException the unsupported encoding exception
143 * @throws AAIException the AAI exception
146 public void getAll() throws UnsupportedEncodingException, AAIException {
147 String parentURI = "network/vces/vce/key1/port-groups/port-group/key2";
148 String parentKey = "vce/key1/port-group/key2";
149 URI uri = UriBuilder.fromPath(parentURI + "/cvlan-tags").build();
150 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
151 GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", parentKey).in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "cvlan-tag");
152 GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key",parentKey);
153 String parentResultType = "port-group";
154 String resultType = "cvlan-tag";
155 String containerType = "cvlan-tags";
157 testSet(query, expected, parentExpected, parentResultType, resultType, containerType);
164 * @param query the query
165 * @param expected the expected
166 * @param parentExpected the parent expected
167 * @param parentResultType the parent result type
168 * @param resultType the result type
169 * @param containerType the container type
171 public void testSet(QueryParser query, GraphTraversal<Vertex, Vertex> expected, GraphTraversal<Vertex, Vertex> parentExpected, String parentResultType, String resultType, String containerType) {
173 "gremlin query should be " + expected,
175 query.getQueryBuilder().getQuery());
177 "parent gremlin query should be " + parentExpected,
179 query.getQueryBuilder().getParentQuery().getQuery());
181 "parent result type should be " + parentResultType,
183 query.getParentResultType());
185 "result type should be " + resultType,
187 query.getResultType());
189 "container type should be " + containerType,
191 query.getContainerType());