Merge "Modify std pap policy to use builder in constr"
[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("Firewall Config", "test", "testDescription", "Test", false, "test", json, 0,
186                         "5", "default", "false", "");
187         MockServletInputStream mockInput =
188                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
189         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
190
191         // set DBDao
192         setDBDao();
193         pap.service(httpServletRequest, httpServletResponse);
194
195         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
196         Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
197         Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_FW_test.1.xml");
198     }
199
200     @Test
201     public void testBRMSCreatePolicy() throws IOException, ServletException, SQLException {
202         httpServletRequest = Mockito.mock(HttpServletRequest.class);
203         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
204         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
205         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
206         Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
207         Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
208         Map<String, String> matchingAttributes = new HashMap<>();
209         Map<String, String> ruleAttributes = new HashMap<>();
210         ruleAttributes.put("templateName", "testPolicy");
211         ruleAttributes.put("samPoll", "5");
212         ruleAttributes.put("value", "test");
213         StdPAPPolicy newPAPPolicy = new StdPAPPolicy("BRMS_Param", "test", "testing",
214                 "BRMS_PARAM_RULE", false, "test",
215                 matchingAttributes, 0, "DROOLS",
216                 null, ruleAttributes, "5",
217                 "default", "false", "", null, null);
218         MockServletInputStream mockInput =
219                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
220         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
221
222         // set DBDao
223         setDBDao();
224         setPolicyCreation();
225         pap.service(httpServletRequest, httpServletResponse);
226
227         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
228         Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
229         Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_BRMS_Param_test.1.xml");
230     }
231
232     @Test
233     public void testBRMSRawCreatePolicy() throws IOException, ServletException, SQLException {
234         httpServletRequest = Mockito.mock(HttpServletRequest.class);
235         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
236         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
237         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
238         Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
239         Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
240         Map<String, String> ruleAttributes = new HashMap<>();
241         ruleAttributes.put("value", "test");
242         StdPAPPolicy newPAPPolicy = new StdPAPPolicy("BRMS_Raw", "test", "testig description",
243                 "BRMS_RAW_RULE", false, "test", ruleAttributes, 0, "DROOLS",
244                 "test", "4",
245                 "default", "false", null, null, null);
246         MockServletInputStream mockInput =
247                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
248         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
249
250         // set DBDao
251         setDBDao();
252         setPolicyCreation();
253         pap.service(httpServletRequest, httpServletResponse);
254
255         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
256         Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
257         Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_BRMS_Raw_test.1.xml");
258     }
259
260     @Test
261     public void testClosedLoopPMCreatePolicy() throws IOException, ServletException, SQLException {
262         httpServletRequest = Mockito.mock(HttpServletRequest.class);
263         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
264         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
265         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
266         Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
267         Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
268         String json = "{\"test\":\"java\"}";
269         StdPAPPolicy newPAPPolicy = new StdPAPPolicy("ClosedLoop_PM", "test", "testing", "onap",
270                 json, false, null, "Registration Failure(Trinity)", false, "test", 0, null,
271                 "default", "true", "");
272         MockServletInputStream mockInput =
273                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
274         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
275
276         // set DBDao
277         setDBDao();
278         setPolicyCreation();
279         pap.service(httpServletRequest, httpServletResponse);
280
281         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
282         Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
283         Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_PM_test.1.xml");
284     }
285
286     @Test
287     public void testDecisonAAFPolicy() throws IOException, ServletException, SQLException {
288         httpServletRequest = Mockito.mock(HttpServletRequest.class);
289         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
290         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
291         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
292         Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
293         Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision");
294         StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder()
295                 .policyName("test")
296                 .description("test rule")
297                 .onapName("ONAP")
298                 .providerComboBox("AAF")
299                 .editPolicy(false)
300                 .domain("test")
301                 .highestVersion(0)
302                 .build());
303         MockServletInputStream mockInput =
304                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
305         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
306
307         // set DBDao
308         setDBDao();
309         pap.service(httpServletRequest, httpServletResponse);
310
311         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
312         Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
313         Mockito.verify(httpServletResponse).addHeader("policyName", "test.Decision_test.1.xml");
314     }
315
316     @Test
317     public void testDecisonGuardPolicy() throws IOException, ServletException, SQLException {
318         httpServletRequest = Mockito.mock(HttpServletRequest.class);
319         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
320         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
321         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
322         Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
323         Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision");
324         Map<String, String> matchingAttributes = new HashMap<>();
325         matchingAttributes.put("actor", "test");
326         matchingAttributes.put("recipe", "restart");
327         matchingAttributes.put("targets", "test,test1");
328         matchingAttributes.put("clname", "");
329         matchingAttributes.put("limit", "1");
330         matchingAttributes.put("timeWindow", "15");
331         matchingAttributes.put("timeUnits", "minute");
332         matchingAttributes.put("guardActiveStart", "05:00");
333         matchingAttributes.put("guardActiveEnd", "10:00");
334         StdPAPPolicy newPAPPolicy =
335
336                 new StdPAPPolicy(StdPAPPolicyParams.builder()
337                         .policyName("testGuard")
338                         .description("test rule")
339                         .onapName("PDPD")
340                         .providerComboBox("GUARD_YAML")
341                         .dyanamicFieldConfigAttributes(matchingAttributes)
342                         .editPolicy(false)
343                         .domain("test")
344                         .highestVersion(0)
345                         .build());
346         MockServletInputStream mockInput =
347                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
348         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
349
350         // set DBDao
351         setDBDao();
352         pap.service(httpServletRequest, httpServletResponse);
353
354         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
355         Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
356         Mockito.verify(httpServletResponse).addHeader("policyName", "test.Decision_testGuard.1.xml");
357     }
358
359     @Test
360     public void testDecisonBLGuardPolicy() throws IOException, ServletException, SQLException {
361         httpServletRequest = Mockito.mock(HttpServletRequest.class);
362         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
363         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
364         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
365         Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
366         Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision");
367         Map<String, String> matchingAttributes = new HashMap<>();
368         matchingAttributes.put("actor", "test");
369         matchingAttributes.put("recipe", "restart");
370         matchingAttributes.put("clname", "test");
371         matchingAttributes.put("guardActiveStart", "05:00");
372         matchingAttributes.put("guardActiveEnd", "10:00");
373         matchingAttributes.put("blackList", "bl1,bl2");
374         StdPAPPolicy newPAPPolicy =
375                 new StdPAPPolicy(StdPAPPolicyParams.builder()
376                         .policyName("testblGuard")
377                         .description("test rule")
378                         .onapName("PDPD")
379                         .providerComboBox("GUARD_BL_YAML")
380                         .dyanamicFieldConfigAttributes(matchingAttributes)
381                         .editPolicy(false)
382                         .domain("test")
383                         .highestVersion(0)
384                         .build());
385         MockServletInputStream mockInput =
386                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
387         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
388
389         // set DBDao
390         setDBDao();
391         pap.service(httpServletRequest, httpServletResponse);
392
393         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
394         Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
395         Mockito.verify(httpServletResponse).addHeader("policyName", "test.Decision_testblGuard.1.xml");
396     }
397
398     @Test
399     public void testConfigPolicy() throws IOException, ServletException, SQLException {
400         httpServletRequest = Mockito.mock(HttpServletRequest.class);
401         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
402         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
403         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
404         Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
405         Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
406         Map<String, String> configAttributes = new HashMap<>();
407         configAttributes.put("value", "test");
408         StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder()
409                 .configPolicyType("Base")
410                 .policyName("test")
411                 .description("test rule")
412                 .onapName("TEST")
413                 .configName("config")
414                 .dyanamicFieldConfigAttributes(configAttributes)
415                 .configType("OTHER")
416                 .configBodyData("test body")
417                 .editPolicy(false)
418                 .domain("test")
419                 .highestVersion(0)
420                 .riskLevel("5")
421                 .riskType("default")
422                 .guard("false")
423                 .ttlDate(null).build());
424         MockServletInputStream mockInput =
425                 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
426         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
427
428         // set DBDao
429         setDBDao();
430         pap.service(httpServletRequest, httpServletResponse);
431
432         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
433         Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
434         Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_test.1.xml");
435     }
436
437     private void setPolicyCreation() {
438         CommonClassDao commonClassDao = Mockito.mock(CommonClassDao.class);
439         PolicyCreation.setCommonClassDao(commonClassDao);
440         PolicyEditorScopes editorScope = new PolicyEditorScopes();
441         UserInfo userInfo = new UserInfo();
442         userInfo.setUserName("API");
443         userInfo.setUserLoginId("API");
444         editorScope.setScopeName("test");
445         editorScope.setUserCreatedBy(userInfo);
446         editorScope.setUserModifiedBy(userInfo);
447         Mockito.when(commonClassDao.getEntityItem(PolicyEditorScopes.class, "scopeName", "test"))
448                 .thenReturn(editorScope);
449         BRMSParamTemplate template = new BRMSParamTemplate();
450         template.setRuleName("testPolicy");
451         template.setUserCreatedBy(userInfo);
452         String rule = "package com.sample;\n"
453                 + "import com.sample.DroolsTest.Message;\n"
454                 + "declare Params\n"
455                 + "samPoll : int\n"
456                 + "value : String\n"
457                 + "end\n"
458                 + "///This Rule will be generated by the UI.\n"
459                 + "rule \"${policyName}.Create parameters structure\"\n"
460                 + "salience 1000  \n"
461                 + "when\n"
462                 + "then\n"
463                 + "Params params = new Params();\n"
464                 + "params.setSamPoll(76);\n"
465                 + "params.setValue(\"test\");\n"
466                 + "insertLogical(params);\n"
467                 + "end\n"
468                 + "rule \"Rule 1: Check parameter structure access from when/then\"\n"
469                 + "when\n"
470                 + "$param: Params()\n"
471                 + "Params($param.samPoll > 50)\n"
472                 + "then\n"
473                 + "System.out.println(\"Firing rule 1\");\n"
474                 + "System.out.println($param);\n"
475                 + "end\n";
476         template.setRule(rule);
477         Mockito.when(commonClassDao.getEntityItem(BRMSParamTemplate.class, "ruleName", "testPolicy"))
478                 .thenReturn(template);
479
480     }
481
482     @Test
483     public void testClosedLoopCreateDictionary() throws IOException, SQLException, ServletException {
484         httpServletRequest = Mockito.mock(HttpServletRequest.class);
485         // Check VSCLAction. 
486         String json = "{\"dictionaryFields\": {\"vsclaction\": \"testRestAPI\",\"description\": \"testing create\"}}";
487         dictionaryTestSetup(false, "VSCLAction", json);
488         // set DBDao
489         ClosedLoopDictionaryController.setCommonClassDao(new CommonClassDaoImpl());
490         // send Request to PAP
491         pap.service(httpServletRequest, httpServletResponse);
492         // Verify 
493         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
494         //
495         // Check VNFType
496         //
497         httpServletRequest = Mockito.mock(HttpServletRequest.class);
498         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
499         json = "{\"dictionaryFields\": {\"vnftype\": \"testrestAPI1\",\"description\": \"testing create\"}}";
500         dictionaryTestSetup(false, "VNFType", json);
501         // send Request to PAP
502         pap.service(httpServletRequest, httpServletResponse);
503         // Verify 
504         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
505         //
506         // Check PEPOptions
507         //
508         httpServletRequest = Mockito.mock(HttpServletRequest.class);
509         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
510         json =
511                 "{\"dictionaryFields\":{\"pepName\":\"testRestAPI\",\"description\":\"testing create\"," +
512                         "\"attributes\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\"," +
513                         "\"number\":\"test\"}]}}";
514         dictionaryTestSetup(false, "PEPOptions", json);
515         // send Request to PAP
516         pap.service(httpServletRequest, httpServletResponse);
517         // Verify 
518         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
519         //
520         // Check Varbind
521         //
522         httpServletRequest = Mockito.mock(HttpServletRequest.class);
523         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
524         json =
525                 "{\"dictionaryFields\":{\"varbindName\":\"testRestAPI\",\"varbindDescription\":\"testing\"," +
526                         "\"varbindOID\":\"test\"}}";
527         dictionaryTestSetup(false, "Varbind", json);
528         // send Request to PAP
529         pap.service(httpServletRequest, httpServletResponse);
530         // Verify 
531         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
532         //
533         // Check Service
534         //
535         httpServletRequest = Mockito.mock(HttpServletRequest.class);
536         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
537         json = "{\"dictionaryFields\":{\"serviceName\":\"testRestAPI\",\"description\":\"testing\"}}";
538         dictionaryTestSetup(false, "Service", json);
539         // send Request to PAP
540         pap.service(httpServletRequest, httpServletResponse);
541         // Verify 
542         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
543         //
544         // Check Site
545         //
546         httpServletRequest = Mockito.mock(HttpServletRequest.class);
547         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
548         json = "{\"dictionaryFields\":{\"siteName\":\"testRestAPI\",\"description\":\"testing\"}}";
549         dictionaryTestSetup(false, "Site", json);
550         // send Request to PAP
551         pap.service(httpServletRequest, httpServletResponse);
552         // Verify 
553         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
554     }
555
556     @Test
557     public void testFirewallCreateDictionary() throws IOException, SQLException, ServletException {
558         httpServletRequest = Mockito.mock(HttpServletRequest.class);
559         // Check SecurityZone. 
560         String json = "{\"dictionaryFields\":{\"zoneName\":\"testRestAPI\",\"zoneValue\":\"testing\"}}";
561         dictionaryTestSetup(false, "SecurityZone", json);
562         // set DBDao
563         FirewallDictionaryController.setCommonClassDao(new CommonClassDaoImpl());
564         // send Request to PAP
565         pap.service(httpServletRequest, httpServletResponse);
566         // Verify 
567         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
568         //
569         // Check Action List
570         //
571         httpServletRequest = Mockito.mock(HttpServletRequest.class);
572         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
573         json = "{\"dictionaryFields\":{\"actionName\":\"testRestAPI\",\"description\":\"test\"}}";
574         dictionaryTestSetup(false, "ActionList", json);
575         // send Request to PAP
576         pap.service(httpServletRequest, httpServletResponse);
577         // Verify 
578         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
579         //
580         // Check Protocol List. 
581         //
582         httpServletRequest = Mockito.mock(HttpServletRequest.class);
583         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
584         json = "{\"dictionaryFields\":{\"protocolName\":\"testRestAPI\",\"description\":\"test\"}}";
585         dictionaryTestSetup(false, "ProtocolList", json);
586         // send Request to PAP
587         pap.service(httpServletRequest, httpServletResponse);
588         // Verify 
589         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
590         //
591         // Check Zone. 
592         //
593         httpServletRequest = Mockito.mock(HttpServletRequest.class);
594         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
595         json = "{\"dictionaryFields\":{\"zoneName\":\"testRestAPI\",\"zoneValue\":\"test\"}}";
596         dictionaryTestSetup(false, "Zone", json);
597         // send Request to PAP
598         pap.service(httpServletRequest, httpServletResponse);
599         // Verify 
600         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
601         //
602         // Check PrefixList. 
603         //
604         httpServletRequest = Mockito.mock(HttpServletRequest.class);
605         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
606         json =
607                 "{\"dictionaryFields\":{\"prefixListName\":\"testRestAPI\",\"prefixListValue\":\"127.0.0.1\"," +
608                         "\"description\":\"testing\"}}";
609         dictionaryTestSetup(false, "PrefixList", json);
610         // send Request to PAP
611         pap.service(httpServletRequest, httpServletResponse);
612         // Verify 
613         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
614         //
615         // Check AddressGroup. 
616         //
617         httpServletRequest = Mockito.mock(HttpServletRequest.class);
618         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
619         json =
620                 "{\"dictionaryFields\":{\"groupName\":\"testRestAPIgroup\",\"description\":\"testing\"," +
621                         "\"attributes\":[{\"option\":\"testRestAPI\"}, {\"option\":\"testRestAPI\"}]}}";
622         dictionaryTestSetup(false, "AddressGroup", json);
623         // send Request to PAP
624         pap.service(httpServletRequest, httpServletResponse);
625         // Verify 
626         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
627         //
628         // Check ServiceGroup. 
629         //
630         httpServletRequest = Mockito.mock(HttpServletRequest.class);
631         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
632         json =
633                 "{\"dictionaryFields\":{\"groupName\":\"testRestAPIServiceGroup\"," +
634                         "\"attributes\":[{\"option\":\"testRestAPIservice\"}]}}";
635         dictionaryTestSetup(false, "ServiceGroup", json);
636         // send Request to PAP
637         pap.service(httpServletRequest, httpServletResponse);
638         // Verify 
639         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
640         //
641         // Check ServiceList. 
642         //
643         httpServletRequest = Mockito.mock(HttpServletRequest.class);
644         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
645         json =
646                 "{\"dictionaryFields\":{\"serviceName\":\"testRestAPIservice\",\"serviceDescription\":\"test\"," +
647                         "\"servicePorts\":\"8888\",\"transportProtocols\":[{\"option\":\"testRestAPI\"}," +
648                         "{\"option\":\"testRestAPI1\"}],\"appProtocols\":[{\"option\":\"testRestAPI\"}," +
649                         "{\"option\":\"testRestAPI1\"}]}}";
650         dictionaryTestSetup(false, "ServiceList", json);
651         // send Request to PAP
652         pap.service(httpServletRequest, httpServletResponse);
653         // Verify 
654         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
655         //
656         // Check TermList. 
657         //
658         httpServletRequest = Mockito.mock(HttpServletRequest.class);
659         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
660         json =
661                 "{\"dictionaryFields\":{\"termName\":\"testRestAPIRule\",\"termDescription\":\"testing\"," +
662                         "\"fromZoneDatas\":[{\"option\":\"testRestAPI\"}]," +
663                         "\"toZoneDatas\":[{\"option\":\"testRestAPI1\"}]," +
664                         "\"sourceListDatas\":[{\"option\":\"Group_testportal\"}]," +
665                         "\"destinationListDatas\":[{\"option\":\"testRestAPI\"}]," +
666                         "\"sourceServiceDatas\":[{\"option\":\"testRestAPIservice\"}," +
667                         "{\"option\":\"testRestAPIservice1\"}]," +
668                         "\"destinationServiceDatas\":[{\"option\":\"testRestAPIservice1\"}," +
669                         "{\"option\":\"testportalservice2\"}],\"actionListDatas\":[{\"option\":\"testRestAPI\"}]}}";
670         dictionaryTestSetup(false, "TermList", json);
671         // send Request to PAP
672         pap.service(httpServletRequest, httpServletResponse);
673         // Verify 
674         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
675     }
676
677     @Test
678     public void testCommonCreateDictionary() throws IOException, SQLException, ServletException {
679         new DictionaryController(commonClassDao);
680         new ActionPolicyDictionaryController(commonClassDao);
681         new SafePolicyController(commonClassDao);
682         new DescriptiveDictionaryController(commonClassDao);
683         List<Object> object = new ArrayList<>();
684         object.add(new Category());
685         when(commonClassDao.getDataById(Category.class, "shortName", "resource")).thenReturn(object);
686         httpServletRequest = Mockito.mock(HttpServletRequest.class);
687         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
688         String json =
689                 "{\"dictionaryFields\": {\"onapName\": \"testMMRestAPI1\",\"description\": \"testing update response " +
690                         "message\"}}";
691         dictionaryTestSetup(false, "OnapName", json);
692         // send Request to PAP
693         pap.service(httpServletRequest, httpServletResponse);
694         // Verify
695         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
696
697         httpServletRequest = Mockito.mock(HttpServletRequest.class);
698         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
699         json =
700                 "{\"dictionaryFields\": {\"xacmlId\": \"testMMRestAPI1\",\"datatypeBean\": {\"shortName\": " +
701                         "\"string\"}, \"description\": \"testing update\",\"priority\": \"High\"," +
702                         "\"userDataTypeValues\": [{\"attributeValues\": \"testAttr\"}, {\"attributeValues\": " +
703                         "\"testAttr2\"}, {\"attributeValues\": \"testAttr3\"}]}}";
704         dictionaryTestSetup(false, "Attribute", json);
705         // send Request to PAP
706         pap.service(httpServletRequest, httpServletResponse);
707         // Verify
708         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
709
710
711         httpServletRequest = Mockito.mock(HttpServletRequest.class);
712         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
713         json =
714                 "{\"dictionaryFields\":{\"attributeName\":\"TestMMrestAPI1\",\"type\":\"REST\",\"url\":\"testsomeurl" +
715                         ".com\",\"method\":\"GET\",\"description\":\"test create\",\"body\":\"Testing Create\"," +
716                         "\"headers\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\"," +
717                         "\"number\":\"test\"}]}}";
718         dictionaryTestSetup(false, "Action", json);
719         // send Request to PAP
720         pap.service(httpServletRequest, httpServletResponse);
721         // Verify
722         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
723
724         httpServletRequest = Mockito.mock(HttpServletRequest.class);
725         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
726         json =
727                 "{\"dictionaryFields\":{\"scopeName\":\"testMMRestAPI1\",\"description\":\"test\"," +
728                         "\"attributes\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\"," +
729                         "\"number\":\"test\"}]}}";
730         dictionaryTestSetup(false, "DescriptiveScope", json);
731         // send Request to PAP
732         pap.service(httpServletRequest, httpServletResponse);
733         // Verify
734         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
735
736         httpServletRequest = Mockito.mock(HttpServletRequest.class);
737         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
738         json = "{\"dictionaryFields\":{\"riskName\":\"testMMrestAPI1\",\"description\":\"test\"}}";
739         dictionaryTestSetup(false, "RiskType", json);
740         // send Request to PAP
741         pap.service(httpServletRequest, httpServletResponse);
742         // Verify
743         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
744
745         httpServletRequest = Mockito.mock(HttpServletRequest.class);
746         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
747         json =
748                 "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"message\":\"test\"," +
749                         "\"riskType\":\"testMMrestAPI1\"}}";
750         dictionaryTestSetup(false, "SafePolicyWarning", json);
751         // send Request to PAP
752         pap.service(httpServletRequest, httpServletResponse);
753         // Verify
754         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
755     }
756
757     @Test
758     public void testDecisionCreateDictionary() throws IOException, SQLException, ServletException {
759         new DecisionPolicyDictionaryController(commonClassDao);
760         httpServletRequest = Mockito.mock(HttpServletRequest.class);
761         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
762         String json =
763                 "{\"dictionaryFields\":{\"xacmlId\":\"testMMRestAPI1\",\"datatypeBean\":{\"shortName\":\"string\"}," +
764                         "\"description\":\"test\",\"priority\":\"High\"}}";
765         dictionaryTestSetup(false, "Settings", json);
766         // send Request to PAP
767         pap.service(httpServletRequest, httpServletResponse);
768         // Verify
769         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
770
771         httpServletRequest = Mockito.mock(HttpServletRequest.class);
772         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
773         json =
774                 "{\"dictionaryFields\":{\"bbid\":\"BB1\",\"workstep\":\"1\",\"treatments\":\"Manual Handling,Abort," +
775                         "Retry\"}}";
776         dictionaryTestSetup(false, "RainyDayTreatments", json);
777         // send Request to PAP
778         pap.service(httpServletRequest, httpServletResponse);
779         // Verify
780         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
781     }
782
783     @Test
784     public void testMSCreateDictionary() throws IOException, SQLException, ServletException {
785         new MicroServiceDictionaryController(commonClassDao);
786         new PolicyScopeDictionaryController(commonClassDao);
787         httpServletRequest = Mockito.mock(HttpServletRequest.class);
788         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
789         String json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"descriptionValue\":\"test\"}}";
790         dictionaryTestSetup(false, "MicroServiceLocation", json);
791         // send Request to PAP
792         pap.service(httpServletRequest, httpServletResponse);
793         // Verify
794         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
795
796         httpServletRequest = Mockito.mock(HttpServletRequest.class);
797         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
798         json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"descriptionValue\":\"test\"}}";
799         dictionaryTestSetup(false, "MicroServiceConfigName", json);
800         // send Request to PAP
801         pap.service(httpServletRequest, httpServletResponse);
802         // Verify
803         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
804
805         httpServletRequest = Mockito.mock(HttpServletRequest.class);
806         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
807         json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"description\":\"test\"}}";
808         dictionaryTestSetup(false, "DCAEUUID", json);
809         // send Request to PAP
810         pap.service(httpServletRequest, httpServletResponse);
811         // Verify
812         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
813
814         httpServletRequest = Mockito.mock(HttpServletRequest.class);
815         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
816         json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
817         dictionaryTestSetup(false, "PolicyScopeService", json);
818         // send Request to PAP
819         pap.service(httpServletRequest, httpServletResponse);
820         // Verify
821         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
822
823         httpServletRequest = Mockito.mock(HttpServletRequest.class);
824         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
825         json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
826         dictionaryTestSetup(false, "PolicyScopeResource", json);
827         // send Request to PAP
828         pap.service(httpServletRequest, httpServletResponse);
829         // Verify
830         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
831
832         httpServletRequest = Mockito.mock(HttpServletRequest.class);
833         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
834         json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
835         dictionaryTestSetup(false, "PolicyScopeType", json);
836         // send Request to PAP
837         pap.service(httpServletRequest, httpServletResponse);
838         // Verify
839         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
840
841         httpServletRequest = Mockito.mock(HttpServletRequest.class);
842         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
843         json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
844         dictionaryTestSetup(false, "PolicyScopeClosedLoop", json);
845         // send Request to PAP
846         pap.service(httpServletRequest, httpServletResponse);
847         // Verify
848         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
849
850         httpServletRequest = Mockito.mock(HttpServletRequest.class);
851         httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
852         json =
853                 "{\"dictionaryFields\":{\"groupName\":\"testMMrestAPI1\",\"description\":\"testing\"}," +
854                         "\"groupPolicyScopeListData1\":{\"resource\":\"ANY\",\"type\":\"ANY\",\"service\":\"ANY\"," +
855                         "\"closedloop\":\"ANY\"}}";
856         dictionaryTestSetup(false, "GroupPolicyScopeList", json);
857         // send Request to PAP
858         pap.service(httpServletRequest, httpServletResponse);
859         // Verify
860         Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
861     }
862
863     private void dictionaryTestSetup(Boolean updateFlag, String dictionaryType, String json)
864             throws IOException, SQLException {
865         Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
866         Mockito.when(httpServletRequest.getHeader("ClientScope")).thenReturn("dictionaryItem");
867         Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
868         Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
869         if (updateFlag) {
870             Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("update");
871         } else {
872             Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
873         }
874         Mockito.when(httpServletRequest.getParameter("dictionaryType")).thenReturn(dictionaryType);
875         MockServletInputStream mockInput = new MockServletInputStream(json.getBytes());
876         Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
877         Mockito.when(httpServletRequest.getReader()).thenReturn(new BufferedReader(new InputStreamReader(mockInput)));
878         // set DBDao
879         setDBDao();
880     }
881
882     public void setDBDao() throws SQLException {
883         BasicDataSource dataSource = new BasicDataSource();
884         dataSource.setDriverClassName("org.h2.Driver");
885         // In-memory DB for testing
886         dataSource.setUrl("jdbc:h2:mem:test");
887         dataSource.setUsername("sa");
888         dataSource.setPassword("");
889         LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
890         sessionBuilder.scanPackages("org.onap.*", "com.*");
891
892         Properties properties = new Properties();
893         properties.put("hibernate.show_sql", "false");
894         properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
895         properties.put("hibernate.hbm2ddl.auto", "drop");
896         properties.put("hibernate.hbm2ddl.auto", "create");
897
898         sessionBuilder.addProperties(properties);
899         sessionFactory = sessionBuilder.buildSessionFactory();
900
901         // Set up dao with SessionFactory
902         CommonClassDaoImpl.setSessionfactory(sessionFactory);
903         PolicyCreation.setCommonClassDao(new CommonClassDaoImpl());
904     }
905
906     @Test
907     public void getDictionary() throws ServletException, IOException {
908         String[] dictionarys = new String[]{"Attribute", "OnapName", "Action", "BRMSParamTemplate", "VSCLAction"
909                 , "VNFType", "PEPOptions", "Varbind", "Service", "Site", "Settings", "RainyDayTreatments",
910                 "DescriptiveScope", "ActionList", "ProtocolList", "Zone", "SecurityZone",
911                 "PrefixList", "AddressGroup", "ServiceGroup", "ServiceList", "TermList",
912                 "MicroServiceLocation", "MicroServiceConfigName", "DCAEUUID", "MicroServiceModels",
913                 "PolicyScopeService", "PolicyScopeResource", "PolicyScopeType", "PolicyScopeClosedLoop",
914                 "GroupPolicyScopeList", "RiskType", "SafePolicyWarning", "MicroServiceDictionary"};
915         for (String dictionary : dictionarys) {
916             httpServletRequest = Mockito.mock(HttpServletRequest.class);
917             httpServletResponse = new MockHttpServletResponse();
918             Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
919             Mockito.when(httpServletRequest.getMethod()).thenReturn("GET");
920             Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
921             Mockito.when(httpServletRequest.getParameter("dictionaryType")).thenReturn(dictionary);
922             pap.service(httpServletRequest, httpServletResponse);
923             assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus());
924         }
925     }
926
927     @Test
928     public void testDummy() throws ServletException, IOException {
929
930         Mockito.when(httpServletRequest.getMethod()).thenReturn("POST");
931         mockOutput = Mockito.mock(ServletOutputStream.class);
932
933         try {
934             Mockito.when(httpServletResponse.getOutputStream()).thenReturn(mockOutput);
935         } catch (IOException e) {
936             fail();
937         }
938
939         try {
940             pap.service(httpServletRequest, httpServletResponse);
941             assertTrue(true);
942         } catch (Exception e) {
943             fail();
944         }
945     }
946
947     @After
948     public void destroy() {
949         if (sessionFactory != null) {
950             sessionFactory.close();
951         }
952         pap.destroy();
953     }
954 }