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=========================================================
21 package org.onap.aai.query.builder.optimization;
23 import java.lang.reflect.Method;
26 import javax.ws.rs.core.MultivaluedHashMap;
27 import javax.ws.rs.core.MultivaluedMap;
29 import org.apache.tinkerpop.gremlin.structure.Vertex;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.aai.query.builder.QueryBuilder;
33 import org.onap.aai.query.builder.TraversalQuery;
34 import org.onap.aai.query.builder.TraversalURIOptimizedQuery;
36 public abstract class AbstractGraphTraversalBuilderTestQueryiesToRun
37 extends AbstractGraphTraversalBuilderOptmizationTest {
39 protected static final String CLOUD_OWNER_1 = "cloud-owner-1";
40 protected static final String CLOUD_REGION_ID_1 = "cloud-region-id-1";
41 protected String tenantId;
42 protected String vserverId;
43 protected String vserverName;
44 protected String randomFromList;
47 public void config() throws Exception {
48 int tenantNum = rand.nextInt(getTenantNum());
49 tenantId = getPrefix() + "tenant-id-" + tenantNum;
50 vserverId = getPrefix() + "vserver-id-" + tenantNum + "-" + rand.nextInt(getVserverNumPerTenant());
51 vserverName = getPrefix() + "vserver-name-" + tenantNum + "-" + rand.nextInt(getVserverNumPerTenant());
53 randomFromList = RANDOM_VALUES.get(rand.nextInt(RANDOM_VALUES.size()));
56 protected abstract String getPrefix();
58 private QueryBuilder<Vertex> getQueryBuilder(OptimizeEnum optimized) {
59 if (OptimizeEnum.URI.equals(optimized)) {
60 return new TraversalURIOptimizedQuery<>(loader, g);
62 return new TraversalQuery<>(loader, g);
66 private void callTest(String methodName, int numResultsExpected) throws Exception {
67 String queryMethodName = methodName.replace("Test", "Query");
69 AbstractGraphTraversalBuilderTestQueryiesToRun.class.getMethod(queryMethodName, OptimizeEnum.class);
70 this.execute(method, numResultsExpected);
74 public void vserverTest() throws Exception {
75 String methodName = new Object() {}.getClass().getEnclosingMethod().getName();
76 callTest(methodName, 1);
79 public QueryBuilder<Vertex> vserverQuery(OptimizeEnum optimized) throws Exception {
80 URI uri = new URI(String.format(vserverUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1,
81 tenantId, vserverId));
82 return getQueryBuilder(optimized).createQueryFromURI(uri).getQueryBuilder();
86 public void vserversUnderATenantTest() throws Exception {
87 String methodName = new Object() {}.getClass().getEnclosingMethod().getName();
88 callTest(methodName, getVserverNumPerTenant());
91 public QueryBuilder<Vertex> vserversUnderATenantQuery(OptimizeEnum optimized) throws Exception {
93 String.format(tenantUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1, tenantId)
95 return getQueryBuilder(optimized).createQueryFromURI(uri).getQueryBuilder();
99 public void vserversUnderATenantWithNonIndexPropertyTest() throws Exception {
100 String methodName = new Object() {}.getClass().getEnclosingMethod().getName();
101 callTest(methodName, Integer.MIN_VALUE);
104 public QueryBuilder<Vertex> vserversUnderATenantWithNonIndexPropertyQuery(OptimizeEnum optimized) throws Exception {
106 String.format(tenantUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1, tenantId)
108 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
109 map.putSingle(VSERVER_SELFLINK, randomFromList);
110 return getQueryBuilder(optimized).createQueryFromURI(uri, map).getQueryBuilder();
114 public void vserversUnderATenantWithIndexPropertyWhereValueIsInMultipleTest() throws Exception {
115 String methodName = new Object() {}.getClass().getEnclosingMethod().getName();
116 callTest(methodName, Integer.MIN_VALUE);
119 public QueryBuilder<Vertex> vserversUnderATenantWithIndexPropertyWhereValueIsInMultipleQuery(OptimizeEnum optimized)
122 String.format(tenantUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1, tenantId)
124 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
125 map.putSingle(PROV_STATUS, randomFromList);
126 return getQueryBuilder(optimized).createQueryFromURI(uri, map).getQueryBuilder();
130 public void vserversUnderATenantWithIndexPropertyWhereValueIsSemiUniqueTest() throws Exception {
131 String methodName = new Object() {}.getClass().getEnclosingMethod().getName();
132 callTest(methodName, Integer.MIN_VALUE);
135 public QueryBuilder<Vertex> vserversUnderATenantWithIndexPropertyWhereValueIsSemiUniqueQuery(OptimizeEnum optimized)
138 String.format(tenantUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1, tenantId)
140 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
141 map.putSingle(VSERVER_NAME, vserverName);
142 return getQueryBuilder(optimized).createQueryFromURI(uri, map).getQueryBuilder();
147 public void nonExistentVserverTest() throws Exception {
148 String methodName = new Object() {}.getClass().getEnclosingMethod().getName();
149 callTest(methodName, 0);
152 public QueryBuilder<Vertex> nonExistentVserverQuery(OptimizeEnum optimized) throws Exception {
153 URI uri = new URI(String.format(vserverUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1,
154 tenantId, "does-not-exist"));
155 return getQueryBuilder(optimized).createQueryFromURI(uri).getQueryBuilder();
159 public void vserverWithNonExistentTenantTest() throws Exception {
160 String methodName = new Object() {}.getClass().getEnclosingMethod().getName();
161 callTest(methodName, 0);
164 public QueryBuilder<Vertex> vserverWithNonExistentTenantQuery(OptimizeEnum optimized) throws Exception {
165 URI uri = new URI(String.format(vserverUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1,
166 "does-not-exist", vserverId));
167 return getQueryBuilder(optimized).createQueryFromURI(uri).getQueryBuilder();
171 public void vserverWithValidQueryParameterTest() throws Exception {
172 String methodName = new Object() {}.getClass().getEnclosingMethod().getName();
173 callTest(methodName, 1);
176 public QueryBuilder<Vertex> vserverWithValidQueryParameterQuery(OptimizeEnum optimized) throws Exception {
177 URI uri = new URI(String.format(vserverUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1,
178 tenantId, vserverId));
179 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
180 map.putSingle("vserver-name2", "someName");
181 return getQueryBuilder(optimized).createQueryFromURI(uri, map).getQueryBuilder();
185 public void cloudRegionTest() throws Exception {
186 String methodName = new Object() {}.getClass().getEnclosingMethod().getName();
187 callTest(methodName, 1);
190 public QueryBuilder<Vertex> cloudRegionQuery(OptimizeEnum optimized) throws Exception {
191 URI uri = new URI(String.format(crUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1));
192 MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
193 map.putSingle("in-maint", "false");
194 return getQueryBuilder(optimized).createQueryFromURI(uri, map).getQueryBuilder();