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 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.junit.Ignore;
32 import org.junit.Test;
33 import org.onap.aai.AAISetup;
34 import org.onap.aai.exceptions.AAIException;
35 import org.onap.aai.introspection.ModelType;
36 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
37 import org.onap.aai.serialization.engines.QueryStyle;
38 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
39 import org.onap.aai.setup.SchemaVersion;
42 public class LegacyQueryTest extends AAISetup {
44 private TransactionalGraphEngine dbEngine;
45 private SchemaVersion version;
48 version = new SchemaVersion("v10");
49 dbEngine = new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
50 loaderFactory.createLoaderForVersion(ModelType.MOXY, version), false);
56 * @throws JAXBException the JAXB exception
57 * @throws UnsupportedEncodingException the unsupported encoding exception
58 * @throws AAIException the AAI exception
61 public void parentQuery() throws UnsupportedEncodingException, AAIException {
63 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1").build();
65 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
67 String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
68 assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
69 assertEquals("parent gremlin query should be equal to normal query", expected,
70 query.getQueryBuilder().getParentQuery().getQuery());
71 assertEquals("result type should be pserver", "pserver", query.getResultType());
78 * @throws JAXBException the JAXB exception
79 * @throws UnsupportedEncodingException the unsupported encoding exception
80 * @throws AAIException the AAI exception
83 public void childQuery() throws UnsupportedEncodingException, AAIException {
84 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1/lag-interfaces/lag-interface/key2")
86 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
88 String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')"
89 + ".out('hasLAGInterface').has('aai-node-type', 'lag-interface')" + ".has('interface-name', 'key2')";
90 String parentExpected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
91 assertEquals("gremlin query should be for node", expected, query.getQueryBuilder().getQuery());
92 assertEquals("parent gremlin query should be for parent", parentExpected,
93 query.getQueryBuilder().getParentQuery().getQuery());
94 assertEquals("result type should be lag-interface", "lag-interface", query.getResultType());
100 * @throws JAXBException the JAXB exception
101 * @throws UnsupportedEncodingException the unsupported encoding exception
102 * @throws AAIException the AAI exception
105 public void namingExceptions() throws UnsupportedEncodingException, AAIException {
106 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655")
109 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
110 String expected = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
111 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
112 + ".has('interface-id', 'key2')"
113 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
114 + ".has('cvlan-tag', 655)";
115 String expectedParent = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
116 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
117 + ".has('interface-id', 'key2')";
118 assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
119 assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
120 query.getQueryBuilder().getParentQuery().getQuery());
121 assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());