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
96 public void childQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
97 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1/lag-interfaces/lag-interface/key2").build();
98 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
101 ".has('hostname', 'key1').has('aai-node-type', 'pserver')"
102 + ".out('hasLAGInterface').has('aai-node-type', 'lag-interface')"
103 + ".has('interface-name', 'key2')";
104 String parentExpected =
105 ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
107 "gremlin query should be for node",
109 query.getQueryBuilder().getQuery());
111 "parent gremlin query should be for parent",
113 query.getQueryBuilder().getParentQuery().getQuery());
115 "result type should be lag-interface",
117 query.getResultType());
123 * @throws JAXBException the JAXB exception
124 * @throws UnsupportedEncodingException the unsupported encoding exception
125 * @throws AAIException the AAI exception
128 public void namingExceptions() throws JAXBException, UnsupportedEncodingException, AAIException {
129 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
131 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
133 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
134 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
135 + ".has('interface-id', 'key2')"
136 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
137 + ".has('cvlan-tag', 655)";
138 String expectedParent =
139 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
140 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
141 + ".has('interface-id', 'key2')";
143 "gremlin query should be " + expected,
145 query.getQueryBuilder().getQuery());
147 "parent gremlin query should be equal the query for port group",
149 query.getQueryBuilder().getParentQuery().getQuery());
151 "result type should be cvlan-tag",
153 query.getResultType());