Merge "String literal comparision on left side"
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java
index eae3e79..d870ca8 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java
@@ -63,6 +63,7 @@
import org.onap.policy.xacml.std.pip.engines.aaf.AAFEngine;
import org.onap.policy.xacml.util.XACMLPolicyScanner;
+import com.att.research.xacml.api.XACML3;
import com.att.research.xacml.api.pap.PAPException;
import com.att.research.xacml.std.IdentifierImpl;
@@ -423,7 +424,6 @@
// Values for AAF Provider are here for XML Creation.
ConditionType condition = new ConditionType();
ApplyType decisionApply = new ApplyType();
- String selectedFunction = "boolean-equal";
AttributeValueType value1 = new AttributeValueType();
value1.setDataType(BOOLEAN_DATATYPE);
@@ -439,7 +439,7 @@
innerDecisionApply.setFunctionId(FUNCTION_BOOLEAN_ONE_AND_ONLY);
innerDecisionApply.getExpression().add(new ObjectFactory().createAttributeDesignator(value2));
- decisionApply.setFunctionId(dropDownMap.get(selectedFunction));
+ decisionApply.setFunctionId(XACML3.ID_FUNCTION_BOOLEAN_EQUAL.stringValue());
decisionApply.getExpression().add(new ObjectFactory().createAttributeValue(value1));
decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply));
condition.setExpression(new ObjectFactory().createApply(decisionApply));
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java
index d142a46..675c825 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java
@@ -35,6 +35,7 @@
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.pap.xacml.rest.adapters.GridData;
+import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
import org.onap.policy.pap.xacml.rest.util.JsonMessage;
import org.onap.policy.rest.dao.CommonClassDao;
import org.onap.policy.rest.jpa.ClosedLoopD2Services;
@@ -1042,6 +1043,10 @@
}
return null;
}
+
+ public static void setCommonClassDao(CommonClassDaoImpl commonClassDaoImpl) {
+ commonClassDao = commonClassDaoImpl;
+ }
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java
index 86706d1..3a4d7b7 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java
@@ -103,6 +103,11 @@
public FirewallDictionaryController(CommonClassDao commonClassDao){
FirewallDictionaryController.commonClassDao = commonClassDao;
}
+
+ public static void setCommonClassDao(CommonClassDao clDao){
+ commonClassDao = clDao;
+ }
+
/*
* This is an empty constructor
*/
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java
index f110c5b..0463585 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java
@@ -23,11 +23,15 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import javax.servlet.ServletConfig;
@@ -43,8 +47,14 @@
import org.junit.Test;
import org.mockito.Mockito;
import org.onap.policy.pap.xacml.rest.XACMLPapServlet;
+import org.onap.policy.pap.xacml.rest.controller.ClosedLoopDictionaryController;
+import org.onap.policy.pap.xacml.rest.controller.FirewallDictionaryController;
import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
import org.onap.policy.pap.xacml.rest.policycontroller.PolicyCreation;
+import org.onap.policy.rest.dao.CommonClassDao;
+import org.onap.policy.rest.jpa.BRMSParamTemplate;
+import org.onap.policy.rest.jpa.PolicyEditorScopes;
+import org.onap.policy.rest.jpa.UserInfo;
import org.onap.policy.utils.PolicyUtils;
import org.onap.policy.xacml.std.pap.StdPAPPolicy;
import org.springframework.mock.web.MockHttpServletResponse;
@@ -84,7 +94,7 @@
@Test
public void testFirwallCreatePolicy() throws IOException, ServletException, SQLException {
httpServletRequest = Mockito.mock(HttpServletRequest.class);
- String json = "";
+ 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");
@@ -102,10 +112,429 @@
Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_FW_test.1.xml");
+ }
+
+ @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");
+ StdPAPPolicy newPAPPolicy = new StdPAPPolicy("BRMS_Param","test", "testing",
+ "BRMS_PARAM_RULE",false,"test",
+ matchingAttributes, 0, "DROOLS",
+ null, ruleAttributes, "5",
+ "default", "false", "", null, null);
+ MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+
+ // set DBDao
+ setDBDao();
+ setPolicyCreation();
+ pap.service(httpServletRequest, httpServletResponse);
+
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
+ Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_BRMS_Param_test.1.xml");
+ }
+
+ @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("BRMS_Raw","test","testig description",
+ "BRMS_RAW_RULE",false,"test", ruleAttributes, 0, "DROOLS",
+ "test", "4",
+ "default", "false", null, null, null);
+ MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+
+ // set DBDao
+ setDBDao();
+ setPolicyCreation();
+ pap.service(httpServletRequest, httpServletResponse);
+
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
+ Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_BRMS_Raw_test.1.xml");
+ }
+
+ @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\"}";
+ StdPAPPolicy newPAPPolicy = new StdPAPPolicy("ClosedLoop_PM", "test", "testing", "onap",
+ json, false, null, "Registration Failure(Trinity)", false, "test", 0, null,
+ "default", "true", "");
+ MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+
+ // set DBDao
+ setDBDao();
+ setPolicyCreation();
+ pap.service(httpServletRequest, httpServletResponse);
+
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
+ Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_PM_test.1.xml");
+ }
+
+ @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("test", "test rule", "ONAP", "AAF", null, null, null,
+ null, null, null, null, null, null, false, "test", 0);
+ MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+
+ // set DBDao
+ setDBDao();
+ pap.service(httpServletRequest, httpServletResponse);
+
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
+ Mockito.verify(httpServletResponse).addHeader("policyName", "test.Decision_test.1.xml");
+ }
+
+ @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("testGuard", "test rule", "PDPD", "GUARD_YAML", matchingAttributes , null, null,
+ null, null, null, null, null, null, false, "test", 0);
+ MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+
+ // set DBDao
+ setDBDao();
+ pap.service(httpServletRequest, httpServletResponse);
+
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
+ Mockito.verify(httpServletResponse).addHeader("policyName", "test.Decision_testGuard.1.xml");
+ }
+
+ @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("testblGuard", "test rule", "PDPD", "GUARD_BL_YAML", matchingAttributes , null, null,
+ null, null, null, null, null, null, false, "test", 0);
+ MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+
+ // set DBDao
+ setDBDao();
+ pap.service(httpServletRequest, httpServletResponse);
+
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
+ Mockito.verify(httpServletResponse).addHeader("policyName", "test.Decision_testblGuard.1.xml");
+ }
+
+ @Test
+ public void testConfigPolicy() 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> configAttributes = new HashMap<>();
+ configAttributes.put("value", "test");
+ StdPAPPolicy newPAPPolicy = new StdPAPPolicy("Base", "test", "test rule", "TEST", "config", configAttributes, "OTHER",
+ "test body", false, "test",0, "5","default", "false", null);
+ MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes());
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+
+ // set DBDao
+ setDBDao();
+ pap.service(httpServletRequest, httpServletResponse);
+
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ Mockito.verify(httpServletResponse).addHeader("successMapKey", "success");
+ Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_test.1.xml");
+ }
+
+ private void setPolicyCreation() {
+ CommonClassDao commonClassDao = Mockito.mock(CommonClassDao.class);
+ PolicyCreation.setCommonClassDao(commonClassDao);
+ PolicyEditorScopes editorScope = new PolicyEditorScopes();
+ UserInfo userInfo = new UserInfo();
+ userInfo.setUserName("API");
+ userInfo.setUserLoginId("API");
+ editorScope.setScopeName("test");
+ editorScope.setUserCreatedBy(userInfo);
+ editorScope.setUserModifiedBy(userInfo);
+ Mockito.when(commonClassDao.getEntityItem(PolicyEditorScopes.class, "scopeName", "test")).thenReturn(editorScope);
+ BRMSParamTemplate template = new BRMSParamTemplate();
+ template.setRuleName("testPolicy");
+ template.setUserCreatedBy(userInfo);
+ String rule = "package com.sample;\n"
+ + "import com.sample.DroolsTest.Message;\n"
+ + "declare Params\n"
+ + "samPoll : int\n"
+ + "value : String\n"
+ + "end\n"
+ + "///This Rule will be generated by the UI.\n"
+ + "rule \"${policyName}.Create parameters structure\"\n"
+ + "salience 1000 \n"
+ + "when\n"
+ + "then\n"
+ + "Params params = new Params();\n"
+ + "params.setSamPoll(76);\n"
+ + "params.setValue(\"test\");\n"
+ + "insertLogical(params);\n"
+ + "end\n"
+ + "rule \"Rule 1: Check parameter structure access from when/then\"\n"
+ + "when\n"
+ + "$param: Params()\n"
+ + "Params($param.samPoll > 50)\n"
+ + "then\n"
+ + "System.out.println(\"Firing rule 1\");\n"
+ + "System.out.println($param);\n"
+ + "end\n";
+ template.setRule(rule );
+ Mockito.when(commonClassDao.getEntityItem(BRMSParamTemplate.class, "ruleName", "testPolicy")).thenReturn(template);
}
+ @Test
+ public void testClosedLoopCreateDictionary() throws IOException, SQLException, ServletException {
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ // Check VSCLAction.
+ String json = "{\"dictionaryFields\": {\"vsclaction\": \"testRestAPI\",\"description\": \"testing create\"}}";
+ dictionaryTestSetup(false, "VSCLAction", json);
+ // set DBDao
+ ClosedLoopDictionaryController.setCommonClassDao(new CommonClassDaoImpl());
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ //
+ // Check VNFType
+ //
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\": {\"vnftype\": \"testrestAPI1\",\"description\": \"testing create\"}}";
+ dictionaryTestSetup(false, "VNFType", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ //
+ // Check PEPOptions
+ //
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"pepName\":\"testRestAPI\",\"description\":\"testing create\",\"attributes\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\",\"number\":\"test\"}]}}";
+ dictionaryTestSetup(false, "PEPOptions", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ //
+ // Check Varbind
+ //
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"varbindName\":\"testRestAPI\",\"varbindDescription\":\"testing\",\"varbindOID\":\"test\"}}";
+ dictionaryTestSetup(false, "Varbind", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ //
+ // Check Service
+ //
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"serviceName\":\"testRestAPI\",\"description\":\"testing\"}}";
+ dictionaryTestSetup(false, "Service", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ //
+ // Check Site
+ //
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"siteName\":\"testRestAPI\",\"description\":\"testing\"}}";
+ dictionaryTestSetup(false, "Site", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ }
+
+ @Test
+ public void testFirewallCreateDictionary() throws IOException, SQLException, ServletException {
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ // Check SecurityZone.
+ String json = "{\"dictionaryFields\":{\"zoneName\":\"testRestAPI\",\"zoneValue\":\"testing\"}}";
+ dictionaryTestSetup(false, "SecurityZone", json);
+ // set DBDao
+ FirewallDictionaryController.setCommonClassDao(new CommonClassDaoImpl());
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ //
+ // Check Action List
+ //
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"actionName\":\"testRestAPI\",\"description\":\"test\"}}";
+ dictionaryTestSetup(false, "ActionList", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ //
+ // Check Protocol List.
+ //
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"protocolName\":\"testRestAPI\",\"description\":\"test\"}}";
+ dictionaryTestSetup(false, "ProtocolList", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ //
+ // Check Zone.
+ //
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"zoneName\":\"testRestAPI\",\"zoneValue\":\"test\"}}";
+ dictionaryTestSetup(false, "Zone", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ //
+ // Check PrefixList.
+ //
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"prefixListName\":\"testRestAPI\",\"prefixListValue\":\"127.0.0.1\",\"description\":\"testing\"}}";
+ dictionaryTestSetup(false, "PrefixList", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ //
+ // Check AddressGroup.
+ //
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"groupName\":\"testRestAPIgroup\",\"description\":\"testing\",\"attributes\":[{\"option\":\"testRestAPI\"}, {\"option\":\"testRestAPI\"}]}}";
+ dictionaryTestSetup(false, "AddressGroup", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ //
+ // Check ServiceGroup.
+ //
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"groupName\":\"testRestAPIServiceGroup\",\"attributes\":[{\"option\":\"testRestAPIservice\"}]}}";
+ dictionaryTestSetup(false, "ServiceGroup", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ //
+ // Check ServiceList.
+ //
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"serviceName\":\"testRestAPIservice\",\"serviceDescription\":\"test\",\"servicePorts\":\"8888\",\"transportProtocols\":[{\"option\":\"testRestAPI\"},{\"option\":\"testRestAPI1\"}],\"appProtocols\":[{\"option\":\"testRestAPI\"},{\"option\":\"testRestAPI1\"}]}}";
+ dictionaryTestSetup(false, "ServiceList", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ //
+ // Check TermList.
+ //
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ 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\"}]}}";
+ dictionaryTestSetup(false, "TermList", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ }
+ private void dictionaryTestSetup(Boolean updateFlag, String dictionaryType, String json) throws IOException, SQLException {
+ Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
+ Mockito.when(httpServletRequest.getHeader("ClientScope")).thenReturn("dictionaryItem");
+ Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT");
+ Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
+ if(updateFlag){
+ Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("update");
+ }else{
+ Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create");
+ }
+ Mockito.when(httpServletRequest.getParameter("dictionaryType")).thenReturn(dictionaryType);
+ MockServletInputStream mockInput = new MockServletInputStream(json.getBytes());
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+ Mockito.when(httpServletRequest.getReader()).thenReturn(new BufferedReader(new InputStreamReader(mockInput)));
+ // set DBDao
+ setDBDao();
+ }
private void setDBDao() throws SQLException {
BasicDataSource dataSource = new BasicDataSource();
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java
index 1a97d7f..99285e7 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java
@@ -20,9 +20,10 @@
package org.onap.policy.pap.xacml.rest.components;
import static org.junit.Assert.*;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
@@ -124,5 +125,24 @@
assertTrue(response);
}
+
+ @Test
+ public void testUpdateJson() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
+ FirewallConfigPolicy firewallConfigPolicy = new FirewallConfigPolicy();
+ Method method = firewallConfigPolicy.getClass().getDeclaredMethod("updateFirewallDictionaryData", String.class , String.class);
+ method.setAccessible(true);
+ String jsonBody= "{\"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}]}";
+ String prevJsonBody = "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"TestFwPolicy1Config\",\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"cloudsite:dev\",\"vendorServiceId\":\"test\",\"vendorSpecificData\":{\"idMap\":[{\"Id\":\"cloudsite:dev1a\",\"vendorId\":\"deviceGroup:dev\"}]},\"serviceGroups\":[{\"name\":\"SSH\",\"description\":\"Ssh service entry in service list\",\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"22\"}],\"addressGroups\":[{\"name\":\"Test\",\"description\":\"Destination Test\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/12\"}]},{\"name\":\"TestServers\",\"description\":\"Source TestServers for first testing\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/23\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"FWRuleTestServerTot\",\"fromZones\":[\"UntrustedZoneTestName\"],\"toZones\":[\"TrustedZoneTName\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"name\":\"TServers\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"name\":\"Test\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"SSH\"}],\"action\":\"accept\",\"description\":\"FW rule for HOHO source to CiscoVCE destination\",\"enabled\":true,\"log\":true}]}";
+ assertFalse((Boolean) method.invoke(firewallConfigPolicy, jsonBody, prevJsonBody));
+ }
+
+ @Test
+ public void testInsertJson() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
+ FirewallConfigPolicy firewallConfigPolicy = new FirewallConfigPolicy();
+ Method method = firewallConfigPolicy.getClass().getDeclaredMethod("insertFirewallDicionaryData", String.class);
+ method.setAccessible(true);
+ String jsonBody= "{\"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}]}";
+ assertFalse((Boolean) method.invoke(firewallConfigPolicy, jsonBody));
+ }
}
\ No newline at end of file
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpServlet.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpServlet.java
index 18c2017..b824312 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpServlet.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpServlet.java
@@ -180,6 +180,14 @@
private static volatile boolean configThreadTerminate = false;
private transient ONAPLoggingContext baseLoggingContext = null;
private transient IntegrityMonitor im;
+ public IntegrityMonitor getIm() {
+ return im;
+ }
+
+ public void setIm(IntegrityMonitor im) {
+ this.im = im;
+ }
+
/**
* Default constructor.
*/
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java
index 3e3f584..594b51c 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java
@@ -27,6 +27,10 @@
import java.util.Properties;
import java.util.Random;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Persistence;
import javax.servlet.ServletConfig;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
@@ -34,16 +38,18 @@
import javax.servlet.http.HttpServletResponse;
import org.junit.Before;
-import org.junit.runner.RunWith;
+import org.junit.Test;
import org.mockito.Mockito;
+import org.onap.policy.common.ia.DbDAO;
+import org.onap.policy.common.ia.IntegrityAuditProperties;
import org.onap.policy.common.im.AdministrativeStateException;
import org.onap.policy.common.im.IntegrityMonitor;
import org.onap.policy.common.im.StandbyStatusException;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
+
+import org.onap.policy.pdp.rest.XACMLPdpServletTest;
import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletConfig;
@@ -51,8 +57,6 @@
import junit.framework.TestCase;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(IntegrityMonitor.class) // so PowerMock can mock static method of IntegrityMonitor
public class XACMLPdpServletTest extends TestCase{
private static Logger LOGGER = FlexLogger.getLogger(XACMLPdpServletTest.class);
@@ -65,16 +69,64 @@
private ServletConfig servletConfig;
private XACMLPdpServlet pdpServlet;
private IntegrityMonitor im;
-
+
+ private DbDAO dbDAO;
+ private String persistenceUnit;
+ private Properties properties;
+ private String resourceName;
+ private String dbDriver;
+ private String dbUrl;
+ private String dbUser;
+ private String dbPwd;
+ private String siteName;
+ private String nodeType;
+ private static final String DEFAULT_DB_DRIVER = "org.h2.Driver";
+ private static final String DEFAULT_DB_USER = "sa";
+ private static final String DEFAULT_DB_PWD = "";
@Before
public void setUp(){
+
+ properties = new Properties();
+ properties.put(IntegrityAuditProperties.DB_DRIVER, XACMLPdpServletTest.DEFAULT_DB_DRIVER);
+ properties.put(IntegrityAuditProperties.DB_URL, "jdbc:h2:file:./sql/xacmlTest");
+ properties.put(IntegrityAuditProperties.DB_USER, XACMLPdpServletTest.DEFAULT_DB_USER);
+ properties.put(IntegrityAuditProperties.DB_PWD, XACMLPdpServletTest.DEFAULT_DB_PWD);
+ properties.put(IntegrityAuditProperties.SITE_NAME, "SiteA");
+ properties.put(IntegrityAuditProperties.NODE_TYPE, "pap");
+ //properties.put("com.sun.management.jmxremote.port", "9999");
+ dbDriver = XACMLPdpServletTest.DEFAULT_DB_DRIVER;
+ dbUrl = "jdbc:h2:file:./sql/xacmlTest";
+ dbUser = XACMLPdpServletTest.DEFAULT_DB_USER;
+ dbPwd = XACMLPdpServletTest.DEFAULT_DB_PWD;
+ siteName = "SiteA";
+ nodeType = "pdp";
+ persistenceUnit = "testPdpPU";
+ resourceName = "siteA.pdp1";
+
+ System.setProperty("com.sun.management.jmxremote.port", "9999");
+
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit, properties);
+
+ EntityManager em = emf.createEntityManager();
+ // Start a transaction
+ EntityTransaction et = em.getTransaction();
+
+ IntegrityMonitor im = null;
+ try {
+ im = IntegrityMonitor.getInstance(resourceName, properties);
+ } catch (Exception e2) {
+ // TODO Auto-generated catch block
+ e2.printStackTrace();
+ }
+ //cleanDb(persistenceUnit, properties);
+
httpServletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(httpServletRequest.getMethod()).thenReturn("POST");
Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headers));
Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(headers));
-
+ Mockito.when(httpServletRequest.getRequestURI()).thenReturn("/pdp/test");
mockOutput = Mockito.mock(ServletOutputStream.class);
@@ -90,15 +142,17 @@
//servletConfig
Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers));
pdpServlet = new XACMLPdpServlet();
+ pdpServlet.setIm(im);
- Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("xacml.pdp.properties");
+ Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("src/test/resources/xacml.pdp.properties");
- System.setProperty("xacml.properties", "xacml.pdp.properties");
- System.setProperty("xacml.rest.pdp.config", "config_testing");
- System.setProperty("xacml.rest.pdp.webapps", "/webapps");
- System.setProperty("xacml.rootPolicies", "test_PolicyEngine.xml");
+ System.setProperty("xacml.properties", "src/test/resources/xacml.pdp.properties");
+ System.setProperty("xacml.rest.pdp.config", "src/test/resources/config_testing");
+ System.setProperty("xacml.rest.pdp.webapps", "src/test/resources/webapps");
+ /*System.setProperty("xacml.rootPolicies", "test_PolicyEngine.xml");
System.setProperty("xacml.referencedPolicies", "test_PolicyEngine.xml");
System.setProperty("test_PolicyEngine.xml.file", "config_testing\\test_PolicyEngine.xml");
+ */
System.setProperty("xacml.rest.pdp.register", "false");
System.setProperty("com.sun.management.jmxremote.port", "9999");
@@ -119,8 +173,9 @@
}
Mockito.doNothing().when(im).endTransaction();
}
-
- public void testInit(){
+
+ @Test
+ public void testInit(){
LOGGER.info("XACMLPdpServletTest - testInit");
try {
pdpServlet.init(servletConfig);
@@ -133,12 +188,14 @@
}
+ @Test
public void testDoGetNoTypeError(){
LOGGER.info("XACMLPdpServletTest - testDoGetNoTypeError");
try{
+
pdpServlet.init(servletConfig);
pdpServlet.doGet(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "type not 'config' or 'hb'");
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
assertTrue(true);
}catch(Exception e){
System.out.println("Unexpected exception in testDoGetNoTypeError");
@@ -147,6 +204,7 @@
}
}
+ @Test
public void testDoGetConfigType(){
LOGGER.info("XACMLPdpServletTest - testDoGetConfigType");
Mockito.when(httpServletRequest.getParameter("type")).thenReturn("config");
@@ -164,14 +222,14 @@
}
-
+ @Test
public void testDoGetTypeHb(){
LOGGER.info("XACMLPdpServletTest - testDoGetTypeHb");
try{
Mockito.when(httpServletRequest.getParameter("type")).thenReturn("hb");
pdpServlet.init(servletConfig);
pdpServlet.doGet(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_NO_CONTENT);
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
assertTrue(true);
}catch(Exception e){
System.out.println("Unexpected exception in testDoGetTypeHb");
@@ -179,6 +237,8 @@
fail();
}
}
+
+ @Test
public void testDoGetTypeStatus(){
LOGGER.info("XACMLPdpServletTest - testDoGetTypeStatus");
try{
@@ -194,6 +254,7 @@
}
}
+ @Test
public void testDoPost(){
LOGGER.info("XACMLPdpServletTest - testDoPost");
try{
@@ -207,6 +268,7 @@
}
}
+ @Test
public void testDoPostToLong(){
LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
try{
@@ -223,6 +285,7 @@
}
}
+ @Test
public void testDoPostContentLengthNegative(){
LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
try{
@@ -239,6 +302,7 @@
}
}
+ @Test
public void testDoPostContentTypeNonValid(){
LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
try{
@@ -255,6 +319,7 @@
}
}
+ @Test
public void testDoPostContentTypeConfigurationError(){
LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
try{
@@ -271,6 +336,7 @@
}
}
+ @Test
public void testDoPutCacheEmpty(){
LOGGER.info("XACMLPdpServletTest - testDoPutCacheEmpty");
mockInput = Mockito.mock(ServletInputStream.class);
@@ -290,6 +356,7 @@
}
}
+ @Test
public void testDoPutConfigPolicies(){
LOGGER.info("XACMLPdpServletTest - testDoPutConfigPolicies");
byte[] b = new byte[20];
@@ -330,6 +397,7 @@
}
}
+ @Test
public void testDoPutInvalidContentType(){
LOGGER.info("XACMLPdpServletTest - testDoPutToLong");
try{
@@ -349,6 +417,7 @@
}
}
+ @Test
public void testDestroy(){
LOGGER.info("XACMLPdpServletTest - testDestroy");
diff --git a/ONAP-PDP-REST/src/test/resources/META-INF/drop.ddl b/ONAP-PDP-REST/src/test/resources/META-INF/drop.ddl
new file mode 100644
index 0000000..f7138ad
--- /dev/null
+++ b/ONAP-PDP-REST/src/test/resources/META-INF/drop.ddl
@@ -0,0 +1,7 @@
+DROP TABLE IF EXISTS ConfigurationDataEntity
+DROP TABLE IF EXISTS PolicyEntity
+DROP TABLE IF EXISTS PolicyDBDaoEntity
+DROP TABLE IF EXISTS ActionBodyEntity
+DROP SEQUENCE IF EXISTS seqPolicy
+DROP SEQUENCE IF EXISTS seqConfig
+DROP SEQUENCE IF EXISTS seqActBody
diff --git a/ONAP-PDP-REST/src/test/resources/META-INF/persistence.xml b/ONAP-PDP-REST/src/test/resources/META-INF/persistence.xml
new file mode 100644
index 0000000..b44841c
--- /dev/null
+++ b/ONAP-PDP-REST/src/test/resources/META-INF/persistence.xml
@@ -0,0 +1,201 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ ONAP-PAP-REST
+ ================================================================================
+ Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ ================================================================================
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ ============LICENSE_END=========================================================
+ -->
+<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
+ <persistence-unit name="XACML-PAP-REST">
+ <class>org.onap.policy.rest.jpa.PolicyEntity</class>
+ <class>org.onap.policy.rest.jpa.ConfigurationDataEntity</class>
+ <class>org.onap.policy.rest.jpa.PolicyDBDaoEntity</class>
+ <class>org.onap.policy.rest.jpa.GroupEntity</class>
+ <class>org.onap.policy.rest.jpa.PdpEntity</class>
+ <class>org.onap.policy.rest.jpa.ActionBodyEntity</class>
+ <class>org.onap.policy.rest.jpa.DatabaseLockEntity</class>
+ <class>org.onap.policy.rest.jpa.PolicyVersion</class>
+ <class>org.onap.policy.rest.jpa.PolicyScore</class>
+ <class>org.onap.policy.rest.jpa.FunctionDefinition</class>
+ <class>org.onap.policy.rest.jpa.Attribute</class>
+ <class>org.onap.policy.rest.jpa.Category</class>
+ <class>org.onap.policy.rest.jpa.ConstraintType</class>
+ <class>org.onap.policy.rest.jpa.ConstraintValue</class>
+ <class>org.onap.policy.rest.jpa.Datatype</class>
+ <class>org.onap.policy.rest.jpa.FunctionArgument</class>
+ <class>org.onap.policy.rest.jpa.UserInfo</class>
+ <class>org.onap.policy.rest.jpa.ActionPolicyDict</class>
+ <class>org.onap.policy.rest.jpa.DecisionSettings</class>
+ <class>org.onap.policy.rest.jpa.MicroServiceModels</class>
+ <class>org.onap.policy.rest.jpa.BRMSParamTemplate</class>
+ <class>org.onap.policy.rest.jpa.PolicyEditorScopes</class>
+ <!-- unique to PolicyEngineUtils - will be audited from PAP -->
+ <class>org.onap.policy.jpa.BackUpMonitorEntity</class>
+ <!-- unique to integrity-monitor - will be audited from PAP -->
+ <class>org.onap.policy.common.im.jpa.StateManagementEntity</class>
+ <class>org.onap.policy.common.im.jpa.ForwardProgressEntity</class>
+ <class>org.onap.policy.common.im.jpa.ResourceRegistrationEntity</class>
+ <!-- unique to integrity-audit - will be audited from PAP -->
+ <class>org.onap.policy.common.ia.jpa.IntegrityAuditEntity</class>
+ <exclude-unlisted-classes>false</exclude-unlisted-classes>
+ <shared-cache-mode>NONE</shared-cache-mode>
+ <properties>
+ <!-- The properties defined below are the default settings to be used when someone initially
+ wants to start working with the XACML-PAP-ADMIN web gui. They are not intended for production
+ use.
+
+ They are setup to drop and create the tables and then load an initial set of data into the database
+ every time the application is deployed. So if you add anything to the dictionaries or PIP
+ configuration, they will get lost upon each deployment. It uses an H2 database engine configured
+ for a local file so you don't have to setup you're own SQL database environment to start.
+
+ Instead of modifying this file directly, please refer to the xacml.admin.properties file for
+ customizing the application settings.
+
+ -->
+ <!-- <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
+ <property name="javax.persistence.schema-generation.create-source" value="metadata-then-script"/>
+ <property name="javax.persistence.schema-generation.create-script-source" value="META-INF/views.sql" />
+ <property name="javax.persistence.schema-generation.drop-source" value="script"/>
+ <property name="javax.persistence.schema-generation.drop-script-source" value="META-INF/drop.sql" />
+ <property name="javax.persistence.sql-load-script-source" value="META-INF/data.sql" />-->
+
+
+
+ <!-- These properties should be set in the xacml.admin.properties file, so they can be re-used by non-JPA
+ database functionality. -->
+ <!--
+ <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
+ <property name="javax.persistence.jdbc.url" value="jdbc:h2:file:sql/xacml"/>
+ <property name="javax.persistence.jdbc.user" value="sa"/>
+ <property name="javax.persistence.jdbc.password" value=""/>
+ -->
+ </properties>
+ </persistence-unit>
+
+<persistence-unit name="auditPapPU">
+ <!-- This is the persistence unit used by IntegrityAudit to determine
+ which classes to audit. All the PAP classes are also included in
+ XACML-PAP-ADMIN, so they will be audited there rather than having a
+ duplicate audit run from the XACL-PAP-REST node -->
+ <!-- unique to PolicyEngineUtils - will be audited from PAP -->
+ <class>org.onap.policy.jpa.BackUpMonitorEntity</class>
+ <!-- unique to integrity-monitor - will be audited from PAP -->
+ <class>org.onap.policy.common.im.jpa.StateManagementEntity</class>
+ <class>org.onap.policy.common.im.jpa.ForwardProgressEntity</class>
+ <class>org.onap.policy.common.im.jpa.ResourceRegistrationEntity</class>
+ <!-- unique to integrity-audit - will be audited from PAP -->
+ <class>org.onap.policy.common.ia.jpa.IntegrityAuditEntity</class>
+ <exclude-unlisted-classes>true</exclude-unlisted-classes>
+ <shared-cache-mode>NONE</shared-cache-mode>
+ </persistence-unit>
+
+ <persistence-unit name="testPdpPU" transaction-type="RESOURCE_LOCAL">
+ <!-- This tests all the classes that will be audited in the XACML-PAP-REST and the XACML-PAP_ADMIN -->
+ <!-- XACML-PAP-REST -->
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+ <class>org.onap.policy.rest.jpa.PolicyEntity</class>
+ <class>org.onap.policy.rest.jpa.ConfigurationDataEntity</class>
+ <class>org.onap.policy.rest.jpa.PolicyDBDaoEntity</class>
+ <class>org.onap.policy.rest.jpa.GroupEntity</class>
+ <class>org.onap.policy.rest.jpa.PdpEntity</class>
+ <class>org.onap.policy.rest.jpa.ActionBodyEntity</class>
+ <class>org.onap.policy.rest.jpa.DatabaseLockEntity</class>
+ <class>org.onap.policy.rest.jpa.PolicyVersion</class>
+ <class>org.onap.policy.rest.jpa.PolicyScore</class>
+ <class>org.onap.policy.rest.jpa.FunctionDefinition</class>
+ <class>org.onap.policy.rest.jpa.Attribute</class>
+ <class>org.onap.policy.rest.jpa.Category</class>
+ <class>org.onap.policy.rest.jpa.ConstraintType</class>
+ <class>org.onap.policy.rest.jpa.ConstraintValue</class>
+ <class>org.onap.policy.rest.jpa.Datatype</class>
+ <class>org.onap.policy.rest.jpa.FunctionArgument</class>
+ <class>org.onap.policy.rest.jpa.UserInfo</class>
+ <class>org.onap.policy.rest.jpa.ActionPolicyDict</class>
+ <class>org.onap.policy.rest.jpa.DecisionSettings</class>
+ <class>org.onap.policy.rest.jpa.MicroServiceModels</class>
+ <!-- unique to XACML-PAP-ADMIN -->
+ <class>org.onap.policy.rest.jpa.ActionList</class>
+ <class>org.onap.policy.rest.jpa.AddressGroup</class>
+ <class>org.onap.policy.rest.jpa.AttributeAssignment</class>
+ <class>org.onap.policy.rest.jpa.BRMSParamTemplate</class>
+ <class>org.onap.policy.rest.jpa.ClosedLoopD2Services</class>
+ <class>org.onap.policy.rest.jpa.ClosedLoopSite</class>
+ <class>org.onap.policy.rest.jpa.DCAEUsers</class>
+ <class>org.onap.policy.rest.jpa.DCAEuuid</class>
+ <class>org.onap.policy.rest.jpa.DescriptiveScope</class>
+ <class>org.onap.policy.rest.jpa.OnapName</class>
+ <class>org.onap.policy.rest.jpa.EnforcingType</class>
+ <class>org.onap.policy.rest.jpa.GlobalRoleSettings</class>
+ <class>org.onap.policy.rest.jpa.GroupPolicyScopeList</class>
+ <class>org.onap.policy.rest.jpa.GroupServiceList</class>
+ <class>org.onap.policy.rest.jpa.MicroServiceConfigName</class>
+ <class>org.onap.policy.rest.jpa.MicroServiceLocation</class>
+ <class>org.onap.policy.rest.jpa.Obadvice</class>
+ <class>org.onap.policy.rest.jpa.ObadviceExpression</class>
+ <class>org.onap.policy.rest.jpa.PEPOptions</class>
+ <class>org.onap.policy.rest.jpa.PIPConfigParam</class>
+ <class>org.onap.policy.rest.jpa.PIPConfiguration</class>
+ <class>org.onap.policy.rest.jpa.PIPResolver</class>
+ <class>org.onap.policy.rest.jpa.PIPResolverParam</class>
+ <class>org.onap.policy.rest.jpa.PIPType</class>
+ <class>org.onap.policy.rest.jpa.PolicyAlgorithms</class>
+ <class>org.onap.policy.rest.jpa.PolicyManagement</class>
+ <class>org.onap.policy.rest.jpa.PolicyScopeService</class>
+ <class>org.onap.policy.rest.jpa.PolicyScopeType</class>
+ <class>org.onap.policy.rest.jpa.PolicyScopeResource</class>
+ <class>org.onap.policy.rest.jpa.PolicyScopeClosedLoop</class>
+ <class>org.onap.policy.rest.jpa.PortList</class>
+ <class>org.onap.policy.rest.jpa.PREFIXLIST</class>
+ <class>org.onap.policy.rest.jpa.ProtocolList</class>
+ <class>org.onap.policy.rest.jpa.RemoteCatalogValues</class>
+ <class>org.onap.policy.rest.jpa.PolicyRoles</class>
+ <class>org.onap.policy.rest.jpa.RuleAlgorithms</class>
+ <class>org.onap.policy.rest.jpa.SecurityZone</class>
+ <class>org.onap.policy.rest.jpa.ServiceList</class>
+ <class>org.onap.policy.rest.jpa.SystemLogDB</class>
+ <class>org.onap.policy.rest.jpa.TermList</class>
+ <class>org.onap.policy.rest.jpa.VarbindDictionary</class>
+ <class>org.onap.policy.rest.jpa.VMType</class>
+ <class>org.onap.policy.rest.jpa.VNFType</class>
+ <class>org.onap.policy.rest.jpa.VSCLAction</class>
+ <class>org.onap.policy.rest.jpa.Zone</class>
+ <!-- unique to PolicyEngineUtils -->
+ <class>org.onap.policy.jpa.BackUpMonitorEntity</class>
+ <!-- unique to integrity-monitor -->
+ <class>org.onap.policy.common.im.jpa.StateManagementEntity</class>
+ <class>org.onap.policy.common.im.jpa.ForwardProgressEntity</class>
+ <class>org.onap.policy.common.im.jpa.ResourceRegistrationEntity</class>
+ <!-- unique to integrity-audit -->
+ <class>org.onap.policy.common.ia.jpa.IntegrityAuditEntity</class>
+
+ <exclude-unlisted-classes>false</exclude-unlisted-classes>
+ <shared-cache-mode>NONE</shared-cache-mode>
+ <properties>
+ <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
+ <property name="javax.persistence.jdbc.url" value="jdbc:h2:file:./sql/xacmlTest"/> <!-- ;MODE=MySQL"/> -->
+ <property name="javax.persistence.jdbc.user" value="sa"/>
+ <property name="javax.persistence.jdbc.password" value=""/>
+ <property name="javax.persistence.schema-generation.scripts.action" value="drop-and-create"/>
+ <property name="javax.persistence.schema-generation.scripts.create-target" value="./src/test/resources/generatedCreate.ddl"/>
+ <property name="javax.persistence.schema-generation.scripts.drop-target" value="./src/test/resources/generatedDrop.ddl"/>
+ <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
+ <property name="javax.persistence.schema-generation.create-source" value="metadata-then-script"/>
+ <property name="javax.persistence.schema-generation.drop-source" value="script"/>
+ <property name="javax.persistence.schema-generation.drop-script-source" value="META-INF/drop.ddl" />
+ </properties>
+ </persistence-unit>
+</persistence>
diff --git a/ONAP-PDP-REST/src/test/resources/xacml.pdp.properties b/ONAP-PDP-REST/src/test/resources/xacml.pdp.properties
new file mode 100644
index 0000000..bb174b9
--- /dev/null
+++ b/ONAP-PDP-REST/src/test/resources/xacml.pdp.properties
@@ -0,0 +1,176 @@
+###
+# ============LICENSE_START=======================================================
+# ONAP-PDP-REST
+# ================================================================================
+# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
+
+# Default XACML Properties File for PDP RESTful servlet
+#
+# Standard API Factories
+#
+xacml.dataTypeFactory=com.att.research.xacml.std.StdDataTypeFactory
+xacml.pdpEngineFactory=com.att.research.xacmlatt.pdp.ATTPDPEngineFactory
+xacml.pepEngineFactory=com.att.research.xacml.std.pep.StdEngineFactory
+# NOT USED SEE BELOW xacml.pipFinderFactory=org.onap.policy.xacml.std.pip.StdPIPFinderFactory
+xacml.traceEngineFactory=com.att.research.xacml.std.trace.LoggingTraceEngineFactory
+#
+# AT&T PDP Implementation Factories
+#
+xacml.att.evaluationContextFactory=com.att.research.xacmlatt.pdp.std.StdEvaluationContextFactory
+xacml.att.combiningAlgorithmFactory=com.att.research.xacmlatt.pdp.std.StdCombiningAlgorithmFactory
+xacml.att.functionDefinitionFactory=org.onap.policy.xacml.custom.OnapFunctionDefinitionFactory
+# NOT USED SEE BELOW xacml.att.policyFinderFactory=org.onap.policy.pdp.std.StdPolicyFinderFactory
+# creteUpdate Policy Implementation Class details.
+createUpdatePolicy.impl.className=org.onap.policy.pdp.rest.api.services.CreateUpdatePolicyServiceImpl
+# AAF Implementation class details
+aafClient.impl.className=org.onap.policy.utils.AAFPolicyClientImpl
+#
+# AT&T RESTful PDP Implementation Factories
+#
+xacml.pipFinderFactory=org.onap.policy.pdp.rest.impl.XACMLPdpPIPFinderFactory
+xacml.att.policyFinderFactory=org.onap.policy.pdp.rest.XACMLPdpPolicyFinderFactory
+#
+# When set to true, this flag tells the StdPolicyFinderFactory to combined all the root policy files into
+# into one PolicySet and use the given Policy Algorithm.
+#
+xacml.att.policyFinderFactory.combineRootPolicies=urn:com:att:xacml:3.0:policy-combining-algorithm:combined-permit-overrides
+#
+# PDP RESTful API properties
+#
+# Set this to the address where the XACML-PAP-REST servlet is running
+xacml.rest.pap.url=http://localhost:8070/pap/
+
+#if multiple paps exist, the xacml.rest.pap.url can be removed and they can be defined like this:
+#xacml.rest.pap.urls=http://localhost:9090/pap/,http://localhost:9091/pap/
+
+#
+# Give the running PDP an ID for the PAP. The url that its running as is a good choice.
+# The PAP identifies PDP's using the URL of the PDP.
+#
+xacml.rest.pdp.id=http://localhost:8082/pdp/
+
+# Give the port number used for the PDP
+
+xacml.jmx.port=0
+
+
+# Notification Properties
+# Notifcation type: websocket, ueb or dmaap... if left blank websocket is the default
+NOTIFICATION_TYPE=websocket
+NOTIFICATION_SERVERS=
+NOTIFICATION_TOPIC=
+NOTIFICATION_DELAY=
+UEB_API_KEY=
+UEB_API_SECRET=
+DMAAP_AAF_LOGIN=
+DMAAP_AAF_PASSWORD=
+
+#
+# Set the directory where the PDP holds its Policy Cache and PIP Configuration
+#
+xacml.rest.pdp.config=config
+
+xacml.rest.pdp.webapps=/home/users/PolicyEngine/webapps/ConfigPAP/
+#
+# Initialize register with PAP servlet
+#
+xacml.rest.pdp.register=true
+#
+# Sleep period in seconds between register attempts
+#
+xacml.rest.pdp.register.sleep=15
+#
+# number of attempts to register. -1 means keep trying forever.
+#
+xacml.rest.pdp.register.retries=-1
+#
+# max number of bytes in a POST of a XML/JSON request
+# old value #32767
+xacml.rest.pdp.maxcontent=99999999
+#
+# Set UserID here
+xacml.rest.pdp.userid=testpdp
+# Set Password here
+xacml.rest.pdp.password=alpha456
+
+# id PAP
+xacml.rest.pap.userid=testpap
+#if multiple paps have different logins, they can be defined like this:
+#http\://localhost\:9090/pap/.xacml.rest.pap.userid=testpap
+
+# pass PAP
+xacml.rest.pap.password=alpha123
+#http\://localhost\:9090/pap/.xacml.rest.pap.password=alpha123
+
+# Delay for Notifications Don't change this. Value in milliSec.
+xacml.rest.notification.delay=30
+
+# Client interval to ping notification service.
+CLIENT_INTERVAL=15000
+
+# Buffer Size.
+REQUEST_BUFFER_SIZE=15
+
+#Properties for db access
+#properties for MySql xacml database: PLEASE DO NOT REMOVE... NEEDED FOR APIs
+javax.persistence.jdbc.driver=org.h2.Driver
+javax.persistence.jdbc.url=jdbc:h2:file:./sql/xacmlTest
+javax.persistence.jdbc.user=sa
+javax.persistence.jdbc.password=
+
+#***Properties for IntegrityMonitor integration defined in XACMLRestProperties.java***
+
+#The name of the PDP. Must be unique across the system
+xacml.rest.pdp.resource.name=site_1.pdp_1
+
+#***Properties for IntegrityMonitor integration defined in IntegrityMonitorProperties.java***
+
+#Interval between forward progress counter updates in seconds
+fp_monitor_interval=30
+
+#Number of forward progress counter failures before failover
+failed_counter_threshold=3
+
+#Interval in seconds between test transactions if there is no other traffic
+test_trans_interval=10
+
+#Interval in seconds between updates of the forward progress counter in the DB
+write_fpc_interval=5
+
+#Name of the site
+site_name=site_1
+
+#Node type
+node_type=pdp_xacml
+
+#Dependency groups are groups of resources upon which a node operational state is dependent upon).
+#Each group is a comma-separated list of resource names and groups are separated by a semicolon.
+#A group may contain one or more members. Resource names must match the resource names defined
+#in the respective servers' properties files
+dependency_groups=site_1.pdplp_1;site_1.astragw_1;site_1.brmsgw_1
+
+# this can be DEVL, TEST, PROD
+ENVIRONMENT=DEVL
+xacml.rest.pep.idfile = client.properties
+
+#AAF Policy Name space
+#Not Mandatory for Open Onap
+policy.aaf.namespace =
+policy.aaf.resource =
+# Decision Response settings.
+# can be either PERMIT or DENY.
+decision.indeterminate.response=PERMIT
\ No newline at end of file
diff --git a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPGroupStatusTest.java b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPGroupStatusTest.java
new file mode 100644
index 0000000..f062618
--- /dev/null
+++ b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPGroupStatusTest.java
@@ -0,0 +1,208 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-XACML
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.xacml.test.std.pap;
+
+import static org.junit.Assert.*;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+import org.onap.policy.xacml.std.pap.StdPDP;
+import org.onap.policy.xacml.std.pap.StdPDPGroupStatus;
+import org.onap.policy.xacml.std.pap.StdPDPPIPConfig;
+
+public class StdPDPGroupStatusTest {
+
+ private static Logger logger = FlexLogger.getLogger(StdPDPGroupStatus.class);
+
+ private StdPDPGroupStatus stdPDPGroupStatus;
+
+ @Before
+ public void setUp(){
+
+ try {
+ stdPDPGroupStatus = new StdPDPGroupStatus();
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void tesGgetStatus() {
+ try {
+ assertTrue(stdPDPGroupStatus.getStatus() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetFailedPIPConfigs() {
+ try {
+ assertTrue(stdPDPGroupStatus.getFailedPIPConfigs() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetUnknownPDPs() {
+ try {
+ assertTrue(stdPDPGroupStatus.getUnknownPDPs() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetLoadErrors() {
+ try {
+ stdPDPGroupStatus.setLoadErrors(new HashSet<String>());
+ assertTrue(stdPDPGroupStatus.getLoadErrors() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetLoadWarnings() {
+ try {
+ stdPDPGroupStatus.setLoadWarnings(new HashSet<>());
+ assertTrue(stdPDPGroupStatus.getLoadWarnings() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetLoadedPolicies() {
+ try {
+ stdPDPGroupStatus.setLoadedPolicies(new HashSet<>());
+ assertTrue(stdPDPGroupStatus.getLoadedPolicies() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetFailedPolicies() {
+ try {
+ stdPDPGroupStatus.setFailedPolicies(new HashSet<>());
+ assertTrue(stdPDPGroupStatus.getFailedPolicies() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetLoadedPipConfigs() {
+ try {
+ stdPDPGroupStatus.addLoadedPipConfig(new StdPDPPIPConfig());
+ assertTrue(stdPDPGroupStatus.getLoadedPipConfigs() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetFailedPipConfigs() {
+ try {
+ stdPDPGroupStatus.addFailedPipConfig(new StdPDPPIPConfig());
+ assertTrue(stdPDPGroupStatus.getFailedPipConfigs() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetInSynchPDPs() {
+ try {
+ stdPDPGroupStatus.addInSynchPDP(new StdPDP());
+ assertTrue(stdPDPGroupStatus.getInSynchPDPs() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetOutOfSynchPDPs() {
+ try {
+ stdPDPGroupStatus.addOutOfSynchPDP(new StdPDP());
+ assertTrue(stdPDPGroupStatus.getOutOfSynchPDPs() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetFailedPDPs() {
+ try {
+ stdPDPGroupStatus.addFailedPDP(new StdPDP());
+ assertTrue(stdPDPGroupStatus.getFailedPDPs() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetUpdatingPDPs() {
+ try {
+ stdPDPGroupStatus.addUpdatingPDP(new StdPDP());
+ assertTrue(stdPDPGroupStatus.getUpdatingPDPs() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetLastUpdateFailedPDPs() {
+ try {
+ stdPDPGroupStatus.addLastUpdateFailedPDP(new StdPDP());
+ assertTrue(stdPDPGroupStatus.getLastUpdateFailedPDPs() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetUnknownStatusPDPs() {
+ try {
+ stdPDPGroupStatus.addUnknownPDP(new StdPDP());
+ assertTrue(stdPDPGroupStatus.getUnknownStatusPDPs() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testIsGroupOk() {
+ try {
+ stdPDPGroupStatus.policiesOK();
+ assertTrue(stdPDPGroupStatus.isGroupOk() == false);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+}
diff --git a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPGroupTest.java b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPGroupTest.java
new file mode 100644
index 0000000..a8a2abf
--- /dev/null
+++ b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPGroupTest.java
@@ -0,0 +1,231 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-XACML
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.xacml.test.std.pap;
+
+import static org.junit.Assert.*;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+import org.onap.policy.xacml.api.pap.OnapPDP;
+import org.onap.policy.xacml.std.pap.StdPDP;
+import org.onap.policy.xacml.std.pap.StdPDPGroup;
+import org.onap.policy.xacml.std.pap.StdPDPGroupStatus;
+
+public class StdPDPGroupTest {
+
+
+ private static Logger logger = FlexLogger.getLogger(StdPDPGroupTest.class);
+
+ private StdPDPGroup stdPDPGroup;
+ private Path repository;
+ private StdPDP testPdp = new StdPDP();
+ private StdPDP testPdp1 = new StdPDP();
+
+ @Before
+ public void setUp(){
+
+ try {
+ stdPDPGroup = new StdPDPGroup();
+ repository = Paths.get("src/test/resources/pdps");
+ testPdp1.setId("100");
+
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+
+ @Test
+ public void testGetStatus() {
+ try {
+ assertTrue(stdPDPGroup.getStatus() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetId() {
+ try {
+ stdPDPGroup.setId("testId");
+ assertTrue(stdPDPGroup.getId() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testIsDefaultGroup() {
+ try {
+ stdPDPGroup.setDefaultGroup(true);
+ assertTrue(stdPDPGroup.isDefaultGroup() == true);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetName() {
+ try {
+ stdPDPGroup.setName("testing");
+ assertTrue(stdPDPGroup.getName() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetDescription() {
+ try {
+ stdPDPGroup.setDescription("description");
+ assertTrue(stdPDPGroup.getDescription() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetDirectory() {
+ try {
+ stdPDPGroup.setDirectory(repository);
+ assertTrue(stdPDPGroup.getDirectory() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetSelectedPolicies() {
+ try {
+ assertTrue(stdPDPGroup.getSelectedPolicies() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetOperation() {
+ try {
+ stdPDPGroup.setOperation("test");
+ assertTrue(stdPDPGroup.getOperation() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetPdps() {
+ try {
+ stdPDPGroup.setOnapPdps(new HashSet<>());
+ assertTrue(stdPDPGroup.getPdps() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetOnapPdps() {
+ try {
+ stdPDPGroup.setOnapPdps(new HashSet<>());
+ assertTrue(stdPDPGroup.getOnapPdps() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testAddPDP() {
+ try {
+ assertTrue(stdPDPGroup.addPDP(testPdp) == true);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testRemovePDP() {
+ try {
+ assertTrue(stdPDPGroup.removePDP(testPdp) == false);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetPolicies() {
+ try {
+ stdPDPGroup.setPolicies(new HashSet());
+ assertTrue(stdPDPGroup.getPolicies() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetPolicy() {
+ try {
+ assertTrue(stdPDPGroup.getPolicy("wrongId") == null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+
+ @Test
+ public void testGetPipConfigs() {
+ try {
+ stdPDPGroup.setPipConfigs(new HashSet());
+ assertTrue(stdPDPGroup.getPipConfigs() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetPipConfig() {
+ try {
+ Set pipConfigs = new HashSet();
+ StdPDP testPdp = new StdPDP();
+ testPdp.setId("20");
+ pipConfigs.add(testPdp);
+ stdPDPGroup.setId("testId");
+ assertTrue(stdPDPGroup.getPipConfig("222") == null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetPipConfigProperties() {
+ try {
+ assertTrue(stdPDPGroup.getPipConfigProperties() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+}
diff --git a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPTest.java b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPTest.java
new file mode 100644
index 0000000..628e725
--- /dev/null
+++ b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPTest.java
@@ -0,0 +1,107 @@
+package org.onap.policy.xacml.test.std.pap;
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-XACML
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+import static org.junit.Assert.*;
+
+import java.util.HashSet;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+import org.onap.policy.xacml.std.pap.StdPDP;
+import org.onap.policy.xacml.std.pap.StdPDPStatus;
+
+public class StdPDPTest {
+
+ private static Logger logger = FlexLogger.getLogger(StdPDPTest.class);
+
+ private StdPDP stdPDP;
+
+ @Before
+ public void setUp(){
+
+ try {
+ stdPDP = new StdPDP();
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetId() {
+ try {
+ stdPDP.setId("testId");
+ assertTrue(stdPDP.getId() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetName() {
+ try {
+ stdPDP.setName("abc");
+ assertTrue(stdPDP.getName() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetDescription() {
+ try {
+ stdPDP.setDescription("somee here");
+ assertTrue(stdPDP.getDescription() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetStatus() {
+ try {
+ stdPDP.setStatus(new StdPDPStatus());
+ assertTrue(stdPDP.getStatus() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetPipConfigs() {
+ try {
+ assertTrue(stdPDP.getPipConfigs() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+ @Test
+ public void testGetJmxPort() {
+ try {
+ stdPDP.setJmxPort(123);
+ assertTrue(stdPDP.getJmxPort() != null);
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+
+}
diff --git a/docs/index.rst b/docs/index.rst
index 4df15fc..f3d2bdb 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -4,6 +4,7 @@
-------------
.. toctree::
- :maxdepth: 1
+ :maxdepth: 2
-
+ platform/index
+ release-notes/index
diff --git a/docs/platform/architecture.rst b/docs/platform/architecture.rst
new file mode 100644
index 0000000..fd46637
--- /dev/null
+++ b/docs/platform/architecture.rst
@@ -0,0 +1,7 @@
+.. This work is licensed under a Creative Commons Attribution 4.0 International License.
+.. http://creativecommons.org/licenses/by/4.0
+
+
+Architecture
+------------
+Describe the architecture and design of the platform component.
diff --git a/docs/platform/index.rst b/docs/platform/index.rst
new file mode 100644
index 0000000..b489b2f
--- /dev/null
+++ b/docs/platform/index.rst
@@ -0,0 +1,12 @@
+.. This work is licensed under a Creative Commons Attribution 4.0 International License.
+
+Policy Engine
+-------------
+
+.. toctree::
+ :maxdepth: 1
+
+ architecture.rst
+ offeredapis.rst
+ installation.rst
+ policygui.rst
diff --git a/docs/platform/installation.rst b/docs/platform/installation.rst
new file mode 100644
index 0000000..3238236
--- /dev/null
+++ b/docs/platform/installation.rst
@@ -0,0 +1,14 @@
+.. This work is licensed under a Creative Commons Attribution 4.0 International License.
+.. http://creativecommons.org/licenses/by/4.0
+
+Installation
+------------
+Describe the environment and steps to install.
+
+
+Environment
++++++++++++
+
+
+Steps
++++++
diff --git a/docs/platform/offeredapis.rst b/docs/platform/offeredapis.rst
new file mode 100644
index 0000000..43a8200
--- /dev/null
+++ b/docs/platform/offeredapis.rst
@@ -0,0 +1,15 @@
+.. This work is licensed under a Creative Commons Attribution 4.0 International License.
+.. http://creativecommons.org/licenses/by/4.0
+
+
+Offered APIs
+============
+List APIs offered. One or more of the following examples may be appropriate.
+
+Example Swagger Displayed with swaggerv2doc directive
+-----------------------------------------------------
+
+.. swaggerv2doc:: http://104.239.197.207:8081/pdp/v2/api-docs
+
+End of document
+
diff --git a/docs/platform/policygui.rst b/docs/platform/policygui.rst
new file mode 100644
index 0000000..3d95579
--- /dev/null
+++ b/docs/platform/policygui.rst
@@ -0,0 +1,19 @@
+.. This work is licensed under a Creative Commons Attribution 4.0 International License.
+.. http://creativecommons.org/licenses/by/4.0
+
+Policy GUI
+----------------
+Provide info on the targeted user, interface types, ports/protocols to access, etc.
+
+Target Users
+++++++++++++
+
+Interface Type
+++++++++++++++
+
+Access
+++++++
+
+
+
+
diff --git a/docs/release-notes/bug-fixes.rst b/docs/release-notes/bug-fixes.rst
new file mode 100644
index 0000000..ee4ff9f
--- /dev/null
+++ b/docs/release-notes/bug-fixes.rst
@@ -0,0 +1,5 @@
+.. This work is licensed under a Creative Commons Attribution 4.0 International License.
+
+Bug Fixes
+---------
+
diff --git a/docs/release-notes/deprecation-notes.rst b/docs/release-notes/deprecation-notes.rst
new file mode 100644
index 0000000..e954e87
--- /dev/null
+++ b/docs/release-notes/deprecation-notes.rst
@@ -0,0 +1,5 @@
+.. This work is licensed under a Creative Commons Attribution 4.0 International License.
+
+Deprecation Notes
+-----------------
+
diff --git a/docs/release-notes/index.rst b/docs/release-notes/index.rst
new file mode 100644
index 0000000..adc76f9
--- /dev/null
+++ b/docs/release-notes/index.rst
@@ -0,0 +1,15 @@
+.. This work is licensed under a Creative Commons Attribution 4.0 International License.
+
+Release Notes
+=============
+
+.. toctree::
+ :maxdepth: 2
+
+ new-features.rst
+ bug-fixes.rst
+ known-issues.rst
+ security-issues.rst
+ upgrade-notes.rst
+ deprecation-notes.rst
+ other.rst
diff --git a/docs/release-notes/known-issues.rst b/docs/release-notes/known-issues.rst
new file mode 100644
index 0000000..01c93d1
--- /dev/null
+++ b/docs/release-notes/known-issues.rst
@@ -0,0 +1,5 @@
+.. This work is licensed under a Creative Commons Attribution 4.0 International License.
+
+Known Issues
+------------
+
diff --git a/docs/release-notes/new-features.rst b/docs/release-notes/new-features.rst
new file mode 100644
index 0000000..ab86bb9
--- /dev/null
+++ b/docs/release-notes/new-features.rst
@@ -0,0 +1,5 @@
+.. This work is licensed under a Creative Commons Attribution 4.0 International License.
+
+New Features
+------------
+
diff --git a/docs/release-notes/other.rst b/docs/release-notes/other.rst
new file mode 100644
index 0000000..2ce683b
--- /dev/null
+++ b/docs/release-notes/other.rst
@@ -0,0 +1,5 @@
+.. This work is licensed under a Creative Commons Attribution 4.0 International License.
+
+Other
+-----
+
diff --git a/docs/release-notes/security-issues.rst b/docs/release-notes/security-issues.rst
new file mode 100644
index 0000000..96e1fe9
--- /dev/null
+++ b/docs/release-notes/security-issues.rst
@@ -0,0 +1,5 @@
+.. This work is licensed under a Creative Commons Attribution 4.0 International License.
+
+Security Issues
+---------------
+
diff --git a/docs/release-notes/upgrade-notes.rst b/docs/release-notes/upgrade-notes.rst
new file mode 100644
index 0000000..f31c74a
--- /dev/null
+++ b/docs/release-notes/upgrade-notes.rst
@@ -0,0 +1,5 @@
+.. This work is licensed under a Creative Commons Attribution 4.0 International License.
+
+Upgrade Notes
+-------------
+