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=========================================================
21 package org.onap.aai.parsers.query;
23 import org.junit.Ignore;
24 import org.junit.Test;
25 import org.onap.aai.AAISetup;
26 import org.onap.aai.exceptions.AAIException;
27 import org.onap.aai.introspection.ModelType;
28 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
29 import org.onap.aai.serialization.engines.QueryStyle;
30 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
31 import org.onap.aai.setup.SchemaVersion;
33 import javax.ws.rs.core.UriBuilder;
34 import javax.xml.bind.JAXBException;
35 import java.io.UnsupportedEncodingException;
38 import static org.junit.Assert.assertEquals;
41 public class LegacyQueryTest extends AAISetup {
43 private TransactionalGraphEngine dbEngine;
44 private SchemaVersion version;
47 version = new SchemaVersion("v10");
48 dbEngine = new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
49 loaderFactory.createLoaderForVersion(ModelType.MOXY, version), false);
55 * @throws JAXBException the JAXB exception
56 * @throws UnsupportedEncodingException the unsupported encoding exception
57 * @throws AAIException the AAI exception
60 public void parentQuery() throws UnsupportedEncodingException, AAIException {
62 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1").build();
64 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
66 String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
67 assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
68 assertEquals("parent gremlin query should be equal to normal query", expected,
69 query.getQueryBuilder().getParentQuery().getQuery());
70 assertEquals("result type should be pserver", "pserver", query.getResultType());
77 * @throws JAXBException the JAXB exception
78 * @throws UnsupportedEncodingException the unsupported encoding exception
79 * @throws AAIException the AAI exception
82 public void childQuery() throws UnsupportedEncodingException, AAIException {
83 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1/lag-interfaces/lag-interface/key2")
85 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
87 String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')"
88 + ".out('hasLAGInterface').has('aai-node-type', 'lag-interface')" + ".has('interface-name', 'key2')";
89 String parentExpected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
90 assertEquals("gremlin query should be for node", expected, query.getQueryBuilder().getQuery());
91 assertEquals("parent gremlin query should be for parent", parentExpected,
92 query.getQueryBuilder().getParentQuery().getQuery());
93 assertEquals("result type should be lag-interface", "lag-interface", query.getResultType());
99 * @throws JAXBException the JAXB exception
100 * @throws UnsupportedEncodingException the unsupported encoding exception
101 * @throws AAIException the AAI exception
104 public void namingExceptions() throws UnsupportedEncodingException, AAIException {
105 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655")
108 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
109 String expected = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
110 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
111 + ".has('interface-id', 'key2')"
112 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
113 + ".has('cvlan-tag', 655)";
114 String expectedParent = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
115 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
116 + ".has('interface-id', 'key2')";
117 assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
118 assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
119 query.getQueryBuilder().getParentQuery().getQuery());
120 assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());