2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.openecomp.aai.parsers.query;
23 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
24 import org.junit.Ignore;
25 import org.junit.Test;
26 import org.openecomp.aai.AAISetup;
27 import org.openecomp.aai.exceptions.AAIException;
28 import org.openecomp.aai.introspection.LoaderFactory;
29 import org.openecomp.aai.introspection.ModelInjestor;
30 import org.openecomp.aai.introspection.ModelType;
31 import org.openecomp.aai.introspection.Version;
32 import org.openecomp.aai.serialization.engines.QueryStyle;
33 import org.openecomp.aai.serialization.engines.TitanDBEngine;
34 import org.openecomp.aai.serialization.engines.TransactionalGraphEngine;
36 import javax.ws.rs.core.UriBuilder;
37 import javax.xml.bind.JAXBException;
38 import java.io.UnsupportedEncodingException;
41 import static org.junit.Assert.assertEquals;
45 public class LegacyQueryTest extends AAISetup {
47 private ModelInjestor injestor = ModelInjestor.getInstance();
49 private TransactionalGraphEngine dbEngine =
50 new TitanDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
51 LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8),
53 private final Version version = Version.v8;
54 private DynamicJAXBContext context = injestor.getContextForVersion(version);
60 * @throws JAXBException the JAXB exception
61 * @throws UnsupportedEncodingException the unsupported encoding exception
62 * @throws AAIException the AAI exception
65 public void parentQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
67 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1").build();
69 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
72 ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
74 "gremlin query should be " + expected,
76 query.getQueryBuilder().getQuery());
78 "parent gremlin query should be equal to normal query",
80 query.getQueryBuilder().getParentQuery().getQuery());
82 "result type should be pserver",
84 query.getResultType());
91 * @throws JAXBException the JAXB exception
92 * @throws UnsupportedEncodingException the unsupported encoding exception
93 * @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
130 public void namingExceptions() throws JAXBException, UnsupportedEncodingException, AAIException {
131 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
133 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
135 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
136 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
137 + ".has('interface-id', 'key2')"
138 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
139 + ".has('cvlan-tag', 655)";
140 String expectedParent =
141 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
142 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
143 + ".has('interface-id', 'key2')";
145 "gremlin query should be " + expected,
147 query.getQueryBuilder().getQuery());
149 "parent gremlin query should be equal the query for port group",
151 query.getQueryBuilder().getParentQuery().getQuery());
153 "result type should be cvlan-tag",
155 query.getResultType());