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