Update the license for 2017-2018 license
[aai/traversal.git] / aai-traversal / src / test / java / org / onap / aai / rest / search / GetCustomQueryConfigTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.aai.rest.search;
21
22 import static org.junit.Assert.*;
23
24 import java.util.ArrayList;
25
26 import org.junit.Before;
27 import org.junit.Test;
28
29 import com.google.common.collect.Lists;
30
31 public class GetCustomQueryConfigTest {
32
33         private String configJson;
34         
35         @Before
36         public void setUp() throws Exception {
37                 System.setProperty("AJSC_HOME", ".");
38                 System.setProperty("BUNDLECONFIG_DIR", "src/main/resources");
39                 
40
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}";
45         }
46
47
48         @Test
49         public void testGetStoredQueryNameWithOptAndReqProps() {
50                 
51                 GetCustomQueryConfig getCustomQueryConfig = new GetCustomQueryConfig(configJson);
52                 CustomQueryConfig cqc = getCustomQueryConfig.getStoredQuery("queryName1");
53
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());
57
58         }
59
60         @Test
61         public void testGetStoredQueryNameWithOptProps() {
62                 
63                 GetCustomQueryConfig getCustomQueryConfig = new GetCustomQueryConfig(configJson);
64                 CustomQueryConfig cqc = getCustomQueryConfig.getStoredQuery("queryName2");
65
66                 assertEquals(Lists.newArrayList("prop5"), cqc.getQueryOptionalProperties());
67                 assertEquals(new ArrayList<String>(), cqc.getQueryRequiredProperties());
68                 assertEquals("out('bar').has('stuff','baz')", cqc.getQuery());
69
70         }
71
72         @Test
73         public void testGetStoredQueryNameWithNoProps() {
74                 
75                 GetCustomQueryConfig getCustomQueryConfig = new GetCustomQueryConfig(configJson);
76                 CustomQueryConfig cqc = getCustomQueryConfig.getStoredQuery("queryName3");
77
78                 assertEquals(new ArrayList<String>(), cqc.getQueryOptionalProperties());
79                 assertEquals(new ArrayList<String>(), cqc.getQueryRequiredProperties());
80                 assertEquals("out('bar1').has('stuff','baz1')", cqc.getQuery());
81
82         }
83 }