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.BeforeClass;
25 import org.junit.Test;
26 import org.openecomp.aai.exceptions.AAIException;
27 import org.openecomp.aai.introspection.LoaderFactory;
28 import org.openecomp.aai.introspection.ModelInjestor;
29 import org.openecomp.aai.introspection.ModelType;
30 import org.openecomp.aai.introspection.Version;
31 import org.openecomp.aai.serialization.engines.QueryStyle;
32 import org.openecomp.aai.serialization.engines.TitanDBEngine;
33 import org.openecomp.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;
43 public class LegacyQueryTest {
44 private ModelInjestor injestor = ModelInjestor.getInstance();
45 private TransactionalGraphEngine dbEngine =
46 new TitanDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
47 LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8),
49 private final Version version = Version.v8;
50 private DynamicJAXBContext context = injestor.getContextForVersion(version);
57 public static void configure() {
58 System.setProperty("AJSC_HOME", "./src/test/resources/");
59 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
65 * @throws JAXBException the JAXB exception
66 * @throws UnsupportedEncodingException the unsupported encoding exception
67 * @throws AAIException the AAI exception
70 public void parentQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
72 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1").build();
74 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
77 ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
79 "gremlin query should be " + expected,
81 query.getQueryBuilder().getQuery());
83 "parent gremlin query should be equal to normal query",
85 query.getQueryBuilder().getParentQuery().getQuery());
87 "result type should be pserver",
89 query.getResultType());
96 * @throws JAXBException the JAXB exception
97 * @throws UnsupportedEncodingException the unsupported encoding exception
98 * @throws AAIException the AAI exception
101 public void childQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
102 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1/lag-interfaces/lag-interface/key2").build();
103 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
106 ".has('hostname', 'key1').has('aai-node-type', 'pserver')"
107 + ".in('tosca.relationships.BindsTo').has('aai-node-type', 'lag-interface')"
108 + ".has('interface-name', 'key2')";
109 String parentExpected =
110 ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
112 "parent gremlin query should be for parent",
114 query.getQueryBuilder().getParentQuery().getQuery());
116 "result type should be lag-interface",
118 query.getResultType());