+ 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}]}";
+ Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
+ Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
+ Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
+ Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
+ Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
+ StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder().configPolicyType("Firewall Config")
+ .policyName("test").description("testDescription").configName("Test").editPolicy(false).domain("test")
+ .jsonBody(json).highestVersion(0).riskLevel("5").riskType("default").guard("false").ttlDate("")
+ .build());
+ MockServletInputStream mockInput =
+ new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+ logger.info(httpServletRequest);
+ logger.info(httpServletResponse);
+ pap.service(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).addHeader("operation", "create");
+ }
+
+ @Test
+ public void testBRMSCreatePolicy() throws IOException, ServletException, SQLException {
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
+ Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
+ Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
+ Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
+ Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
+ Map<String, String> matchingAttributes = new HashMap<>();
+ Map<String, String> ruleAttributes = new HashMap<>();
+ ruleAttributes.put("templateName", "testPolicy");
+ ruleAttributes.put("samPoll", "5");
+ ruleAttributes.put("value", "test");
+ // Creating BRMS Param Policies from the Admin Console
+ StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder().configPolicyType("BRMS_Param")
+ .policyName("test").description("testing").configName("BRMS_PARAM_RULE").editPolicy(false)
+ .domain("test").dynamicFieldConfigAttributes(matchingAttributes).highestVersion(0).onapName("DROOLS")
+ .configBodyData(null).drlRuleAndUIParams(ruleAttributes).riskLevel("5").riskType("default")
+ .guard("false").ttlDate("").brmsController(null).brmsDependency(null).build());
+ MockServletInputStream mockInput =
+ new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+
+ setPolicyCreation();
+ logger.info(httpServletRequest);
+ logger.info(httpServletResponse);
+ pap.service(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).addHeader("operation", "create");
+ }
+
+ @Test
+ public void testBRMSRawCreatePolicy() throws IOException, ServletException, SQLException {
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
+ Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
+ Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
+ Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
+ Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
+ Map<String, String> ruleAttributes = new HashMap<>();
+ ruleAttributes.put("value", "test");
+ StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder().configPolicyType("BRMS_Raw")
+ .policyName("test").description("testig description").configName("BRMS_RAW_RULE").editPolicy(false)
+ .domain("test").dynamicFieldConfigAttributes(ruleAttributes).highestVersion(0).onapName("DROOLS")
+ .configBodyData("test").riskLevel("4").riskType("default").guard("false").build());
+ MockServletInputStream mockInput =
+ new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+
+ setPolicyCreation();
+ logger.info(httpServletRequest);
+ logger.info(httpServletResponse);
+ pap.service(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).addHeader("operation", "create");
+ }
+
+ @Test
+ public void testClosedLoopPMCreatePolicy() throws IOException, ServletException, SQLException {
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
+ Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
+ Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
+ Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
+ Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config");
+ String json = "{\"test\":\"java\"}";
+ // Creating CloseLoop_Fault and Performance Metric Policies
+ StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder().configPolicyType("ClosedLoop_PM")
+ .policyName("test").description("testing").onapName("onap").jsonBody(json).draft(false)
+ .oldPolicyFileName(null).serviceType("Registration Failure(Trinity)").editPolicy(false).domain("test")
+ .highestVersion(0).riskLevel(null).riskType("default").guard("true").ttlDate("").build());
+ MockServletInputStream mockInput =
+ new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+
+ setPolicyCreation();
+ logger.info(httpServletRequest);
+ logger.info(httpServletResponse);
+ pap.service(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).addHeader("operation", "create");
+ }
+
+ @Test
+ public void testDecisonAAFPolicy() throws IOException, ServletException, SQLException {
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
+ Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
+ Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
+ Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
+ Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision");
+ StdPAPPolicy newPAPPolicy = new StdPAPPolicy(
+ StdPAPPolicyParams.builder().policyName("test").description("test rule").onapName("ONAP")
+ .providerComboBox("AAF").editPolicy(false).domain("test").highestVersion(0).build());
+ MockServletInputStream mockInput =
+ new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+
+ logger.info(httpServletRequest);
+ logger.info(httpServletResponse);
+ pap.service(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).addHeader("operation", "create");
+ }
+
+ @Test
+ public void testDecisonGuardPolicy() throws IOException, ServletException, SQLException {
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
+ Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
+ Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
+ Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
+ Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision");
+ Map<String, String> matchingAttributes = new HashMap<>();
+ matchingAttributes.put("actor", "test");
+ matchingAttributes.put("recipe", "restart");
+ matchingAttributes.put("targets", "test,test1");
+ matchingAttributes.put("clname", "");
+ matchingAttributes.put("limit", "1");
+ matchingAttributes.put("timeWindow", "15");
+ matchingAttributes.put("timeUnits", "minute");
+ matchingAttributes.put("guardActiveStart", "05:00");
+ matchingAttributes.put("guardActiveEnd", "10:00");
+ StdPAPPolicy newPAPPolicy = new StdPAPPolicy(
+ StdPAPPolicyParams.builder().policyName("testGuard").description("test rule").onapName("PDPD")
+ .providerComboBox("GUARD_YAML").dynamicFieldConfigAttributes(matchingAttributes)
+ .editPolicy(false).domain("test").highestVersion(0).build());
+ MockServletInputStream mockInput =
+ new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+
+ logger.info(httpServletRequest);
+ logger.info(httpServletResponse);
+ pap.service(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).addHeader("operation", "create");
+ }
+
+ @Test
+ public void testDecisonGuardMinMaxPolicy() throws IOException, ServletException, SQLException {
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
+ Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
+ Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
+ Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
+ Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision");
+ Map<String, String> matchingAttributes = new HashMap<>();
+ matchingAttributes.put("actor", "test");
+ matchingAttributes.put("recipe", "scaleOut");
+ matchingAttributes.put("targets", "test,test1");
+ matchingAttributes.put("clname", "test");
+ matchingAttributes.put("min", "1");
+ matchingAttributes.put("max", "5");
+ matchingAttributes.put("guardActiveStart", "05:00");
+ matchingAttributes.put("guardActiveEnd", "10:00");
+ StdPAPPolicy newPAPPolicy =
+
+ new StdPAPPolicy(StdPAPPolicyParams.builder().policyName("testGuardMinMax").description("test rule")
+ .onapName("PDPD").providerComboBox("GUARD_MIN_MAX")
+ .dynamicFieldConfigAttributes(matchingAttributes).editPolicy(false).domain("test")
+ .highestVersion(0).build());
+ MockServletInputStream mockInput =
+ new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+
+ logger.info(httpServletRequest);
+ logger.info(httpServletResponse);
+ pap.service(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).addHeader("operation", "create");
+ }
+
+ @Test
+ public void testDecisonBLGuardPolicy() throws IOException, ServletException, SQLException {
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
+ Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
+ Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
+ Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
+ Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision");
+ Map<String, String> matchingAttributes = new HashMap<>();
+ matchingAttributes.put("actor", "test");
+ matchingAttributes.put("recipe", "restart");
+ matchingAttributes.put("clname", "test");
+ matchingAttributes.put("guardActiveStart", "05:00");
+ matchingAttributes.put("guardActiveEnd", "10:00");
+ matchingAttributes.put("blackList", "bl1,bl2");
+ StdPAPPolicy newPAPPolicy = new StdPAPPolicy(
+ StdPAPPolicyParams.builder().policyName("testblGuard").description("test rule").onapName("PDPD")
+ .providerComboBox("GUARD_BL_YAML").dynamicFieldConfigAttributes(matchingAttributes)
+ .editPolicy(false).domain("test").highestVersion(0).build());
+ MockServletInputStream mockInput =
+ new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+
+ logger.info(httpServletRequest);
+ logger.info(httpServletResponse);
+ pap.service(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).addHeader("operation", "create");
+ }
+
+ @Test
+ public void testConfigPolicy() throws IOException, ServletException, SQLException {
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);