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=========================================================
20 package org.onap.aai.rest.search;
22 import static org.junit.Assert.*;
24 import java.util.ArrayList;
26 import org.junit.Before;
27 import org.junit.Test;
29 import com.google.common.collect.Lists;
31 public class GetCustomQueryConfigTest {
33 private String configJson;
36 public void setUp() throws Exception {
37 System.setProperty("AJSC_HOME", ".");
38 System.setProperty("BUNDLECONFIG_DIR", "src/main/resources");
41 configJson = "{\n \"stored-queries\": [{\n" +
42 " \"queryName1\": {\n \"query\": {\n \"required-properties\": [\"prop1\", \"prop2\"],\n \"optional-properties\": [\"prop3\", \"prop4\"]\n },\n \"stored-query\": \"out('blah').has('something','foo')\"\n }\n }, {\n" +
43 " \"queryName2\": {\n \"query\": {\n \"optional-properties\": [\"prop5\"]\n },\n \"stored-query\": \"out('bar').has('stuff','baz')\"\n }\n }, {\n" +
44 " \"queryName3\": {\n \"stored-query\": \"out('bar1').has('stuff','baz1')\"\n }\n }]\n}";
49 public void testGetStoredQueryNameWithOptAndReqProps() {
51 GetCustomQueryConfig getCustomQueryConfig = new GetCustomQueryConfig(configJson);
52 CustomQueryConfig cqc = getCustomQueryConfig.getStoredQuery("queryName1");
54 assertEquals(Lists.newArrayList("prop3", "prop4"), cqc.getQueryOptionalProperties());
55 assertEquals(Lists.newArrayList("prop1", "prop2"), cqc.getQueryRequiredProperties());
56 assertEquals("out('blah').has('something','foo')", cqc.getQuery());
61 public void testGetStoredQueryNameWithOptProps() {
63 GetCustomQueryConfig getCustomQueryConfig = new GetCustomQueryConfig(configJson);
64 CustomQueryConfig cqc = getCustomQueryConfig.getStoredQuery("queryName2");
66 assertEquals(Lists.newArrayList("prop5"), cqc.getQueryOptionalProperties());
67 assertEquals(new ArrayList<String>(), cqc.getQueryRequiredProperties());
68 assertEquals("out('bar').has('stuff','baz')", cqc.getQuery());
73 public void testGetStoredQueryNameWithNoProps() {
75 GetCustomQueryConfig getCustomQueryConfig = new GetCustomQueryConfig(configJson);
76 CustomQueryConfig cqc = getCustomQueryConfig.getStoredQuery("queryName3");
78 assertEquals(new ArrayList<String>(), cqc.getQueryOptionalProperties());
79 assertEquals(new ArrayList<String>(), cqc.getQueryRequiredProperties());
80 assertEquals("out('bar1').has('stuff','baz1')", cqc.getQuery());