Consolidate PolicyRestAdapter setup
[policy/engine.git] / ONAP-PAP-REST / src / test / java / org / onap / policy / pap / xacml / rest / elk / PolicyElasticSearchControllerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
4  * ================================================================================
5  * Copyright (C) 2018-2019 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
21 package org.onap.policy.pap.xacml.rest.elk;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.when;
25
26 import java.io.BufferedReader;
27 import java.io.StringReader;
28 import java.util.ArrayList;
29 import java.util.List;
30
31 import javax.servlet.http.HttpServletRequest;
32 import javax.servlet.http.HttpServletResponse;
33
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.mockito.Mockito;
37 import org.onap.policy.pap.xacml.rest.elk.client.PolicyElasticSearchController;
38
39 public class PolicyElasticSearchControllerTest {
40
41     private PolicyElasticSearchController conroller;
42     private HttpServletRequest request = null;
43     private HttpServletResponse response = null;
44
45     @Before
46     public void setup() {
47         conroller = new PolicyElasticSearchController();
48         request = Mockito.mock(HttpServletRequest.class);
49         response = Mockito.mock(HttpServletResponse.class);
50     }
51
52     @Test
53     public void testSearchDictionary() {
54         List<String> jsonString = new ArrayList<>();
55         jsonString.add("{\"type\":\"attribute\",\"data\":{\"xacmlId\":\"Test\"}}");
56         jsonString.add("{\"type\":\"onapName\",\"data\":{\"onapName\":\"Test\"}}");
57         jsonString.add("{\"type\":\"actionPolicy\",\"data\":{\"attributeName\":\"Test\"}}");
58         jsonString.add("{\"type\":\"brmsParam\",\"data\":{\"ruleName\":\"Test\"}}");
59         jsonString.add("{\"type\":\"pepOptions\",\"data\":{\"pepName\":\"Test\"}}");
60         jsonString.add("{\"type\":\"clSite\",\"data\":{\"siteName\":\"Test\"}}");
61         jsonString.add("{\"type\":\"clService\",\"data\":{\"serviceName\":\"Test\"}}");
62         jsonString.add("{\"type\":\"clVarbind\",\"data\":{\"varbindName\":\"Test\"}}");
63         jsonString.add("{\"type\":\"clVnf\",\"data\":{\"vnftype\":\"Test\"}}");
64         jsonString.add("{\"type\":\"clVSCL\",\"data\":{\"vsclaction\":\"Test\"}}");
65         jsonString.add("{\"type\":\"decision\",\"data\":{\"xacmlId\":\"Test\"}}");
66         jsonString.add("{\"type\":\"fwTerm\",\"data\":{\"termName\":\"Test\"}}");
67         jsonString.add("{\"type\":\"msDCAEUUID\",\"data\":{\"name\":\"Test\"}}");
68         jsonString.add("{\"type\":\"msLocation\",\"data\":{\"name\":\"Test\"}}");
69         jsonString.add("{\"type\":\"msModels\",\"data\":{\"modelName\":\"Test\"}}");
70         jsonString.add("{\"type\":\"psGroupPolicy\",\"data\":{\"name\":\"Test\"}}");
71         jsonString.add("{\"type\":\"safeRisk\",\"data\":{\"name\":\"Test\"}}");
72         jsonString.add("{\"type\":\"safePolicyWarning\",\"data\":{\"name\":\"Test\"}}");
73         for (int i = 0; i < jsonString.size(); i++) {
74             try (BufferedReader br = new BufferedReader(new StringReader(jsonString.get(i)))) {
75                 when(request.getReader()).thenReturn(br);
76                 conroller.searchDictionary(request, response);
77             } catch (Exception e) {
78                 assertEquals(NullPointerException.class, e.getClass());
79             }
80         }
81     }
82 }