2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.rest.search;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.Matchers.any;
26 import static org.mockito.Mockito.when;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
33 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
34 import org.apache.tinkerpop.gremlin.structure.Graph;
35 import org.apache.tinkerpop.gremlin.structure.Vertex;
36 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
37 import org.mockito.Mock;
38 import org.mockito.MockitoAnnotations;
39 import org.onap.aai.exceptions.AAIException;
40 import org.onap.aai.introspection.Loader;
41 import org.onap.aai.introspection.LoaderFactory;
42 import org.onap.aai.introspection.ModelType;
43 import org.onap.aai.introspection.Version;
44 import org.onap.aai.query.builder.GremlinTraversal;
45 import org.onap.aai.serialization.db.EdgeRules;
46 import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException;
47 import org.onap.aai.serialization.engines.QueryStyle;
48 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
50 public abstract class QueryTest {
52 protected Graph graph;
53 private GremlinServerSingleton gremlinServerSingleton;
54 private GremlinGroovyShellSingleton shell;
55 @Mock private TransactionalGraphEngine dbEngine;
56 protected final List<Vertex> expectedResult = new ArrayList<>();
57 protected final EdgeRules rules = EdgeRules.getInstance();
58 protected Loader loader;
60 public QueryTest() throws AAIException, NoEdgeRuleFoundException {
63 public void setUp() throws AAIException, NoEdgeRuleFoundException {
64 System.setProperty("AJSC_HOME", ".");
65 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
66 MockitoAnnotations.initMocks(this);
67 graph = TinkerGraph.open();
69 gremlinServerSingleton = GremlinServerSingleton.getInstance();
70 shell = GremlinGroovyShellSingleton.getInstance();
71 loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.getLatest());
76 String query = gremlinServerSingleton.getStoredQueryFromConfig(getQueryName());
77 Map<String, Object> params = new HashMap<>();
79 when(dbEngine.getQueryBuilder(any(QueryStyle.class))).thenReturn(new GremlinTraversal<>(loader, graph.traversal()));
80 query = GroovyQueryBuilderSingleton.getInstance().executeTraversal(dbEngine, query, params);
82 GraphTraversal<Vertex, Vertex> g = graph.traversal().V();
85 GraphTraversal<Vertex, Vertex> result = (GraphTraversal<Vertex, Vertex>)shell.executeTraversal(query, params);
87 List<Vertex> vertices = result.toList();
88 assertTrue("all vertices found", vertices.containsAll(expectedResult) && expectedResult.containsAll(vertices));
92 protected abstract void createGraph() throws AAIException, NoEdgeRuleFoundException;
94 protected abstract String getQueryName();
96 protected abstract void addStartNode(GraphTraversal<Vertex, Vertex> g);
98 protected abstract void addParam(Map<String, Object> params);