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