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.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
24 import org.junit.BeforeClass;
25 import org.junit.Test;
26 import org.openecomp.aai.exceptions.AAIException;
27 import org.openecomp.aai.introspection.LoaderFactory;
28 import org.openecomp.aai.introspection.ModelInjestor;
29 import org.openecomp.aai.introspection.ModelType;
30 import org.openecomp.aai.introspection.Version;
31 import org.openecomp.aai.serialization.engines.QueryStyle;
32 import org.openecomp.aai.serialization.engines.TitanDBEngine;
33 import org.openecomp.aai.serialization.engines.TransactionalGraphEngine;
35 import javax.ws.rs.core.UriBuilder;
36 import javax.xml.bind.JAXBException;
37 import java.io.UnsupportedEncodingException;
40 import static org.junit.Assert.assertEquals;
43 public class LegacyQueryTest {
44 private ModelInjestor injestor = ModelInjestor.getInstance();
45 private TransactionalGraphEngine dbEngine =
46 new TitanDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
47 LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8),
49 private final Version version = Version.v8;
50 private DynamicJAXBContext context = injestor.getContextForVersion(version);
57 public static void configure() {
58 System.setProperty("AJSC_HOME", "./src/test/resources/");
59 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
65 * @throws JAXBException the JAXB exception
66 * @throws UnsupportedEncodingException the unsupported encoding exception
67 * @throws AAIException the AAI exception
70 public void parentQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
72 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1").build();
74 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
77 ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
79 "gremlin query should be " + expected,
81 query.getQueryBuilder().getQuery());
83 "parent gremlin query should be equal to normal query",
85 query.getQueryBuilder().getParentQuery().getQuery());
87 "result type should be pserver",
89 query.getResultType());
96 * @throws JAXBException the JAXB exception
97 * @throws UnsupportedEncodingException the unsupported encoding exception
98 * @throws AAIException the AAI exception
101 public void childQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
102 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1/lag-interfaces/lag-interface/key2").build();
103 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
106 ".has('hostname', 'key1').has('aai-node-type', 'pserver')"
107 + ".in('tosca.relationships.BindsTo').has('aai-node-type', 'lag-interface')"
108 + ".has('interface-name', 'key2')";
109 String parentExpected =
110 ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
112 "gremlin query should be for node",
114 query.getQueryBuilder().getQuery());
116 "parent gremlin query should be for parent",
118 query.getQueryBuilder().getParentQuery().getQuery());
120 "result type should be lag-interface",
122 query.getResultType());
128 * @throws JAXBException the JAXB exception
129 * @throws UnsupportedEncodingException the unsupported encoding exception
130 * @throws AAIException the AAI exception
133 public void namingExceptions() throws JAXBException, UnsupportedEncodingException, AAIException {
134 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
136 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
138 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
139 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
140 + ".has('interface-id', 'key2')"
141 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
142 + ".has('cvlan-tag', 655)";
143 String expectedParent =
144 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
145 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
146 + ".has('interface-id', 'key2')";
148 "gremlin query should be " + expected,
150 query.getQueryBuilder().getQuery());
152 "parent gremlin query should be equal the query for port group",
154 query.getQueryBuilder().getParentQuery().getQuery());
156 "result type should be cvlan-tag",
158 query.getResultType());