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;
27 import org.onap.aai.introspection.LoaderFactory;
28 import org.onap.aai.introspection.ModelInjestor;
29 import org.onap.aai.introspection.ModelType;
30 import org.onap.aai.introspection.Version;
31 import org.onap.aai.serialization.engines.QueryStyle;
32 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
33 import org.onap.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;
44 public class LegacyQueryTest extends AAISetup {
46 private ModelInjestor injestor = ModelInjestor.getInstance();
48 private TransactionalGraphEngine dbEngine =
49 new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
50 LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8),
52 private final Version version = Version.v8;
53 private DynamicJAXBContext context = injestor.getContextForVersion(version);
59 * @throws JAXBException the JAXB exception
60 * @throws UnsupportedEncodingException the unsupported encoding exception
61 * @throws AAIException the AAI exception
64 public void parentQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
66 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1").build();
68 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
71 ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
73 "gremlin query should be " + expected,
75 query.getQueryBuilder().getQuery());
77 "parent gremlin query should be equal to normal query",
79 query.getQueryBuilder().getParentQuery().getQuery());
81 "result type should be pserver",
83 query.getResultType());
90 * @throws JAXBException the JAXB exception
91 * @throws UnsupportedEncodingException the unsupported encoding exception
92 * @throws AAIException the AAI exception
95 public void childQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
96 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1/lag-interfaces/lag-interface/key2").build();
97 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
100 ".has('hostname', 'key1').has('aai-node-type', 'pserver')"
101 + ".out('hasLAGInterface').has('aai-node-type', 'lag-interface')"
102 + ".has('interface-name', 'key2')";
103 String parentExpected =
104 ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
106 "gremlin query should be for node",
108 query.getQueryBuilder().getQuery());
110 "parent gremlin query should be for parent",
112 query.getQueryBuilder().getParentQuery().getQuery());
114 "result type should be lag-interface",
116 query.getResultType());
122 * @throws JAXBException the JAXB exception
123 * @throws UnsupportedEncodingException the unsupported encoding exception
124 * @throws AAIException the AAI exception
127 public void namingExceptions() throws JAXBException, UnsupportedEncodingException, AAIException {
128 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
130 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
132 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
133 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
134 + ".has('interface-id', 'key2')"
135 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
136 + ".has('cvlan-tag', 655)";
137 String expectedParent =
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')";
142 "gremlin query should be " + expected,
144 query.getQueryBuilder().getQuery());
146 "parent gremlin query should be equal the query for port group",
148 query.getQueryBuilder().getParentQuery().getQuery());
150 "result type should be cvlan-tag",
152 query.getResultType());