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