6a3a9dc8d5fca07376ba540fa97a74121a70f871
[policy/engine.git] / ONAP-PAP-REST / src / test / java / org / onap / policy / pap / test / XACMLPAPTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
4  * ================================================================================
5  * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.pap.test;
23
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26 import static org.mockito.Mockito.when;
27 import com.mockrunner.mock.web.MockServletInputStream;
28 import java.io.BufferedReader;
29 import java.io.IOException;
30 import java.io.InputStreamReader;
31 import java.sql.SQLException;
32 import java.util.ArrayList;
33 import java.util.Collections;
34 import java.util.HashMap;
35 import java.util.List;
36 import java.util.Map;
37 import java.util.Properties;
38 import javax.servlet.ServletConfig;
39 import javax.servlet.ServletException;
40 import javax.servlet.ServletOutputStream;
41 import javax.servlet.http.HttpServletRequest;
42 import javax.servlet.http.HttpServletResponse;
43 import org.apache.commons.logging.Log;
44 import org.apache.commons.logging.LogFactory;
45 import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
46 import org.hibernate.SessionFactory;
47 import org.junit.AfterClass;
48 import org.junit.Before;
49 import org.junit.BeforeClass;
50 import org.junit.Test;
51 import org.mockito.Mockito;
52 import org.onap.policy.pap.xacml.rest.XACMLPapServlet;
53 import org.onap.policy.pap.xacml.rest.components.FirewallConfigPolicy;
54 import org.onap.policy.pap.xacml.rest.components.PolicyDBDaoTest;
55 import org.onap.policy.pap.xacml.rest.controller.ActionPolicyDictionaryController;
56 import org.onap.policy.pap.xacml.rest.controller.ClosedLoopDictionaryController;
57 import org.onap.policy.pap.xacml.rest.controller.DecisionPolicyDictionaryController;
58 import org.onap.policy.pap.xacml.rest.controller.DescriptiveDictionaryController;
59 import org.onap.policy.pap.xacml.rest.controller.DictionaryController;
60 import org.onap.policy.pap.xacml.rest.controller.FirewallDictionaryController;
61 import org.onap.policy.pap.xacml.rest.controller.MicroServiceDictionaryController;
62 import org.onap.policy.pap.xacml.rest.controller.PolicyScopeDictionaryController;
63 import org.onap.policy.pap.xacml.rest.controller.SafePolicyController;
64 import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
65 import org.onap.policy.pap.xacml.rest.policycontroller.PolicyCreation;
66 import org.onap.policy.pap.xacml.rest.util.DictionaryUtils;
67 import org.onap.policy.rest.dao.CommonClassDao;
68 import org.onap.policy.rest.jpa.BRMSParamTemplate;
69 import org.onap.policy.rest.jpa.Category;
70 import org.onap.policy.rest.jpa.PolicyEditorScopes;
71 import org.onap.policy.rest.jpa.UserInfo;
72 import org.onap.policy.utils.PolicyUtils;
73 import org.onap.policy.xacml.std.pap.StdPAPPolicy;
74 import org.onap.policy.xacml.std.pap.StdPAPPolicyParams;
75 import org.springframework.mock.web.MockHttpServletResponse;
76 import org.springframework.mock.web.MockServletConfig;
77 import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
78
79
80 public class XACMLPAPTest {
81     private static final Log logger = LogFactory.getLog(XACMLPAPTest.class);
82
83     private static final String ENVIRONMENT_HEADER = "Environment";
84     private static List<String> headers = new ArrayList<>();
85     private HttpServletRequest httpServletRequest;
86     private HttpServletResponse httpServletResponse;
87     private ServletOutputStream mockOutput;
88     private static ServletConfig servletConfig;
89     private static XACMLPapServlet pap;
90     private static SessionFactory sessionFactory;
91     private static CommonClassDao commonClassDao;
92
93     private static final String DEFAULT_DB_DRIVER = "org.h2.Driver";
94     private static final String DEFAULT_DB_USER = "sa";
95     private static final String DEFAULT_DB_PWD = "";
96
97     @BeforeClass
98     public static void beforeClassSetup() throws ServletException {
99         sessionFactory = PolicyDBDaoTest.setupH2DbDaoImpl("xacmlpaptest");
100         new FirewallConfigPolicy(new CommonClassDaoImpl());
101         new DictionaryUtils(new CommonClassDaoImpl());
102         setUp();
103     }
104
105     public static void setUp() throws ServletException {
106         servletConfig = Mockito.mock(MockServletConfig.class);
107         System.setProperty("com.sun.management.jmxremote.port", "9993");
108         Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers));
109         Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME"))
110                 .thenReturn("src/test/resources/xacml.pap.properties");
111         pap = new XACMLPapServlet();
112         pap.init(servletConfig);
113         commonClassDao = Mockito.mock(CommonClassDao.class);
114         new DictionaryUtils(commonClassDao);
115         DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
116         UserInfo user = new UserInfo();
117         user.setUserLoginId("API");
118         user.setUserName("API");
119         Mockito.when(commonClassDao.getEntityItem(UserInfo.class, "userLoginId", "API")).thenReturn(user);
120         Mockito.mock(DictionaryUtils.class);
121     }
122
123     @Before
124     public void testInit() {
125         httpServletRequest = Mockito.mock(HttpServletRequest.class);
126         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
127         Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headers));
128         Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(headers));
129         CommonClassDaoImpl.setSessionfactory(sessionFactory);
130         PolicyCreation.setCommonClassDao(new CommonClassDaoImpl());
131     }
132
133     @Test
134     public void testFirwallCreatePolicy() throws IOException, ServletException, SQLException {
135         httpServletRequest = Mockito.mock(HttpServletRequest.class);
136         String json = "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"TestFwPolicyConfig\","
137                 + "\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"cloudsite:dev1a\","
138                 + "\"serviceGroups\":[{\"name\":\"SSH\",\"description\":\"Sshservice entry in servicelist\","
139                 + "\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"22\"}],"
140                 + "\"addressGroups\":[{\"name\":\"test\",\"description\":\"Destination\","
141                 + "\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/12\"}]},{\"name\":\"TestServers\","
142                 + "\"description\":\"SourceTestServers for firsttesting\",\"members\":[{\"type\":\"SUBNET\","
143                 + "\"value\":\"127.0.0.1/23\"}]}],\"firewallRuleList\":[{\"position\":\"1\","
144                 + "\"ruleName\":\"FWRuleTestServerToTest\",\"fromZones\":[\"UntrustedZoneTestName\"],"
145                 + "\"toZones\":[\"TrustedZoneTestName\"],\"negateSource\":false,\"negateDestination\":false,"
146                 + "\"sourceList\":[{\"type\":\"REFERENCE\",\"name\":\"TestServers\"}],"
147                 + "\"destinationList\":[{\"type\":\"REFERENCE\",\"name\":\"Test\"}],\"sourceServices\":[],"
148                 + "\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"SSH\"}],\"action\":\"accept\","
149                 + "\"description\":\"FWrule for Test source to Test destination\",\"enabled\":true,"
150                 + "\"log\":true}]}";
151         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
152         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
153         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
154         Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
155         Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
156         StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder().configPolicyType("Firewall Config")
157                 .policyName("test").description("testDescription").configName("Test").editPolicy(false).domain("test")
158                 .jsonBody(json).highestVersion(0).riskLevel("5").riskType("default").guard("false").ttlDate("")
159                 .build());
160         MockServletInputStream mockInput =
161                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
162         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
163
164         pap.service(httpServletRequest, httpServletResponse);
165         Mockito.verify(httpServletResponse).addHeader("operation", "create");
166     }
167
168     @Test
169     public void testBRMSCreatePolicy() throws IOException, ServletException, SQLException {
170         httpServletRequest = Mockito.mock(HttpServletRequest.class);
171         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
172         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
173         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
174         Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
175         Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
176         Map<String, String> matchingAttributes = new HashMap<>();
177         Map<String, String> ruleAttributes = new HashMap<>();
178         ruleAttributes.put("templateName", "testPolicy");
179         ruleAttributes.put("samPoll", "5");
180         ruleAttributes.put("value", "test");
181         // Creating BRMS Param Policies from the Admin Console
182         StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder().configPolicyType("BRMS_Param")
183                 .policyName("test").description("testing").configName("BRMS_PARAM_RULE").editPolicy(false)
184                 .domain("test").dynamicFieldConfigAttributes(matchingAttributes).highestVersion(0).onapName("DROOLS")
185                 .configBodyData(null).drlRuleAndUIParams(ruleAttributes).riskLevel("5").riskType("default")
186                 .guard("false").ttlDate("").brmsController(null).brmsDependency(null).build());
187         MockServletInputStream mockInput =
188                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
189         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
190
191         setPolicyCreation();
192         pap.service(httpServletRequest, httpServletResponse);
193         Mockito.verify(httpServletResponse).addHeader("operation", "create");
194     }
195
196     @Test
197     public void testBRMSRawCreatePolicy() throws IOException, ServletException, SQLException {
198         httpServletRequest = Mockito.mock(HttpServletRequest.class);
199         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
200         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
201         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
202         Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
203         Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
204         Map<String, String> ruleAttributes = new HashMap<>();
205         ruleAttributes.put("value", "test");
206         StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder().configPolicyType("BRMS_Raw")
207                 .policyName("test").description("testig description").configName("BRMS_RAW_RULE").editPolicy(false)
208                 .domain("test").dynamicFieldConfigAttributes(ruleAttributes).highestVersion(0).onapName("DROOLS")
209                 .configBodyData("test").riskLevel("4").riskType("default").guard("false").build());
210         MockServletInputStream mockInput =
211                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
212         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
213
214         setPolicyCreation();
215         pap.service(httpServletRequest, httpServletResponse);
216         Mockito.verify(httpServletResponse).addHeader("operation", "create");
217     }
218
219     @Test
220     public void testClosedLoopPMCreatePolicy() throws IOException, ServletException, SQLException {
221         httpServletRequest = Mockito.mock(HttpServletRequest.class);
222         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
223         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
224         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
225         Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
226         Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
227         String json = "{\"test\":\"java\"}";
228         // Creating CloseLoop_Fault and Performance Metric Policies
229         StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder().configPolicyType("ClosedLoop_PM")
230                 .policyName("test").description("testing").onapName("onap").jsonBody(json).draft(false)
231                 .oldPolicyFileName(null).serviceType("Registration Failure(Trinity)").editPolicy(false).domain("test")
232                 .highestVersion(0).riskLevel(null).riskType("default").guard("true").ttlDate("").build());
233         MockServletInputStream mockInput =
234                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
235         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
236
237         setPolicyCreation();
238         pap.service(httpServletRequest, httpServletResponse);
239         Mockito.verify(httpServletResponse).addHeader("operation", "create");
240     }
241
242     @Test
243     public void testDecisonAAFPolicy() throws IOException, ServletException, SQLException {
244         httpServletRequest = Mockito.mock(HttpServletRequest.class);
245         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
246         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
247         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
248         Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
249         Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision");
250         StdPAPPolicy newPAPPolicy = new StdPAPPolicy(
251                 StdPAPPolicyParams.builder().policyName("test").description("test rule").onapName("ONAP")
252                         .providerComboBox("AAF").editPolicy(false).domain("test").highestVersion(0).build());
253         MockServletInputStream mockInput =
254                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
255         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
256
257         pap.service(httpServletRequest, httpServletResponse);
258         Mockito.verify(httpServletResponse).addHeader("operation", "create");
259     }
260
261     @Test
262     public void testDecisonGuardPolicy() throws IOException, ServletException, SQLException {
263         httpServletRequest = Mockito.mock(HttpServletRequest.class);
264         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
265         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
266         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
267         Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
268         Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision");
269         Map<String, String> matchingAttributes = new HashMap<>();
270         matchingAttributes.put("actor", "test");
271         matchingAttributes.put("recipe", "restart");
272         matchingAttributes.put("targets", "test,test1");
273         matchingAttributes.put("clname", "");
274         matchingAttributes.put("limit", "1");
275         matchingAttributes.put("timeWindow", "15");
276         matchingAttributes.put("timeUnits", "minute");
277         matchingAttributes.put("guardActiveStart", "05:00");
278         matchingAttributes.put("guardActiveEnd", "10:00");
279         StdPAPPolicy newPAPPolicy = new StdPAPPolicy(
280                 StdPAPPolicyParams.builder().policyName("testGuard").description("test rule").onapName("PDPD")
281                         .providerComboBox("GUARD_YAML").dynamicFieldConfigAttributes(matchingAttributes)
282                         .editPolicy(false).domain("test").highestVersion(0).build());
283         MockServletInputStream mockInput =
284                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
285         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
286
287         pap.service(httpServletRequest, httpServletResponse);
288         Mockito.verify(httpServletResponse).addHeader("operation", "create");
289     }
290
291     @Test
292     public void testDecisonGuardMinMaxPolicy() throws IOException, ServletException, SQLException {
293         httpServletRequest = Mockito.mock(HttpServletRequest.class);
294         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
295         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
296         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
297         Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
298         Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision");
299         Map<String, String> matchingAttributes = new HashMap<>();
300         matchingAttributes.put("actor", "test");
301         matchingAttributes.put("recipe", "scaleOut");
302         matchingAttributes.put("targets", "test,test1");
303         matchingAttributes.put("clname", "test");
304         matchingAttributes.put("min", "1");
305         matchingAttributes.put("max", "5");
306         matchingAttributes.put("guardActiveStart", "05:00");
307         matchingAttributes.put("guardActiveEnd", "10:00");
308         StdPAPPolicy newPAPPolicy =
309
310                 new StdPAPPolicy(
311                         StdPAPPolicyParams.builder().policyName("testGuardMinMax").description("test rule").onapName("PDPD")
312                                 .providerComboBox("GUARD_MIN_MAX").dynamicFieldConfigAttributes(matchingAttributes)
313                                 .editPolicy(false).domain("test").highestVersion(0).build());
314         MockServletInputStream mockInput =
315                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
316         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
317
318         pap.service(httpServletRequest, httpServletResponse);
319         Mockito.verify(httpServletResponse).addHeader("operation", "create");
320     }
321
322
323     @Test
324     public void testDecisonBLGuardPolicy() throws IOException, ServletException, SQLException {
325         httpServletRequest = Mockito.mock(HttpServletRequest.class);
326         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
327         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
328         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
329         Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
330         Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision");
331         Map<String, String> matchingAttributes = new HashMap<>();
332         matchingAttributes.put("actor", "test");
333         matchingAttributes.put("recipe", "restart");
334         matchingAttributes.put("clname", "test");
335         matchingAttributes.put("guardActiveStart", "05:00");
336         matchingAttributes.put("guardActiveEnd", "10:00");
337         matchingAttributes.put("blackList", "bl1,bl2");
338         StdPAPPolicy newPAPPolicy = new StdPAPPolicy(
339                 StdPAPPolicyParams.builder().policyName("testblGuard").description("test rule").onapName("PDPD")
340                         .providerComboBox("GUARD_BL_YAML").dynamicFieldConfigAttributes(matchingAttributes)
341                         .editPolicy(false).domain("test").highestVersion(0).build());
342         MockServletInputStream mockInput =
343                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
344         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
345
346         pap.service(httpServletRequest, httpServletResponse);
347         Mockito.verify(httpServletResponse).addHeader("operation", "create");
348     }
349
350     @Test
351     public void testConfigPolicy() throws IOException, ServletException, SQLException {
352         httpServletRequest = Mockito.mock(HttpServletRequest.class);
353         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
354         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
355         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
356         Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
357         Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
358         Map<String, String> configAttributes = new HashMap<>();
359         configAttributes.put("value", "test");
360         StdPAPPolicy newPAPPolicy = new StdPAPPolicy(
361                 StdPAPPolicyParams.builder().configPolicyType("Base").policyName("test").description("test rule")
362                         .onapName("TEST").configName("config").dynamicFieldConfigAttributes(configAttributes)
363                         .configType("OTHER").configBodyData("test body").editPolicy(false).domain("test")
364                         .highestVersion(0).riskLevel("5").riskType("default").guard("false").ttlDate(null).build());
365         MockServletInputStream mockInput =
366                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
367         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
368
369         pap.service(httpServletRequest, httpServletResponse);
370         Mockito.verify(httpServletResponse).addHeader("operation", "create");
371     }
372
373     private void setPolicyCreation() {
374         CommonClassDao commonClassDao = Mockito.mock(CommonClassDao.class);
375         PolicyCreation.setCommonClassDao(commonClassDao);
376         PolicyEditorScopes editorScope = new PolicyEditorScopes();
377         UserInfo userInfo = new UserInfo();
378         userInfo.setUserName("API");
379         userInfo.setUserLoginId("API");
380         editorScope.setScopeName("test");
381         editorScope.setUserCreatedBy(userInfo);
382         editorScope.setUserModifiedBy(userInfo);
383         Mockito.when(commonClassDao.getEntityItem(PolicyEditorScopes.class, "scopeName", "test"))
384                 .thenReturn(editorScope);
385         BRMSParamTemplate template = new BRMSParamTemplate();
386         template.setRuleName("testPolicy");
387         template.setUserCreatedBy(userInfo);
388         String rule = "package com.sample;\n" + "import com.sample.DroolsTest.Message;\n" + "declare Params\n"
389                 + "samPoll : int\n" + "value : String\n" + "end\n" + "///This Rule will be generated by the UI.\n"
390                 + "rule \"${policyName}.Create parameters structure\"\n" + "salience 1000  \n" + "when\n" + "then\n"
391                 + "Params params = new Params();\n" + "params.setSamPoll(76);\n" + "params.setValue(\"test\");\n"
392                 + "insertLogical(params);\n" + "end\n"
393                 + "rule \"Rule 1: Check parameter structure access from when/then\"\n" + "when\n" + "$param: Params()\n"
394                 + "Params($param.samPoll > 50)\n" + "then\n" + "System.out.println(\"Firing rule 1\");\n"
395                 + "System.out.println($param);\n" + "end\n";
396         template.setRule(rule);
397         Mockito.when(commonClassDao.getEntityItem(BRMSParamTemplate.class, "ruleName", "testPolicy"))
398                 .thenReturn(template);
399
400     }
401
402     @Test
403     public void testClosedLoopCreateDictionary() throws IOException, SQLException, ServletException {
404         httpServletRequest = Mockito.mock(HttpServletRequest.class);
405         // Check VSCLAction.
406         String json = "{\"dictionaryFields\": {\"vsclaction\": \"testRestAPI\",\"description\": \"testing create\"}}";
407         dictionaryTestSetup(false, "VSCLAction", json);
408         // set DBDao
409         ClosedLoopDictionaryController.setCommonClassDao(new CommonClassDaoImpl());
410         // send Request to PAP
411         pap.service(httpServletRequest, httpServletResponse);
412         // Verify
413         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
414         //
415         // Check VNFType
416         //
417         httpServletRequest = Mockito.mock(HttpServletRequest.class);
418         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
419         json = "{\"dictionaryFields\": {\"vnftype\": \"testrestAPI1\",\"description\": \"testing create\"}}";
420         dictionaryTestSetup(false, "VNFType", json);
421         // send Request to PAP
422         pap.service(httpServletRequest, httpServletResponse);
423         // Verify
424         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
425         //
426         // Check PEPOptions
427         //
428         httpServletRequest = Mockito.mock(HttpServletRequest.class);
429         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
430         json = "{\"dictionaryFields\":{\"pepName\":\"testRestAPI\",\"description\":\"testing create\","
431                 + "\"attributes\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\","
432                 + "\"number\":\"test\"}]}}";
433         dictionaryTestSetup(false, "PEPOptions", json);
434         // send Request to PAP
435         pap.service(httpServletRequest, httpServletResponse);
436         // Verify
437         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
438         //
439         // Check Varbind
440         //
441         httpServletRequest = Mockito.mock(HttpServletRequest.class);
442         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
443         json = "{\"dictionaryFields\":{\"varbindName\":\"testRestAPI\",\"varbindDescription\":\"testing\","
444                 + "\"varbindOID\":\"test\"}}";
445         dictionaryTestSetup(false, "Varbind", json);
446         // send Request to PAP
447         pap.service(httpServletRequest, httpServletResponse);
448         // Verify
449         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
450         //
451         // Check Service
452         //
453         httpServletRequest = Mockito.mock(HttpServletRequest.class);
454         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
455         json = "{\"dictionaryFields\":{\"serviceName\":\"testRestAPI\",\"description\":\"testing\"}}";
456         dictionaryTestSetup(false, "Service", json);
457         // send Request to PAP
458         pap.service(httpServletRequest, httpServletResponse);
459         // Verify
460         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
461         //
462         // Check Site
463         //
464         httpServletRequest = Mockito.mock(HttpServletRequest.class);
465         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
466         json = "{\"dictionaryFields\":{\"siteName\":\"testRestAPI\",\"description\":\"testing\"}}";
467         dictionaryTestSetup(false, "Site", json);
468         // send Request to PAP
469         pap.service(httpServletRequest, httpServletResponse);
470         // Verify
471         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
472     }
473
474     @Test
475     public void testFirewallCreateDictionary() throws IOException, SQLException, ServletException {
476         httpServletRequest = Mockito.mock(HttpServletRequest.class);
477         // Check SecurityZone.
478         String json = "{\"dictionaryFields\":{\"zoneName\":\"testRestAPI\",\"zoneValue\":\"testing\"}}";
479         dictionaryTestSetup(false, "SecurityZone", json);
480         // set DBDao
481         FirewallDictionaryController.setCommonClassDao(new CommonClassDaoImpl());
482         // send Request to PAP
483         pap.service(httpServletRequest, httpServletResponse);
484         // Verify
485         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
486         //
487         // Check Action List
488         //
489         httpServletRequest = Mockito.mock(HttpServletRequest.class);
490         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
491         json = "{\"dictionaryFields\":{\"actionName\":\"testRestAPI\",\"description\":\"test\"}}";
492         dictionaryTestSetup(false, "ActionList", json);
493         // send Request to PAP
494         pap.service(httpServletRequest, httpServletResponse);
495         // Verify
496         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
497         //
498         // Check Protocol List.
499         //
500         httpServletRequest = Mockito.mock(HttpServletRequest.class);
501         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
502         json = "{\"dictionaryFields\":{\"protocolName\":\"testRestAPI\",\"description\":\"test\"}}";
503         dictionaryTestSetup(false, "ProtocolList", json);
504         // send Request to PAP
505         pap.service(httpServletRequest, httpServletResponse);
506         // Verify
507         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
508         //
509         // Check Zone.
510         //
511         httpServletRequest = Mockito.mock(HttpServletRequest.class);
512         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
513         json = "{\"dictionaryFields\":{\"zoneName\":\"testRestAPI\",\"zoneValue\":\"test\"}}";
514         dictionaryTestSetup(false, "Zone", json);
515         // send Request to PAP
516         pap.service(httpServletRequest, httpServletResponse);
517         // Verify
518         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
519         //
520         // Check PrefixList.
521         //
522         httpServletRequest = Mockito.mock(HttpServletRequest.class);
523         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
524         json = "{\"dictionaryFields\":{\"prefixListName\":\"testRestAPI\",\"prefixListValue\":\"127.0.0.1\","
525                 + "\"description\":\"testing\"}}";
526         dictionaryTestSetup(false, "PrefixList", json);
527         // send Request to PAP
528         pap.service(httpServletRequest, httpServletResponse);
529         // Verify
530         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
531         //
532         // Check AddressGroup.
533         //
534         httpServletRequest = Mockito.mock(HttpServletRequest.class);
535         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
536         json = "{\"dictionaryFields\":{\"groupName\":\"testRestAPIgroup\",\"description\":\"testing\","
537                 + "\"attributes\":[{\"option\":\"testRestAPI\"}, {\"option\":\"testRestAPI\"}]}}";
538         dictionaryTestSetup(false, "AddressGroup", json);
539         // send Request to PAP
540         pap.service(httpServletRequest, httpServletResponse);
541         // Verify
542         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
543         //
544         // Check ServiceGroup.
545         //
546         httpServletRequest = Mockito.mock(HttpServletRequest.class);
547         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
548         json = "{\"dictionaryFields\":{\"groupName\":\"testRestAPIServiceGroup\","
549                 + "\"attributes\":[{\"option\":\"testRestAPIservice\"}]}}";
550         dictionaryTestSetup(false, "ServiceGroup", json);
551         // send Request to PAP
552         pap.service(httpServletRequest, httpServletResponse);
553         // Verify
554         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
555         //
556         // Check ServiceList.
557         //
558         httpServletRequest = Mockito.mock(HttpServletRequest.class);
559         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
560         json = "{\"dictionaryFields\":{\"serviceName\":\"testRestAPIservice\",\"serviceDescription\":\"test\","
561                 + "\"servicePorts\":\"8888\",\"transportProtocols\":[{\"option\":\"testRestAPI\"},"
562                 + "{\"option\":\"testRestAPI1\"}],\"appProtocols\":[{\"option\":\"testRestAPI\"},"
563                 + "{\"option\":\"testRestAPI1\"}]}}";
564         dictionaryTestSetup(false, "ServiceList", json);
565         // send Request to PAP
566         pap.service(httpServletRequest, httpServletResponse);
567         // Verify
568         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
569         //
570         // Check TermList.
571         //
572         httpServletRequest = Mockito.mock(HttpServletRequest.class);
573         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
574         json = "{\"dictionaryFields\":{\"termName\":\"testRestAPIRule\",\"termDescription\":\"testing\","
575                 + "\"fromZoneDatas\":[{\"option\":\"testRestAPI\"}],"
576                 + "\"toZoneDatas\":[{\"option\":\"testRestAPI1\"}],"
577                 + "\"sourceListDatas\":[{\"option\":\"Group_testportal\"}],"
578                 + "\"destinationListDatas\":[{\"option\":\"testRestAPI\"}],"
579                 + "\"sourceServiceDatas\":[{\"option\":\"testRestAPIservice\"},"
580                 + "{\"option\":\"testRestAPIservice1\"}],"
581                 + "\"destinationServiceDatas\":[{\"option\":\"testRestAPIservice1\"},"
582                 + "{\"option\":\"testportalservice2\"}],\"actionListDatas\":[{\"option\":\"testRestAPI\"}]}}";
583         dictionaryTestSetup(false, "TermList", json);
584         // send Request to PAP
585         pap.service(httpServletRequest, httpServletResponse);
586         // Verify
587         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
588     }
589
590     @Test
591     public void testCommonCreateDictionary() throws IOException, SQLException, ServletException {
592         new DictionaryController(commonClassDao);
593         new ActionPolicyDictionaryController(commonClassDao);
594         new SafePolicyController(commonClassDao);
595         new DescriptiveDictionaryController(commonClassDao);
596         List<Object> object = new ArrayList<>();
597         object.add(new Category());
598         when(commonClassDao.getDataById(Category.class, "shortName", "resource")).thenReturn(object);
599         httpServletRequest = Mockito.mock(HttpServletRequest.class);
600         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
601         String json =
602                 "{\"dictionaryFields\": {\"onapName\": \"testMMRestAPI1\",\"description\": \"testing update response "
603                         + "message\"}}";
604         dictionaryTestSetup(false, "OnapName", json);
605         // send Request to PAP
606         pap.service(httpServletRequest, httpServletResponse);
607         // Verify
608         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
609
610         httpServletRequest = Mockito.mock(HttpServletRequest.class);
611         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
612         json = "{\"dictionaryFields\": {\"xacmlId\": \"testMMRestAPI1\",\"datatypeBean\": {\"shortName\": "
613                 + "\"string\"}, \"description\": \"testing update\",\"priority\": \"High\","
614                 + "\"userDataTypeValues\": [{\"attributeValues\": \"testAttr\"}, {\"attributeValues\": "
615                 + "\"testAttr2\"}, {\"attributeValues\": \"testAttr3\"}]}}";
616         dictionaryTestSetup(false, "Attribute", json);
617         // send Request to PAP
618         pap.service(httpServletRequest, httpServletResponse);
619         // Verify
620         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
621
622
623         httpServletRequest = Mockito.mock(HttpServletRequest.class);
624         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
625         json = "{\"dictionaryFields\":{\"attributeName\":\"TestMMrestAPI1\",\"type\":\"REST\",\"url\":\"testsomeurl"
626                 + ".com\",\"method\":\"GET\",\"description\":\"test create\",\"body\":\"Testing Create\","
627                 + "\"headers\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\","
628                 + "\"number\":\"test\"}]}}";
629         dictionaryTestSetup(false, "Action", json);
630         // send Request to PAP
631         pap.service(httpServletRequest, httpServletResponse);
632         // Verify
633         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
634
635         httpServletRequest = Mockito.mock(HttpServletRequest.class);
636         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
637         json = "{\"dictionaryFields\":{\"scopeName\":\"testMMRestAPI1\",\"description\":\"test\","
638                 + "\"attributes\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\","
639                 + "\"number\":\"test\"}]}}";
640         dictionaryTestSetup(false, "DescriptiveScope", json);
641         // send Request to PAP
642         pap.service(httpServletRequest, httpServletResponse);
643         // Verify
644         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
645
646         httpServletRequest = Mockito.mock(HttpServletRequest.class);
647         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
648         json = "{\"dictionaryFields\":{\"riskName\":\"testMMrestAPI1\",\"description\":\"test\"}}";
649         dictionaryTestSetup(false, "RiskType", json);
650         // send Request to PAP
651         pap.service(httpServletRequest, httpServletResponse);
652         // Verify
653         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
654
655         httpServletRequest = Mockito.mock(HttpServletRequest.class);
656         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
657         json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"message\":\"test\","
658                 + "\"riskType\":\"testMMrestAPI1\"}}";
659         dictionaryTestSetup(false, "SafePolicyWarning", json);
660         // send Request to PAP
661         pap.service(httpServletRequest, httpServletResponse);
662         // Verify
663         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
664     }
665
666     @Test
667     public void testDecisionCreateDictionary() throws IOException, SQLException, ServletException {
668         new DecisionPolicyDictionaryController(commonClassDao);
669         httpServletRequest = Mockito.mock(HttpServletRequest.class);
670         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
671         String json =
672                 "{\"dictionaryFields\":{\"xacmlId\":\"testMMRestAPI1\",\"datatypeBean\":{\"shortName\":\"string\"},"
673                         + "\"description\":\"test\",\"priority\":\"High\"}}";
674         dictionaryTestSetup(false, "Settings", json);
675         // send Request to PAP
676         pap.service(httpServletRequest, httpServletResponse);
677         // Verify
678         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
679
680         httpServletRequest = Mockito.mock(HttpServletRequest.class);
681         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
682         json = "{\"dictionaryFields\":{\"bbid\":\"BB1\",\"workstep\":\"1\",\"treatments\":\"Manual Handling,Abort,"
683                 + "Retry\"}}";
684         dictionaryTestSetup(false, "RainyDayTreatments", json);
685         // send Request to PAP
686         pap.service(httpServletRequest, httpServletResponse);
687         // Verify
688         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
689     }
690
691     @Test
692     public void testMSCreateDictionary() throws IOException, SQLException, ServletException {
693         new MicroServiceDictionaryController(commonClassDao);
694         new PolicyScopeDictionaryController(commonClassDao);
695         httpServletRequest = Mockito.mock(HttpServletRequest.class);
696         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
697         String json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"descriptionValue\":\"test\"}}";
698         dictionaryTestSetup(false, "MicroServiceLocation", json);
699         // send Request to PAP
700         pap.service(httpServletRequest, httpServletResponse);
701         // Verify
702         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
703
704         httpServletRequest = Mockito.mock(HttpServletRequest.class);
705         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
706         json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"descriptionValue\":\"test\"}}";
707         dictionaryTestSetup(false, "MicroServiceConfigName", json);
708         // send Request to PAP
709         pap.service(httpServletRequest, httpServletResponse);
710         // Verify
711         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
712
713         httpServletRequest = Mockito.mock(HttpServletRequest.class);
714         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
715         json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"description\":\"test\"}}";
716         dictionaryTestSetup(false, "DCAEUUID", json);
717         // send Request to PAP
718         pap.service(httpServletRequest, httpServletResponse);
719         // Verify
720         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
721
722         httpServletRequest = Mockito.mock(HttpServletRequest.class);
723         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
724         json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
725         dictionaryTestSetup(false, "PolicyScopeService", json);
726         // send Request to PAP
727         pap.service(httpServletRequest, httpServletResponse);
728         // Verify
729         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
730
731         httpServletRequest = Mockito.mock(HttpServletRequest.class);
732         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
733         json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
734         dictionaryTestSetup(false, "PolicyScopeResource", json);
735         // send Request to PAP
736         pap.service(httpServletRequest, httpServletResponse);
737         // Verify
738         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
739
740         httpServletRequest = Mockito.mock(HttpServletRequest.class);
741         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
742         json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
743         dictionaryTestSetup(false, "PolicyScopeType", json);
744         // send Request to PAP
745         pap.service(httpServletRequest, httpServletResponse);
746         // Verify
747         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
748
749         httpServletRequest = Mockito.mock(HttpServletRequest.class);
750         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
751         json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
752         dictionaryTestSetup(false, "PolicyScopeClosedLoop", json);
753         // send Request to PAP
754         pap.service(httpServletRequest, httpServletResponse);
755         // Verify
756         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
757
758         httpServletRequest = Mockito.mock(HttpServletRequest.class);
759         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
760         json = "{\"dictionaryFields\":{\"groupName\":\"testMMrestAPI1\",\"description\":\"testing\"},"
761                 + "\"groupPolicyScopeListData1\":{\"resource\":\"ANY\",\"type\":\"ANY\",\"service\":\"ANY\","
762                 + "\"closedloop\":\"ANY\"}}";
763         dictionaryTestSetup(false, "GroupPolicyScopeList", json);
764         // send Request to PAP
765         pap.service(httpServletRequest, httpServletResponse);
766         // Verify
767         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
768     }
769
770     private void dictionaryTestSetup(Boolean updateFlag, String dictionaryType, String json)
771             throws IOException, SQLException {
772         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
773         Mockito.when(httpServletRequest.getHeader("ClientScope")).thenReturn("dictionaryItem");
774         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
775         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
776         if (updateFlag) {
777             Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("update");
778         } else {
779             Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
780         }
781         Mockito.when(httpServletRequest.getParameter("dictionaryType")).thenReturn(dictionaryType);
782         MockServletInputStream mockInput = new MockServletInputStream(json.getBytes());
783         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
784         Mockito.when(httpServletRequest.getReader()).thenReturn(new BufferedReader(new InputStreamReader(mockInput)));
785     }
786
787     public void setDBDao() throws SQLException {
788         BasicDataSource dataSource = new BasicDataSource();
789         dataSource.setDriverClassName("org.h2.Driver");
790         // In-memory DB for testing
791         dataSource.setUrl("jdbc:h2:mem:test");
792         dataSource.setUsername("sa");
793         dataSource.setPassword("");
794         LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
795         sessionBuilder.scanPackages("org.onap.*", "com.*");
796
797         Properties properties = new Properties();
798         properties.put("hibernate.show_sql", "false");
799         properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
800         properties.put("hibernate.hbm2ddl.auto", "drop");
801         properties.put("hibernate.hbm2ddl.auto", "create");
802
803         sessionBuilder.addProperties(properties);
804         sessionFactory = sessionBuilder.buildSessionFactory();
805
806         // Set up dao with SessionFactory
807         CommonClassDaoImpl.setSessionfactory(sessionFactory);
808         PolicyCreation.setCommonClassDao(new CommonClassDaoImpl());
809     }
810
811     @Test
812     public void getDictionary() throws ServletException, IOException {
813         String[] dictionarys = new String[] {"Attribute", "OnapName", "Action", "BRMSParamTemplate", "VSCLAction",
814                 "VNFType", "PEPOptions", "Varbind", "Service", "Site", "Settings", "RainyDayTreatments",
815                 "DescriptiveScope", "ActionList", "ProtocolList", "Zone", "SecurityZone", "PrefixList", "AddressGroup",
816                 "ServiceGroup", "ServiceList", "TermList", "MicroServiceLocation", "MicroServiceConfigName", "DCAEUUID",
817                 "MicroServiceModels", "PolicyScopeService", "PolicyScopeResource", "PolicyScopeType",
818                 "PolicyScopeClosedLoop", "GroupPolicyScopeList", "RiskType", "SafePolicyWarning",
819                 "MicroServiceDictionary"};
820         for (String dictionary : dictionarys) {
821             httpServletRequest = Mockito.mock(HttpServletRequest.class);
822             httpServletResponse = new MockHttpServletResponse();
823             Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
824             Mockito.when(httpServletRequest.getMethod()).thenReturn("GET");
825             Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
826             Mockito.when(httpServletRequest.getParameter("dictionaryType")).thenReturn(dictionary);
827             pap.service(httpServletRequest, httpServletResponse);
828             assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus());
829         }
830     }
831
832     @Test
833     public void testDummy() throws ServletException, IOException {
834
835         Mockito.when(httpServletRequest.getMethod()).thenReturn("POST");
836         mockOutput = Mockito.mock(ServletOutputStream.class);
837
838         try {
839             Mockito.when(httpServletResponse.getOutputStream()).thenReturn(mockOutput);
840         } catch (IOException e) {
841             fail();
842         }
843
844         try {
845             pap.service(httpServletRequest, httpServletResponse);
846             assertTrue(true);
847         } catch (Exception e) {
848             fail();
849         }
850     }
851
852     @AfterClass
853     public static void destroy() {
854         if (sessionFactory != null) {
855             sessionFactory.close();
856         }
857         pap.destroy();
858     }
859 }