2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.pap.test;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26 import static org.mockito.Mockito.when;
28 import java.io.BufferedReader;
29 import java.io.IOException;
30 import java.io.InputStreamReader;
31 import java.sql.SQLException;
32 import java.util.ArrayList;
33 import java.util.Collections;
34 import java.util.HashMap;
35 import java.util.List;
37 import java.util.Properties;
39 import javax.persistence.EntityManager;
40 import javax.persistence.EntityManagerFactory;
41 import javax.persistence.EntityTransaction;
42 import javax.persistence.Persistence;
43 import javax.servlet.ServletConfig;
44 import javax.servlet.ServletException;
45 import javax.servlet.ServletOutputStream;
46 import javax.servlet.http.HttpServletRequest;
47 import javax.servlet.http.HttpServletResponse;
49 import org.apache.commons.logging.Log;
50 import org.apache.commons.logging.LogFactory;
51 import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
52 import org.hibernate.SessionFactory;
53 import org.junit.After;
54 import org.junit.Before;
55 import org.junit.Test;
56 import org.mockito.Mockito;
57 import org.onap.policy.common.ia.IntegrityAuditProperties;
58 import org.onap.policy.pap.xacml.rest.XACMLPapServlet;
59 import org.onap.policy.pap.xacml.rest.controller.ActionPolicyDictionaryController;
60 import org.onap.policy.pap.xacml.rest.controller.ClosedLoopDictionaryController;
61 import org.onap.policy.pap.xacml.rest.controller.DecisionPolicyDictionaryController;
62 import org.onap.policy.pap.xacml.rest.controller.DescriptiveDictionaryController;
63 import org.onap.policy.pap.xacml.rest.controller.DictionaryController;
64 import org.onap.policy.pap.xacml.rest.controller.FirewallDictionaryController;
65 import org.onap.policy.pap.xacml.rest.controller.MicroServiceDictionaryController;
66 import org.onap.policy.pap.xacml.rest.controller.PolicyScopeDictionaryController;
67 import org.onap.policy.pap.xacml.rest.controller.SafePolicyController;
68 import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
69 import org.onap.policy.pap.xacml.rest.policycontroller.PolicyCreation;
70 import org.onap.policy.pap.xacml.rest.util.DictionaryUtils;
71 import org.onap.policy.rest.dao.CommonClassDao;
72 import org.onap.policy.rest.jpa.BRMSParamTemplate;
73 import org.onap.policy.rest.jpa.Category;
74 import org.onap.policy.rest.jpa.PolicyEditorScopes;
75 import org.onap.policy.rest.jpa.UserInfo;
76 import org.onap.policy.utils.PolicyUtils;
77 import org.onap.policy.xacml.std.pap.StdPAPPolicy;
78 import org.onap.policy.xacml.std.pap.StdPAPPolicyParams;
79 import org.springframework.mock.web.MockHttpServletResponse;
80 import org.springframework.mock.web.MockServletConfig;
81 import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
83 import com.mockrunner.mock.web.MockServletInputStream;
85 public class XACMLPAPTest {
86 private static final Log logger = LogFactory.getLog(XACMLPAPTest.class);
88 private static final String ENVIRONMENT_HEADER = "Environment";
89 private List<String> headers = new ArrayList<>();
90 private HttpServletRequest httpServletRequest;
91 private HttpServletResponse httpServletResponse;
92 private ServletOutputStream mockOutput;
93 private ServletConfig servletConfig;
94 private XACMLPapServlet pap;
95 private SessionFactory sessionFactory;
96 private CommonClassDao commonClassDao;
98 private static final String DEFAULT_DB_DRIVER = "org.h2.Driver";
99 private static final String DEFAULT_DB_USER = "sa";
100 private static final String DEFAULT_DB_PWD = "";
103 public void setUpDB() throws Exception {
104 logger.info("setUpDB: Entering");
106 Properties properties = new Properties();
107 properties.put(IntegrityAuditProperties.DB_DRIVER, XACMLPAPTest.DEFAULT_DB_DRIVER);
108 properties.put(IntegrityAuditProperties.DB_URL, "jdbc:h2:file:./sql/xacmlTest");
109 properties.put(IntegrityAuditProperties.DB_USER, XACMLPAPTest.DEFAULT_DB_USER);
110 properties.put(IntegrityAuditProperties.DB_PWD, XACMLPAPTest.DEFAULT_DB_PWD);
111 properties.put(IntegrityAuditProperties.SITE_NAME, "SiteA");
112 properties.put(IntegrityAuditProperties.NODE_TYPE, "pap");
114 //Clean the iaTest DB table for IntegrityAuditEntity entries
115 cleanDb("testPapPU", properties);
117 logger.info("setUpDB: Exiting");
120 public void cleanDb(String persistenceUnit, Properties properties) {
121 logger.debug("cleanDb: enter");
123 EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit, properties);
125 EntityManager em = emf.createEntityManager();
126 // Start a transaction
127 EntityTransaction et = em.getTransaction();
132 em.createQuery("Delete from IntegrityAuditEntity").executeUpdate();
134 // commit transaction
137 logger.debug("cleanDb: exit");
141 public void setUp() throws ServletException {
142 httpServletRequest = Mockito.mock(HttpServletRequest.class);
143 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
144 Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headers));
145 Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(headers));
147 servletConfig = Mockito.mock(MockServletConfig.class);
148 System.setProperty("com.sun.management.jmxremote.port", "9993");
149 Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers));
150 Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME"))
151 .thenReturn("src/test/resources/xacml.pap.properties");
152 pap = new XACMLPapServlet();
153 pap.init(servletConfig);
154 commonClassDao = Mockito.mock(CommonClassDao.class);
155 new DictionaryUtils(commonClassDao);
156 DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
157 Mockito.mock(DictionaryUtils.class);
161 public void testFirwallCreatePolicy() throws IOException, ServletException, SQLException {
162 httpServletRequest = Mockito.mock(HttpServletRequest.class);
164 "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"TestFwPolicyConfig\"," +
165 "\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"cloudsite:dev1a\"," +
166 "\"serviceGroups\":[{\"name\":\"SSH\",\"description\":\"Sshservice entry in servicelist\"," +
167 "\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"22\"}]," +
168 "\"addressGroups\":[{\"name\":\"test\",\"description\":\"Destination\"," +
169 "\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/12\"}]},{\"name\":\"TestServers\"," +
170 "\"description\":\"SourceTestServers for firsttesting\",\"members\":[{\"type\":\"SUBNET\"," +
171 "\"value\":\"127.0.0.1/23\"}]}],\"firewallRuleList\":[{\"position\":\"1\"," +
172 "\"ruleName\":\"FWRuleTestServerToTest\",\"fromZones\":[\"UntrustedZoneTestName\"]," +
173 "\"toZones\":[\"TrustedZoneTestName\"],\"negateSource\":false,\"negateDestination\":false," +
174 "\"sourceList\":[{\"type\":\"REFERENCE\",\"name\":\"TestServers\"}]," +
175 "\"destinationList\":[{\"type\":\"REFERENCE\",\"name\":\"Test\"}],\"sourceServices\":[]," +
176 "\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"SSH\"}],\"action\":\"accept\"," +
177 "\"description\":\"FWrule for Test source to Test destination\",\"enabled\":true," +
179 Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
180 Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
181 Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
182 Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
183 Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
184 StdPAPPolicy newPAPPolicy =
185 new StdPAPPolicy(StdPAPPolicyParams.builder()
186 .configPolicyType("Firewall Config")
188 .description("testDescription")
199 MockServletInputStream mockInput =
200 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
201 Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
205 pap.service(httpServletRequest, httpServletResponse);
207 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
208 Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
209 Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_FW_test.1.xml");
213 public void testBRMSCreatePolicy() throws IOException, ServletException, SQLException {
214 httpServletRequest = Mockito.mock(HttpServletRequest.class);
215 Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
216 Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
217 Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
218 Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
219 Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
220 Map<String, String> matchingAttributes = new HashMap<>();
221 Map<String, String> ruleAttributes = new HashMap<>();
222 ruleAttributes.put("templateName", "testPolicy");
223 ruleAttributes.put("samPoll", "5");
224 ruleAttributes.put("value", "test");
225 //Creating BRMS Param Policies from the Admin Console
226 StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder()
227 .configPolicyType("BRMS_Param")
229 .description("testing")
230 .configName("BRMS_PARAM_RULE")
233 .dynamicFieldConfigAttributes(matchingAttributes)
236 .configBodyData(null)
237 .drlRuleAndUIParams(ruleAttributes)
242 .brmsController(null)
243 .brmsDependency(null)
245 MockServletInputStream mockInput =
246 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
247 Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
252 pap.service(httpServletRequest, httpServletResponse);
254 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
255 Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
256 Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_BRMS_Param_test.1.xml");
260 public void testBRMSRawCreatePolicy() 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 Map<String, String> ruleAttributes = new HashMap<>();
268 ruleAttributes.put("value", "test");
269 StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder()
270 .configPolicyType("BRMS_Raw")
272 .description("testig description")
273 .configName("BRMS_RAW_RULE")
276 .dynamicFieldConfigAttributes(ruleAttributes)
279 .configBodyData("test")
284 MockServletInputStream mockInput =
285 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
286 Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
291 pap.service(httpServletRequest, httpServletResponse);
293 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
294 Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
295 Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_BRMS_Raw_test.1.xml");
299 public void testClosedLoopPMCreatePolicy() throws IOException, ServletException, SQLException {
300 httpServletRequest = Mockito.mock(HttpServletRequest.class);
301 Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
302 Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
303 Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
304 Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
305 Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
306 String json = "{\"test\":\"java\"}";
307 //Creating CloseLoop_Fault and Performance Metric Policies
308 StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder()
309 .configPolicyType("ClosedLoop_PM")
311 .description("testing")
315 .oldPolicyFileName(null)
316 .serviceType("Registration Failure(Trinity)")
325 MockServletInputStream mockInput =
326 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
327 Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
332 pap.service(httpServletRequest, httpServletResponse);
334 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
335 Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
336 Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_PM_test.1.xml");
340 public void testDecisonAAFPolicy() throws IOException, ServletException, SQLException {
341 httpServletRequest = Mockito.mock(HttpServletRequest.class);
342 Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
343 Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
344 Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
345 Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
346 Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision");
347 StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder()
349 .description("test rule")
351 .providerComboBox("AAF")
356 MockServletInputStream mockInput =
357 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
358 Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
362 pap.service(httpServletRequest, httpServletResponse);
364 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
365 Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
366 Mockito.verify(httpServletResponse).addHeader("policyName", "test.Decision_test.1.xml");
370 public void testDecisonGuardPolicy() throws IOException, ServletException, SQLException {
371 httpServletRequest = Mockito.mock(HttpServletRequest.class);
372 Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
373 Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
374 Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
375 Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
376 Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision");
377 Map<String, String> matchingAttributes = new HashMap<>();
378 matchingAttributes.put("actor", "test");
379 matchingAttributes.put("recipe", "restart");
380 matchingAttributes.put("targets", "test,test1");
381 matchingAttributes.put("clname", "");
382 matchingAttributes.put("limit", "1");
383 matchingAttributes.put("timeWindow", "15");
384 matchingAttributes.put("timeUnits", "minute");
385 matchingAttributes.put("guardActiveStart", "05:00");
386 matchingAttributes.put("guardActiveEnd", "10:00");
387 StdPAPPolicy newPAPPolicy =
389 new StdPAPPolicy(StdPAPPolicyParams.builder()
390 .policyName("testGuard")
391 .description("test rule")
393 .providerComboBox("GUARD_YAML")
394 .dynamicFieldConfigAttributes(matchingAttributes)
399 MockServletInputStream mockInput =
400 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
401 Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
405 pap.service(httpServletRequest, httpServletResponse);
407 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
408 Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
409 Mockito.verify(httpServletResponse).addHeader("policyName", "test.Decision_testGuard.1.xml");
413 public void testDecisonGuardMinMaxPolicy() throws IOException, ServletException, SQLException {
414 httpServletRequest = Mockito.mock(HttpServletRequest.class);
415 Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
416 Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
417 Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
418 Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
419 Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision");
420 Map<String, String> matchingAttributes = new HashMap<>();
421 matchingAttributes.put("actor", "test");
422 matchingAttributes.put("recipe", "scaleOut");
423 matchingAttributes.put("targets", "test,test1");
424 matchingAttributes.put("clname", "test");
425 matchingAttributes.put("min", "1");
426 matchingAttributes.put("max", "5");
427 matchingAttributes.put("guardActiveStart", "05:00");
428 matchingAttributes.put("guardActiveEnd", "10:00");
429 StdPAPPolicy newPAPPolicy =
432 StdPAPPolicyParams.builder().policyName("testGuard").description("test rule").onapName("PDPD")
433 .providerComboBox("GUARD_MIN_MAX").dynamicFieldConfigAttributes(matchingAttributes)
434 .editPolicy(false).domain("test").highestVersion(0).build());
435 MockServletInputStream mockInput = new MockServletInputStream(
436 PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
437 Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
441 pap.service(httpServletRequest, httpServletResponse);
443 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
444 Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
445 Mockito.verify(httpServletResponse).addHeader("policyName", "test.Decision_testGuard.1.xml");
450 public void testDecisonBLGuardPolicy() throws IOException, ServletException, SQLException {
451 httpServletRequest = Mockito.mock(HttpServletRequest.class);
452 Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
453 Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
454 Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
455 Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
456 Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision");
457 Map<String, String> matchingAttributes = new HashMap<>();
458 matchingAttributes.put("actor", "test");
459 matchingAttributes.put("recipe", "restart");
460 matchingAttributes.put("clname", "test");
461 matchingAttributes.put("guardActiveStart", "05:00");
462 matchingAttributes.put("guardActiveEnd", "10:00");
463 matchingAttributes.put("blackList", "bl1,bl2");
464 StdPAPPolicy newPAPPolicy =
465 new StdPAPPolicy(StdPAPPolicyParams.builder()
466 .policyName("testblGuard")
467 .description("test rule")
469 .providerComboBox("GUARD_BL_YAML")
470 .dynamicFieldConfigAttributes(matchingAttributes)
475 MockServletInputStream mockInput =
476 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
477 Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
481 pap.service(httpServletRequest, httpServletResponse);
483 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
484 Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
485 Mockito.verify(httpServletResponse).addHeader("policyName", "test.Decision_testblGuard.1.xml");
489 public void testConfigPolicy() throws IOException, ServletException, SQLException {
490 httpServletRequest = Mockito.mock(HttpServletRequest.class);
491 Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
492 Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
493 Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
494 Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
495 Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
496 Map<String, String> configAttributes = new HashMap<>();
497 configAttributes.put("value", "test");
498 StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder()
499 .configPolicyType("Base")
501 .description("test rule")
503 .configName("config")
504 .dynamicFieldConfigAttributes(configAttributes)
506 .configBodyData("test body")
513 .ttlDate(null).build());
514 MockServletInputStream mockInput =
515 new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
516 Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
520 pap.service(httpServletRequest, httpServletResponse);
522 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
523 Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
524 Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_test.1.xml");
527 private void setPolicyCreation() {
528 CommonClassDao commonClassDao = Mockito.mock(CommonClassDao.class);
529 PolicyCreation.setCommonClassDao(commonClassDao);
530 PolicyEditorScopes editorScope = new PolicyEditorScopes();
531 UserInfo userInfo = new UserInfo();
532 userInfo.setUserName("API");
533 userInfo.setUserLoginId("API");
534 editorScope.setScopeName("test");
535 editorScope.setUserCreatedBy(userInfo);
536 editorScope.setUserModifiedBy(userInfo);
537 Mockito.when(commonClassDao.getEntityItem(PolicyEditorScopes.class, "scopeName", "test"))
538 .thenReturn(editorScope);
539 BRMSParamTemplate template = new BRMSParamTemplate();
540 template.setRuleName("testPolicy");
541 template.setUserCreatedBy(userInfo);
542 String rule = "package com.sample;\n"
543 + "import com.sample.DroolsTest.Message;\n"
548 + "///This Rule will be generated by the UI.\n"
549 + "rule \"${policyName}.Create parameters structure\"\n"
553 + "Params params = new Params();\n"
554 + "params.setSamPoll(76);\n"
555 + "params.setValue(\"test\");\n"
556 + "insertLogical(params);\n"
558 + "rule \"Rule 1: Check parameter structure access from when/then\"\n"
560 + "$param: Params()\n"
561 + "Params($param.samPoll > 50)\n"
563 + "System.out.println(\"Firing rule 1\");\n"
564 + "System.out.println($param);\n"
566 template.setRule(rule);
567 Mockito.when(commonClassDao.getEntityItem(BRMSParamTemplate.class, "ruleName", "testPolicy"))
568 .thenReturn(template);
573 public void testClosedLoopCreateDictionary() throws IOException, SQLException, ServletException {
574 httpServletRequest = Mockito.mock(HttpServletRequest.class);
576 String json = "{\"dictionaryFields\": {\"vsclaction\": \"testRestAPI\",\"description\": \"testing create\"}}";
577 dictionaryTestSetup(false, "VSCLAction", json);
579 ClosedLoopDictionaryController.setCommonClassDao(new CommonClassDaoImpl());
580 // send Request to PAP
581 pap.service(httpServletRequest, httpServletResponse);
583 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
587 httpServletRequest = Mockito.mock(HttpServletRequest.class);
588 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
589 json = "{\"dictionaryFields\": {\"vnftype\": \"testrestAPI1\",\"description\": \"testing create\"}}";
590 dictionaryTestSetup(false, "VNFType", json);
591 // send Request to PAP
592 pap.service(httpServletRequest, httpServletResponse);
594 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
598 httpServletRequest = Mockito.mock(HttpServletRequest.class);
599 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
601 "{\"dictionaryFields\":{\"pepName\":\"testRestAPI\",\"description\":\"testing create\"," +
602 "\"attributes\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\"," +
603 "\"number\":\"test\"}]}}";
604 dictionaryTestSetup(false, "PEPOptions", json);
605 // send Request to PAP
606 pap.service(httpServletRequest, httpServletResponse);
608 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
612 httpServletRequest = Mockito.mock(HttpServletRequest.class);
613 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
615 "{\"dictionaryFields\":{\"varbindName\":\"testRestAPI\",\"varbindDescription\":\"testing\"," +
616 "\"varbindOID\":\"test\"}}";
617 dictionaryTestSetup(false, "Varbind", json);
618 // send Request to PAP
619 pap.service(httpServletRequest, httpServletResponse);
621 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
625 httpServletRequest = Mockito.mock(HttpServletRequest.class);
626 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
627 json = "{\"dictionaryFields\":{\"serviceName\":\"testRestAPI\",\"description\":\"testing\"}}";
628 dictionaryTestSetup(false, "Service", json);
629 // send Request to PAP
630 pap.service(httpServletRequest, httpServletResponse);
632 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
636 httpServletRequest = Mockito.mock(HttpServletRequest.class);
637 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
638 json = "{\"dictionaryFields\":{\"siteName\":\"testRestAPI\",\"description\":\"testing\"}}";
639 dictionaryTestSetup(false, "Site", json);
640 // send Request to PAP
641 pap.service(httpServletRequest, httpServletResponse);
643 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
647 public void testFirewallCreateDictionary() throws IOException, SQLException, ServletException {
648 httpServletRequest = Mockito.mock(HttpServletRequest.class);
649 // Check SecurityZone.
650 String json = "{\"dictionaryFields\":{\"zoneName\":\"testRestAPI\",\"zoneValue\":\"testing\"}}";
651 dictionaryTestSetup(false, "SecurityZone", json);
653 FirewallDictionaryController.setCommonClassDao(new CommonClassDaoImpl());
654 // send Request to PAP
655 pap.service(httpServletRequest, httpServletResponse);
657 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
661 httpServletRequest = Mockito.mock(HttpServletRequest.class);
662 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
663 json = "{\"dictionaryFields\":{\"actionName\":\"testRestAPI\",\"description\":\"test\"}}";
664 dictionaryTestSetup(false, "ActionList", json);
665 // send Request to PAP
666 pap.service(httpServletRequest, httpServletResponse);
668 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
670 // Check Protocol List.
672 httpServletRequest = Mockito.mock(HttpServletRequest.class);
673 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
674 json = "{\"dictionaryFields\":{\"protocolName\":\"testRestAPI\",\"description\":\"test\"}}";
675 dictionaryTestSetup(false, "ProtocolList", json);
676 // send Request to PAP
677 pap.service(httpServletRequest, httpServletResponse);
679 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
683 httpServletRequest = Mockito.mock(HttpServletRequest.class);
684 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
685 json = "{\"dictionaryFields\":{\"zoneName\":\"testRestAPI\",\"zoneValue\":\"test\"}}";
686 dictionaryTestSetup(false, "Zone", json);
687 // send Request to PAP
688 pap.service(httpServletRequest, httpServletResponse);
690 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
694 httpServletRequest = Mockito.mock(HttpServletRequest.class);
695 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
697 "{\"dictionaryFields\":{\"prefixListName\":\"testRestAPI\",\"prefixListValue\":\"127.0.0.1\"," +
698 "\"description\":\"testing\"}}";
699 dictionaryTestSetup(false, "PrefixList", json);
700 // send Request to PAP
701 pap.service(httpServletRequest, httpServletResponse);
703 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
705 // Check AddressGroup.
707 httpServletRequest = Mockito.mock(HttpServletRequest.class);
708 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
710 "{\"dictionaryFields\":{\"groupName\":\"testRestAPIgroup\",\"description\":\"testing\"," +
711 "\"attributes\":[{\"option\":\"testRestAPI\"}, {\"option\":\"testRestAPI\"}]}}";
712 dictionaryTestSetup(false, "AddressGroup", json);
713 // send Request to PAP
714 pap.service(httpServletRequest, httpServletResponse);
716 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
718 // Check ServiceGroup.
720 httpServletRequest = Mockito.mock(HttpServletRequest.class);
721 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
723 "{\"dictionaryFields\":{\"groupName\":\"testRestAPIServiceGroup\"," +
724 "\"attributes\":[{\"option\":\"testRestAPIservice\"}]}}";
725 dictionaryTestSetup(false, "ServiceGroup", json);
726 // send Request to PAP
727 pap.service(httpServletRequest, httpServletResponse);
729 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
731 // Check ServiceList.
733 httpServletRequest = Mockito.mock(HttpServletRequest.class);
734 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
736 "{\"dictionaryFields\":{\"serviceName\":\"testRestAPIservice\",\"serviceDescription\":\"test\"," +
737 "\"servicePorts\":\"8888\",\"transportProtocols\":[{\"option\":\"testRestAPI\"}," +
738 "{\"option\":\"testRestAPI1\"}],\"appProtocols\":[{\"option\":\"testRestAPI\"}," +
739 "{\"option\":\"testRestAPI1\"}]}}";
740 dictionaryTestSetup(false, "ServiceList", json);
741 // send Request to PAP
742 pap.service(httpServletRequest, httpServletResponse);
744 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
748 httpServletRequest = Mockito.mock(HttpServletRequest.class);
749 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
751 "{\"dictionaryFields\":{\"termName\":\"testRestAPIRule\",\"termDescription\":\"testing\"," +
752 "\"fromZoneDatas\":[{\"option\":\"testRestAPI\"}]," +
753 "\"toZoneDatas\":[{\"option\":\"testRestAPI1\"}]," +
754 "\"sourceListDatas\":[{\"option\":\"Group_testportal\"}]," +
755 "\"destinationListDatas\":[{\"option\":\"testRestAPI\"}]," +
756 "\"sourceServiceDatas\":[{\"option\":\"testRestAPIservice\"}," +
757 "{\"option\":\"testRestAPIservice1\"}]," +
758 "\"destinationServiceDatas\":[{\"option\":\"testRestAPIservice1\"}," +
759 "{\"option\":\"testportalservice2\"}],\"actionListDatas\":[{\"option\":\"testRestAPI\"}]}}";
760 dictionaryTestSetup(false, "TermList", json);
761 // send Request to PAP
762 pap.service(httpServletRequest, httpServletResponse);
764 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
768 public void testCommonCreateDictionary() throws IOException, SQLException, ServletException {
769 new DictionaryController(commonClassDao);
770 new ActionPolicyDictionaryController(commonClassDao);
771 new SafePolicyController(commonClassDao);
772 new DescriptiveDictionaryController(commonClassDao);
773 List<Object> object = new ArrayList<>();
774 object.add(new Category());
775 when(commonClassDao.getDataById(Category.class, "shortName", "resource")).thenReturn(object);
776 httpServletRequest = Mockito.mock(HttpServletRequest.class);
777 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
779 "{\"dictionaryFields\": {\"onapName\": \"testMMRestAPI1\",\"description\": \"testing update response " +
781 dictionaryTestSetup(false, "OnapName", json);
782 // send Request to PAP
783 pap.service(httpServletRequest, httpServletResponse);
785 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
787 httpServletRequest = Mockito.mock(HttpServletRequest.class);
788 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
790 "{\"dictionaryFields\": {\"xacmlId\": \"testMMRestAPI1\",\"datatypeBean\": {\"shortName\": " +
791 "\"string\"}, \"description\": \"testing update\",\"priority\": \"High\"," +
792 "\"userDataTypeValues\": [{\"attributeValues\": \"testAttr\"}, {\"attributeValues\": " +
793 "\"testAttr2\"}, {\"attributeValues\": \"testAttr3\"}]}}";
794 dictionaryTestSetup(false, "Attribute", json);
795 // send Request to PAP
796 pap.service(httpServletRequest, httpServletResponse);
798 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
801 httpServletRequest = Mockito.mock(HttpServletRequest.class);
802 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
804 "{\"dictionaryFields\":{\"attributeName\":\"TestMMrestAPI1\",\"type\":\"REST\",\"url\":\"testsomeurl" +
805 ".com\",\"method\":\"GET\",\"description\":\"test create\",\"body\":\"Testing Create\"," +
806 "\"headers\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\"," +
807 "\"number\":\"test\"}]}}";
808 dictionaryTestSetup(false, "Action", json);
809 // send Request to PAP
810 pap.service(httpServletRequest, httpServletResponse);
812 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
814 httpServletRequest = Mockito.mock(HttpServletRequest.class);
815 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
817 "{\"dictionaryFields\":{\"scopeName\":\"testMMRestAPI1\",\"description\":\"test\"," +
818 "\"attributes\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\"," +
819 "\"number\":\"test\"}]}}";
820 dictionaryTestSetup(false, "DescriptiveScope", json);
821 // send Request to PAP
822 pap.service(httpServletRequest, httpServletResponse);
824 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
826 httpServletRequest = Mockito.mock(HttpServletRequest.class);
827 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
828 json = "{\"dictionaryFields\":{\"riskName\":\"testMMrestAPI1\",\"description\":\"test\"}}";
829 dictionaryTestSetup(false, "RiskType", json);
830 // send Request to PAP
831 pap.service(httpServletRequest, httpServletResponse);
833 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
835 httpServletRequest = Mockito.mock(HttpServletRequest.class);
836 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
838 "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"message\":\"test\"," +
839 "\"riskType\":\"testMMrestAPI1\"}}";
840 dictionaryTestSetup(false, "SafePolicyWarning", json);
841 // send Request to PAP
842 pap.service(httpServletRequest, httpServletResponse);
844 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
848 public void testDecisionCreateDictionary() throws IOException, SQLException, ServletException {
849 new DecisionPolicyDictionaryController(commonClassDao);
850 httpServletRequest = Mockito.mock(HttpServletRequest.class);
851 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
853 "{\"dictionaryFields\":{\"xacmlId\":\"testMMRestAPI1\",\"datatypeBean\":{\"shortName\":\"string\"}," +
854 "\"description\":\"test\",\"priority\":\"High\"}}";
855 dictionaryTestSetup(false, "Settings", json);
856 // send Request to PAP
857 pap.service(httpServletRequest, httpServletResponse);
859 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
861 httpServletRequest = Mockito.mock(HttpServletRequest.class);
862 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
864 "{\"dictionaryFields\":{\"bbid\":\"BB1\",\"workstep\":\"1\",\"treatments\":\"Manual Handling,Abort," +
866 dictionaryTestSetup(false, "RainyDayTreatments", json);
867 // send Request to PAP
868 pap.service(httpServletRequest, httpServletResponse);
870 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
874 public void testMSCreateDictionary() throws IOException, SQLException, ServletException {
875 new MicroServiceDictionaryController(commonClassDao);
876 new PolicyScopeDictionaryController(commonClassDao);
877 httpServletRequest = Mockito.mock(HttpServletRequest.class);
878 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
879 String json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"descriptionValue\":\"test\"}}";
880 dictionaryTestSetup(false, "MicroServiceLocation", json);
881 // send Request to PAP
882 pap.service(httpServletRequest, httpServletResponse);
884 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
886 httpServletRequest = Mockito.mock(HttpServletRequest.class);
887 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
888 json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"descriptionValue\":\"test\"}}";
889 dictionaryTestSetup(false, "MicroServiceConfigName", json);
890 // send Request to PAP
891 pap.service(httpServletRequest, httpServletResponse);
893 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
895 httpServletRequest = Mockito.mock(HttpServletRequest.class);
896 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
897 json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"description\":\"test\"}}";
898 dictionaryTestSetup(false, "DCAEUUID", json);
899 // send Request to PAP
900 pap.service(httpServletRequest, httpServletResponse);
902 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
904 httpServletRequest = Mockito.mock(HttpServletRequest.class);
905 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
906 json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
907 dictionaryTestSetup(false, "PolicyScopeService", json);
908 // send Request to PAP
909 pap.service(httpServletRequest, httpServletResponse);
911 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
913 httpServletRequest = Mockito.mock(HttpServletRequest.class);
914 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
915 json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
916 dictionaryTestSetup(false, "PolicyScopeResource", json);
917 // send Request to PAP
918 pap.service(httpServletRequest, httpServletResponse);
920 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
922 httpServletRequest = Mockito.mock(HttpServletRequest.class);
923 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
924 json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
925 dictionaryTestSetup(false, "PolicyScopeType", json);
926 // send Request to PAP
927 pap.service(httpServletRequest, httpServletResponse);
929 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
931 httpServletRequest = Mockito.mock(HttpServletRequest.class);
932 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
933 json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
934 dictionaryTestSetup(false, "PolicyScopeClosedLoop", json);
935 // send Request to PAP
936 pap.service(httpServletRequest, httpServletResponse);
938 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
940 httpServletRequest = Mockito.mock(HttpServletRequest.class);
941 httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
943 "{\"dictionaryFields\":{\"groupName\":\"testMMrestAPI1\",\"description\":\"testing\"}," +
944 "\"groupPolicyScopeListData1\":{\"resource\":\"ANY\",\"type\":\"ANY\",\"service\":\"ANY\"," +
945 "\"closedloop\":\"ANY\"}}";
946 dictionaryTestSetup(false, "GroupPolicyScopeList", json);
947 // send Request to PAP
948 pap.service(httpServletRequest, httpServletResponse);
950 Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
953 private void dictionaryTestSetup(Boolean updateFlag, String dictionaryType, String json)
954 throws IOException, SQLException {
955 Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
956 Mockito.when(httpServletRequest.getHeader("ClientScope")).thenReturn("dictionaryItem");
957 Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
958 Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
960 Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("update");
962 Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
964 Mockito.when(httpServletRequest.getParameter("dictionaryType")).thenReturn(dictionaryType);
965 MockServletInputStream mockInput = new MockServletInputStream(json.getBytes());
966 Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
967 Mockito.when(httpServletRequest.getReader()).thenReturn(new BufferedReader(new InputStreamReader(mockInput)));
972 public void setDBDao() throws SQLException {
973 BasicDataSource dataSource = new BasicDataSource();
974 dataSource.setDriverClassName("org.h2.Driver");
975 // In-memory DB for testing
976 dataSource.setUrl("jdbc:h2:mem:test");
977 dataSource.setUsername("sa");
978 dataSource.setPassword("");
979 LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
980 sessionBuilder.scanPackages("org.onap.*", "com.*");
982 Properties properties = new Properties();
983 properties.put("hibernate.show_sql", "false");
984 properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
985 properties.put("hibernate.hbm2ddl.auto", "drop");
986 properties.put("hibernate.hbm2ddl.auto", "create");
988 sessionBuilder.addProperties(properties);
989 sessionFactory = sessionBuilder.buildSessionFactory();
991 // Set up dao with SessionFactory
992 CommonClassDaoImpl.setSessionfactory(sessionFactory);
993 PolicyCreation.setCommonClassDao(new CommonClassDaoImpl());
997 public void getDictionary() throws ServletException, IOException {
998 String[] dictionarys = new String[]{"Attribute", "OnapName", "Action", "BRMSParamTemplate", "VSCLAction"
999 , "VNFType", "PEPOptions", "Varbind", "Service", "Site", "Settings", "RainyDayTreatments",
1000 "DescriptiveScope", "ActionList", "ProtocolList", "Zone", "SecurityZone",
1001 "PrefixList", "AddressGroup", "ServiceGroup", "ServiceList", "TermList",
1002 "MicroServiceLocation", "MicroServiceConfigName", "DCAEUUID", "MicroServiceModels",
1003 "PolicyScopeService", "PolicyScopeResource", "PolicyScopeType", "PolicyScopeClosedLoop",
1004 "GroupPolicyScopeList", "RiskType", "SafePolicyWarning", "MicroServiceDictionary"};
1005 for (String dictionary : dictionarys) {
1006 httpServletRequest = Mockito.mock(HttpServletRequest.class);
1007 httpServletResponse = new MockHttpServletResponse();
1008 Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
1009 Mockito.when(httpServletRequest.getMethod()).thenReturn("GET");
1010 Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
1011 Mockito.when(httpServletRequest.getParameter("dictionaryType")).thenReturn(dictionary);
1012 pap.service(httpServletRequest, httpServletResponse);
1013 assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus());
1018 public void testDummy() throws ServletException, IOException {
1020 Mockito.when(httpServletRequest.getMethod()).thenReturn("POST");
1021 mockOutput = Mockito.mock(ServletOutputStream.class);
1024 Mockito.when(httpServletResponse.getOutputStream()).thenReturn(mockOutput);
1025 } catch (IOException e) {
1030 pap.service(httpServletRequest, httpServletResponse);
1032 } catch (Exception e) {
1038 public void destroy() {
1039 if (sessionFactory != null) {
1040 sessionFactory.close();