aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterGroup.java67
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java66
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java45
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java8
-rw-r--r--main/src/test/resources/parameters/MinimumParameters.json8
-rw-r--r--main/src/test/resources/parameters/NoParameters.json6
-rw-r--r--main/src/test/resources/parameters/XacmlPdpConfigParameters.json6
-rw-r--r--main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidName.json26
-rw-r--r--main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json19
-rw-r--r--main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json6
10 files changed, 178 insertions, 79 deletions
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterGroup.java b/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterGroup.java
index 167a2c45..5731a7b2 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterGroup.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterGroup.java
@@ -21,6 +21,8 @@
package org.onap.policy.pdpx.main.parameters;
+import lombok.Getter;
+import lombok.Setter;
import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
import org.onap.policy.common.parameters.GroupValidationResult;
@@ -32,12 +34,18 @@ import org.onap.policy.common.utils.validation.ParameterValidationUtils;
* Class to hold all parameters needed for xacml pdp component.
*
*/
+@Getter
public class XacmlPdpParameterGroup implements ParameterGroup {
private static final String PARAM_REST_SERVER = "restServerParameters";
+ private static final String PARAM_POLICY_API = "policyApiParameters";
private static final String PARAM_TOPIC_PARAMETER_GROUP = "topicParameterGroup";
private static final String PARAM_APPLICATION_PATH = "applicationPath";
+
+ @Setter
private String name;
+
private RestServerParameters restServerParameters;
+ private RestServerParameters policyApiParameters;
private TopicParameterGroup topicParameterGroup;
private String applicationPath;
@@ -47,61 +55,16 @@ public class XacmlPdpParameterGroup implements ParameterGroup {
* @param name the parameter group name
*/
public XacmlPdpParameterGroup(final String name, final RestServerParameters restServerParameters,
- final TopicParameterGroup topicParameterGroup, final String applicationPath) {
+ final RestServerParameters policyApiParameters, final TopicParameterGroup topicParameterGroup,
+ final String applicationPath) {
this.name = name;
this.restServerParameters = restServerParameters;
+ this.policyApiParameters = policyApiParameters;
this.topicParameterGroup = topicParameterGroup;
this.applicationPath = applicationPath;
}
/**
- * Return the name of this parameter group instance.
- *
- * @return name the parameter group name
- */
- @Override
- public String getName() {
- return name;
- }
-
- /**
- * Set the name of this parameter group instance.
- *
- * @param name the parameter group name
- */
- @Override
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * Return the restServerParameters of this parameter group instance.
- *
- * @return the restServerParameters
- */
- public RestServerParameters getRestServerParameters() {
- return restServerParameters;
- }
-
- /**
- * Return the topicParameterGroup of this parameter group instance.
- *
- * @return the topicParameterGroup
- */
- public TopicParameterGroup getTopicParameterGroup() {
- return topicParameterGroup;
- }
-
- /**
- * Returns the path where applications will store their data.
- *
- * @return String to the path
- */
- public String getApplicationPath() {
- return applicationPath;
- }
-
- /**
* Validate the parameter group.
*
* @return the result of the validation
@@ -118,6 +81,14 @@ public class XacmlPdpParameterGroup implements ParameterGroup {
} else {
validationResult.setResult(PARAM_REST_SERVER, restServerParameters.validate());
}
+ if (policyApiParameters == null) {
+ validationResult.setResult(PARAM_POLICY_API, ValidationStatus.INVALID,
+ "must have policyApiParameters to configure xacml pdp rest server");
+ } else {
+ // set the name - this only really matters for validation messages
+ policyApiParameters.setName(PARAM_POLICY_API);
+ validationResult.setResult(PARAM_POLICY_API, policyApiParameters.validate());
+ }
if (topicParameterGroup == null) {
validationResult.setResult(PARAM_TOPIC_PARAMETER_GROUP, ValidationStatus.INVALID,
"must have topicParameterGroup to configure xacml pdp topic sink and source");
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
index fd79035e..76d07045 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
@@ -22,6 +22,7 @@
package org.onap.policy.pdpx.main.parameters;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -37,14 +38,30 @@ import org.onap.policy.common.utils.coder.StandardCoder;
*/
public class CommonTestData {
- private static final String REST_SERVER_PASSWORD = "zb!XztG34";
+ private static final String PASS_KEY = "password";
+ private static final String USER_KEY = "userName";
+ private static final String PORT_KEY = "port";
+ private static final String HOST_KEY = "host";
+ private static final String AAF_KEY = "aaf";
+ private static final String HTTPS_KEY = "https";
+
+ private static final String REST_SERVER_PASS = "zb!XztG34";
private static final String REST_SERVER_USER = "healthcheck";
private static final int REST_SERVER_PORT = 6969;
private static final String REST_SERVER_HOST = "0.0.0.0";
private static final boolean REST_SERVER_HTTPS = false;
private static final boolean REST_SERVER_AAF = false;
+
+ private static final String POLICY_API_PASS = "zb!XztG34";
+ private static final String POLICY_API_USER = "healthcheck";
+ private static final int POLICY_API_PORT = 6970;
+ private static final String POLICY_API_HOST = "0.0.0.0";
+ private static final boolean POLICY_API_HTTPS = false;
+ private static final boolean POLICY_API_AAF = false;
+
public static final String PDPX_GROUP_NAME = "XacmlPdpGroup";
- public static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParams());
+ public static final List<TopicParameters> TOPIC_PARAMS =
+ Collections.unmodifiableList(Arrays.asList(getTopicParams()));
public static final Coder coder = new StandardCoder();
@@ -69,14 +86,14 @@ public class CommonTestData {
*/
public Map<String, Object> getRestServerParametersMap(final boolean isEmpty) {
final Map<String, Object> map = new TreeMap<>();
- map.put("https", REST_SERVER_HTTPS);
- map.put("aaf", REST_SERVER_AAF);
+ map.put(HTTPS_KEY, REST_SERVER_HTTPS);
+ map.put(AAF_KEY, REST_SERVER_AAF);
if (!isEmpty) {
- map.put("host", REST_SERVER_HOST);
- map.put("port", REST_SERVER_PORT);
- map.put("userName", REST_SERVER_USER);
- map.put("password", REST_SERVER_PASSWORD);
+ map.put(HOST_KEY, REST_SERVER_HOST);
+ map.put(PORT_KEY, REST_SERVER_PORT);
+ map.put(USER_KEY, REST_SERVER_USER);
+ map.put(PASS_KEY, REST_SERVER_PASS);
}
return map;
@@ -90,12 +107,12 @@ public class CommonTestData {
*/
public Map<String, Object> getRestServerParametersMap(final int port) {
final Map<String, Object> map = new TreeMap<>();
- map.put("https", REST_SERVER_HTTPS);
- map.put("aaf", REST_SERVER_AAF);
- map.put("host", REST_SERVER_HOST);
- map.put("port", port);
- map.put("userName", REST_SERVER_USER);
- map.put("password", REST_SERVER_PASSWORD);
+ map.put(HTTPS_KEY, REST_SERVER_HTTPS);
+ map.put(AAF_KEY, REST_SERVER_AAF);
+ map.put(HOST_KEY, REST_SERVER_HOST);
+ map.put(PORT_KEY, port);
+ map.put(USER_KEY, REST_SERVER_USER);
+ map.put(PASS_KEY, REST_SERVER_PASS);
return map;
}
@@ -117,6 +134,27 @@ public class CommonTestData {
}
/**
+ * Returns a property map for a RestServerParameters map for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return a property map suitable for constructing an object
+ */
+ public Map<String, Object> getPolicyApiParametersMap(final boolean isEmpty) {
+ final Map<String, Object> map = new TreeMap<>();
+ map.put(HTTPS_KEY, POLICY_API_HTTPS);
+ map.put(AAF_KEY, POLICY_API_AAF);
+
+ if (!isEmpty) {
+ map.put(HOST_KEY, POLICY_API_HOST);
+ map.put(PORT_KEY, POLICY_API_PORT);
+ map.put(USER_KEY, POLICY_API_USER);
+ map.put(PASS_KEY, POLICY_API_PASS);
+ }
+
+ return map;
+ }
+
+ /**
* Returns a property map for a TopicParameters map for test cases.
*
* @param isEmpty boolean value to represent that object created should be empty or not
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
index 1484edfd..c66af0ce 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
@@ -57,11 +57,13 @@ public class TestXacmlPdpParameterGroup {
public void testXacmlPdpParameterGroup() throws IOException {
final RestServerParameters restServerParameters =
testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
+ final RestServerParameters policyApiParameters =
+ testData.toObject(testData.getPolicyApiParametersMap(false), RestServerParameters.class);
final TopicParameterGroup topicParameterGroup =
testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlPdpParameterGroup pdpxParameters =
- new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME,
- restServerParameters, topicParameterGroup, applicationPath.getAbsolutePath());
+ new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters,
+ policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath());
final GroupValidationResult validationResult = pdpxParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(restServerParameters.getHost(), pdpxParameters.getRestServerParameters().getHost());
@@ -77,10 +79,12 @@ public class TestXacmlPdpParameterGroup {
public void testXacmlPdpParameterGroup_NullName() {
final RestServerParameters restServerParameters =
testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
+ final RestServerParameters policyApiParameters =
+ testData.toObject(testData.getPolicyApiParametersMap(false), RestServerParameters.class);
final TopicParameterGroup topicParameterGroup =
testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(null, restServerParameters,
- topicParameterGroup, applicationPath.getAbsolutePath());
+ policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath());
final GroupValidationResult validationResult = pdpxParameters.validate();
assertFalse(validationResult.isValid());
assertEquals(null, pdpxParameters.getName());
@@ -92,10 +96,12 @@ public class TestXacmlPdpParameterGroup {
public void testXacmlPdpParameterGroup_EmptyName() {
final RestServerParameters restServerParameters =
testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
+ final RestServerParameters policyApiParameters =
+ testData.toObject(testData.getPolicyApiParametersMap(false), RestServerParameters.class);
final TopicParameterGroup topicParameterGroup =
testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup("", restServerParameters,
- topicParameterGroup, applicationPath.getAbsolutePath());
+ policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath());
final GroupValidationResult validationResult = pdpxParameters.validate();
assertFalse(validationResult.isValid());
assertEquals("", pdpxParameters.getName());
@@ -107,31 +113,50 @@ public class TestXacmlPdpParameterGroup {
public void testXacmlPdpParameterGroup_EmptyRestServerParameters() {
final RestServerParameters restServerParameters =
testData.toObject(testData.getRestServerParametersMap(true), RestServerParameters.class);
+ final RestServerParameters policyApiParameters =
+ testData.toObject(testData.getPolicyApiParametersMap(false), RestServerParameters.class);
final TopicParameterGroup topicParameterGroup =
testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlPdpParameterGroup pdpxParameters =
new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters,
- topicParameterGroup, applicationPath.getAbsolutePath());
+ policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath());
final GroupValidationResult validationResult = pdpxParameters.validate();
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
- .contains("\"org.onap.policy.common.endpoints.parameters.RestServerParameters\" INVALID, "
- + "parameter group has status INVALID"));
+ .contains("parameter group \"RestServerParameters\""));
+ }
+
+ @Test
+ public void testXacmlPdpParameterGroup_EmptyPolicyApiParameters() {
+ final RestServerParameters restServerParameters =
+ testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
+ final RestServerParameters policyApiParameters =
+ testData.toObject(testData.getPolicyApiParametersMap(true), RestServerParameters.class);
+ final TopicParameterGroup topicParameterGroup =
+ testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
+ final XacmlPdpParameterGroup pdpxParameters =
+ new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters,
+ policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath());
+ final GroupValidationResult validationResult = pdpxParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("parameter group \"policyApiParameters\""));
}
@Test
public void testXacmlPdpParameterGroup_EmptyTopicParameterGroup() {
final RestServerParameters restServerParameters =
testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
+ final RestServerParameters policyApiParameters =
+ testData.toObject(testData.getPolicyApiParametersMap(false), RestServerParameters.class);
final TopicParameterGroup topicParameterGroup =
testData.toObject(testData.getTopicParametersMap(true), TopicParameterGroup.class);
final XacmlPdpParameterGroup pdpxParameters =
new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters,
- topicParameterGroup, applicationPath.getAbsolutePath());
+ policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath());
final GroupValidationResult validationResult = pdpxParameters.validate();
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
- .contains("\"org.onap.policy.common.endpoints.parameters.TopicParameterGroup\" INVALID, "
- + "parameter group has status INVALID"));
+ .contains("parameter group \"TopicParameterGroup\""));
}
}
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java
index 0edfc6f5..5f75e6dd 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java
@@ -101,10 +101,12 @@ public class TestDecision {
//
RestServerParameters rest =
testData.toObject(testData.getRestServerParametersMap(port), RestServerParameters.class);
+ RestServerParameters policyApiParameters =
+ testData.toObject(testData.getPolicyApiParametersMap(false), RestServerParameters.class);
TopicParameterGroup topicParameterGroup =
- testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
- XacmlPdpParameterGroup params =
- new XacmlPdpParameterGroup("XacmlPdpGroup", rest, topicParameterGroup, apps.getAbsolutePath());
+ testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
+ XacmlPdpParameterGroup params = new XacmlPdpParameterGroup("XacmlPdpGroup", rest, policyApiParameters,
+ topicParameterGroup, apps.getAbsolutePath());
final Gson gson = new GsonBuilder().create();
File fileParams = appsFolder.newFile("params.json");
String jsonParams = gson.toJson(params);
diff --git a/main/src/test/resources/parameters/MinimumParameters.json b/main/src/test/resources/parameters/MinimumParameters.json
index 6ae2aa94..42e54581 100644
--- a/main/src/test/resources/parameters/MinimumParameters.json
+++ b/main/src/test/resources/parameters/MinimumParameters.json
@@ -6,8 +6,14 @@
"userName": "healthcheck",
"password": "zb!XztG34"
},
+ "policyApiParameters": {
+ "host": "0.0.0.0",
+ "port": 6970,
+ "userName": "healthcheck",
+ "password": "zb!XztG34"
+ },
"applicationPath": "apps.test",
- "topicParameterGroup": {
+ "topicParameterGroup": {
"topicSources" : [{
"topic" : "POLICY-PDP-PAP",
"servers" : [ "anyserver" ],
diff --git a/main/src/test/resources/parameters/NoParameters.json b/main/src/test/resources/parameters/NoParameters.json
index 953f70e7..1b25951c 100644
--- a/main/src/test/resources/parameters/NoParameters.json
+++ b/main/src/test/resources/parameters/NoParameters.json
@@ -5,6 +5,12 @@
"userName": "healthcheck",
"password": "zb!XztG34"
},
+ "policyApiParameters": {
+ "host": "0.0.0.0",
+ "port": 6970,
+ "userName": "healthcheck",
+ "password": "zb!XztG34"
+ },
"topicParameterGroup": {
"topicSources" : [{
"topic" : "POLICY-PDP-PAP",
diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters.json
index e5ab198b..186a7b26 100644
--- a/main/src/test/resources/parameters/XacmlPdpConfigParameters.json
+++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters.json
@@ -6,6 +6,12 @@
"userName": "healthcheck",
"password": "zb!XztG34"
},
+ "policyApiParameters": {
+ "host": "0.0.0.0",
+ "port": 6970,
+ "userName": "healthcheck",
+ "password": "zb!XztG34"
+ },
"applicationPath": "src/test/resources/apps",
"topicParameterGroup": {
"topicSources" : [{
diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidName.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidName.json
index 8949a3c4..27e7ef46 100644
--- a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidName.json
+++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidName.json
@@ -1,9 +1,29 @@
{
"name": " ",
- "restServerParameters": {
- "host": "0.0.0.0",
+ "restServerParameters":{
+ "host":"0.0.0.0",
"port": 6969,
+ "userName":"healthcheck",
+ "password":"zb!XztG34",
+ "https":true
+ },
+ "policyApiParameters": {
+ "host": "0.0.0.0",
+ "port": 6970,
"userName": "healthcheck",
"password": "zb!XztG34"
+ },
+ "applicationPath": "src/test/resources/apps",
+ "topicParameterGroup": {
+ "topicSources" : [{
+ "topic" : "POLICY-PDP-PAP",
+ "servers" : [ "anyserver" ],
+ "topicCommInfrastructure" : "noop"
+ }],
+ "topicSinks" : [{
+ "topic" : "POLICY-PDP-PAP",
+ "servers" : [ "anyserver" ],
+ "topicCommInfrastructure" : "noop"
+ }]
}
-}
+} \ No newline at end of file
diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json
index 8b8e5c67..d320b11d 100644
--- a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json
+++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json
@@ -5,5 +5,24 @@
"port": -1,
"userName": "",
"password": ""
+ },
+ "policyApiParameters": {
+ "host": "0.0.0.0",
+ "port": 6970,
+ "userName": "healthcheck",
+ "password": "zb!XztG34"
+ },
+ "applicationPath": "src/test/resources/apps",
+ "topicParameterGroup": {
+ "topicSources" : [{
+ "topic" : "POLICY-PDP-PAP",
+ "servers" : [ "anyserver" ],
+ "topicCommInfrastructure" : "noop"
+ }],
+ "topicSinks" : [{
+ "topic" : "POLICY-PDP-PAP",
+ "servers" : [ "anyserver" ],
+ "topicCommInfrastructure" : "noop"
+ }]
}
}
diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json
index 2d1f7cde..1c17414b 100644
--- a/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json
+++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json
@@ -7,6 +7,12 @@
"password":"zb!XztG34",
"https":true
},
+ "policyApiParameters": {
+ "host": "0.0.0.0",
+ "port": 6970,
+ "userName": "healthcheck",
+ "password": "zb!XztG34"
+ },
"applicationPath": "src/test/resources/apps",
"topicParameterGroup": {
"topicSources" : [{