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.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
23 import org.junit.Ignore;
24 import org.junit.Test;
25 import org.onap.aai.AAISetup;
26 import org.onap.aai.exceptions.AAIException;
28 import org.onap.aai.introspection.ModelType;
29 import org.onap.aai.serialization.engines.QueryStyle;
30 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
31 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
32 import org.onap.aai.setup.SchemaVersion;
34 import javax.ws.rs.core.UriBuilder;
35 import javax.xml.bind.JAXBException;
36 import java.io.UnsupportedEncodingException;
39 import static org.junit.Assert.assertEquals;
43 public class LegacyQueryTest extends AAISetup {
46 private TransactionalGraphEngine dbEngine;
47 private SchemaVersion version;
48 private DynamicJAXBContext context = nodeIngestor.getContextForVersion(version);
51 version = new SchemaVersion("v10");
53 new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
54 loaderFactory.createLoaderForVersion(ModelType.MOXY, version),
61 * @throws JAXBException the JAXB exception
62 * @throws UnsupportedEncodingException the unsupported encoding exception
63 * @throws AAIException the AAI exception
66 public void parentQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
68 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1").build();
70 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
73 ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
75 "gremlin query should be " + expected,
77 query.getQueryBuilder().getQuery());
79 "parent gremlin query should be equal to normal query",
81 query.getQueryBuilder().getParentQuery().getQuery());
83 "result type should be pserver",
85 query.getResultType());
92 * @throws JAXBException the JAXB exception
93 * @throws UnsupportedEncodingException the unsupported encoding exception
94 * @throws AAIException the AAI exception
97 public void childQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
98 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1/lag-interfaces/lag-interface/key2").build();
99 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
102 ".has('hostname', 'key1').has('aai-node-type', 'pserver')"
103 + ".out('hasLAGInterface').has('aai-node-type', 'lag-interface')"
104 + ".has('interface-name', 'key2')";
105 String parentExpected =
106 ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
108 "gremlin query should be for node",
110 query.getQueryBuilder().getQuery());
112 "parent gremlin query should be for parent",
114 query.getQueryBuilder().getParentQuery().getQuery());
116 "result type should be lag-interface",
118 query.getResultType());
124 * @throws JAXBException the JAXB exception
125 * @throws UnsupportedEncodingException the unsupported encoding exception
126 * @throws AAIException the AAI exception
129 public void namingExceptions() throws JAXBException, UnsupportedEncodingException, AAIException {
130 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
132 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
134 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
135 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
136 + ".has('interface-id', 'key2')"
137 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
138 + ".has('cvlan-tag', 655)";
139 String expectedParent =
140 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
141 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
142 + ".has('interface-id', 'key2')";
144 "gremlin query should be " + expected,
146 query.getQueryBuilder().getQuery());
148 "parent gremlin query should be equal the query for port group",
150 query.getQueryBuilder().getParentQuery().getQuery());
152 "result type should be cvlan-tag",
154 query.getResultType());