diff options
author | Jim Hahn <jrh3@att.com> | 2019-08-28 15:20:18 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-08-30 12:07:32 -0400 |
commit | 98873e8c202426b9d74d9460ebd30b57fa4c7eb7 (patch) | |
tree | db56b53965c37b36008c99c49acf9e5d079c2fbf /main/src/test | |
parent | 30b9aa0d2e2e6b954e2ce25537d7d7ca81d3a5a4 (diff) |
Get policy type from policy-api
Added a class to retrieve a policy type from the policy-api.
Updated property files to include parameters that are needed
to configure it.
Updates per review comments:
- change PolicyApi to PolicyApiCaller
- use HttpClientFactory
- removed superfluous constructors from exception classes
- changed parameters to use RestServerParameters instead of BusTopicParams
Change-Id: I8aad6ca5a733c8ad9cc983496e745ebe7400dd17
Issue-ID: POLICY-1911
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src/test')
9 files changed, 159 insertions, 31 deletions
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" : [{ |