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