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;
29 import javax.xml.bind.JAXBException;
31 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
32 import org.junit.BeforeClass;
33 import org.junit.Ignore;
34 import org.junit.Test;
36 import org.openecomp.aai.exceptions.AAIException;
37 import org.openecomp.aai.introspection.LoaderFactory;
38 import org.openecomp.aai.introspection.ModelInjestor;
39 import org.openecomp.aai.introspection.ModelType;
40 import org.openecomp.aai.introspection.Version;
41 import org.openecomp.aai.serialization.engines.QueryStyle;
42 import org.openecomp.aai.serialization.engines.TitanDBEngine;
43 import org.openecomp.aai.serialization.engines.TransactionalGraphEngine;
46 public class LegacyQueryTest {
47 private ModelInjestor injestor = ModelInjestor.getInstance();
48 private TransactionalGraphEngine dbEngine =
49 new TitanDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
50 LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8),
52 private final Version version = Version.v8;
53 private DynamicJAXBContext context = injestor.getContextForVersion(version);
60 public static void configure() {
61 System.setProperty("AJSC_HOME", ".");
62 System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
68 * @throws JAXBException the JAXB exception
69 * @throws UnsupportedEncodingException the unsupported encoding exception
70 * @throws AAIException the AAI exception
73 public void parentQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
75 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1").build();
77 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
80 ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
82 "gremlin query should be " + expected,
84 query.getQueryBuilder().getQuery());
86 "parent gremlin query should be equal to normal query",
88 query.getQueryBuilder().getParentQuery().getQuery());
90 "result type should be pserver",
92 query.getResultType());
99 * @throws JAXBException the JAXB exception
100 * @throws UnsupportedEncodingException the unsupported encoding exception
101 * @throws AAIException the AAI exception
104 public void childQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
105 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1/lag-interfaces/lag-interface/key2").build();
106 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
109 ".has('hostname', 'key1').has('aai-node-type', 'pserver')"
110 + ".out('hasLAGInterface').has('aai-node-type', 'lag-interface')"
111 + ".has('interface-name', 'key2')";
112 String parentExpected =
113 ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
115 "gremlin query should be for node",
117 query.getQueryBuilder().getQuery());
119 "parent gremlin query should be for parent",
121 query.getQueryBuilder().getParentQuery().getQuery());
123 "result type should be lag-interface",
125 query.getResultType());
131 * @throws JAXBException the JAXB exception
132 * @throws UnsupportedEncodingException the unsupported encoding exception
133 * @throws AAIException the AAI exception
137 public void namingExceptions() throws JAXBException, UnsupportedEncodingException, AAIException {
138 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
140 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
142 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
143 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
144 + ".has('interface-id', 'key2')"
145 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
146 + ".has('cvlan-tag', 655)";
147 String expectedParent =
148 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
149 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
150 + ".has('interface-id', 'key2')";
152 "gremlin query should be " + expected,
154 query.getQueryBuilder().getQuery());
156 "parent gremlin query should be equal the query for port group",
158 query.getQueryBuilder().getParentQuery().getQuery());
160 "result type should be cvlan-tag",
162 query.getResultType());