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.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
32 import org.junit.Ignore;
33 import org.junit.Test;
34 import org.onap.aai.AAISetup;
35 import org.onap.aai.exceptions.AAIException;
36 import org.onap.aai.introspection.ModelType;
37 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
38 import org.onap.aai.serialization.engines.QueryStyle;
39 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
40 import org.onap.aai.setup.SchemaVersion;
43 public class LegacyQueryTest extends AAISetup {
45 private TransactionalGraphEngine dbEngine;
46 private SchemaVersion version;
47 private DynamicJAXBContext context = nodeIngestor.getContextForVersion(version);
50 version = new SchemaVersion("v10");
51 dbEngine = new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
52 loaderFactory.createLoaderForVersion(ModelType.MOXY, version), false);
58 * @throws JAXBException the JAXB exception
59 * @throws UnsupportedEncodingException the unsupported encoding exception
60 * @throws AAIException the AAI exception
63 public void parentQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
65 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1").build();
67 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
69 String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
70 assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
71 assertEquals("parent gremlin query should be equal to normal query", expected,
72 query.getQueryBuilder().getParentQuery().getQuery());
73 assertEquals("result type should be pserver", "pserver", query.getResultType());
80 * @throws JAXBException the JAXB exception
81 * @throws UnsupportedEncodingException the unsupported encoding exception
82 * @throws AAIException the AAI exception
85 public void childQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
86 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1/lag-interfaces/lag-interface/key2")
88 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
90 String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')"
91 + ".out('hasLAGInterface').has('aai-node-type', 'lag-interface')" + ".has('interface-name', 'key2')";
92 String parentExpected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
93 assertEquals("gremlin query should be for node", expected, query.getQueryBuilder().getQuery());
94 assertEquals("parent gremlin query should be for parent", parentExpected,
95 query.getQueryBuilder().getParentQuery().getQuery());
96 assertEquals("result type should be lag-interface", "lag-interface", query.getResultType());
102 * @throws JAXBException the JAXB exception
103 * @throws UnsupportedEncodingException the unsupported encoding exception
104 * @throws AAIException the AAI exception
107 public void namingExceptions() throws JAXBException, UnsupportedEncodingException, AAIException {
108 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655")
111 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
112 String expected = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
113 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
114 + ".has('interface-id', 'key2')"
115 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
116 + ".has('cvlan-tag', 655)";
117 String expectedParent = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
118 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
119 + ".has('interface-id', 'key2')";
120 assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
121 assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
122 query.getQueryBuilder().getParentQuery().getQuery());
123 assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());