diff options
Diffstat (limited to 'main/src/test')
12 files changed, 110 insertions, 21 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 ca8b763d..8b79ae9b 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 @@ -170,4 +170,19 @@ public class CommonTestData { } return map; } + + /** + * Returns a property map for a XacmlApplicationParameters map for test cases. + * + * @param isEmpty boolean value to represent that object created should be empty or not + * @param tempPath Application Path string + * @return a property map suitable for constructing an object + */ + public Map<String, Object> getXacmlapplicationParametersMap(boolean isEmpty, String tempPath) { + final Map<String, Object> map = new TreeMap<>(); + if (!isEmpty) { + map.put("applicationPath", tempPath); + } + return map; + } } 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 b2d1cbe3..f71c99c2 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 @@ -63,10 +63,13 @@ public class TestXacmlPdpParameterGroup { testData.toObject(testData.getPolicyApiParametersMap(false), BusTopicParams.class); final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); + final XacmlApplicationParameters xacmlApplicationParameters = + testData.toObject(testData.getXacmlapplicationParametersMap(false, + applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, CommonTestData.PDPX_GROUP, "flavor", restServerParameters, policyApiParameters, - topicParameterGroup, applicationPath.getAbsolutePath()); + topicParameterGroup, xacmlApplicationParameters); final ValidationResult validationResult = pdpxParameters.validate(); assertThat(validationResult.getResult()).isNull(); assertTrue(validationResult.isValid()); @@ -88,9 +91,11 @@ public class TestXacmlPdpParameterGroup { testData.toObject(testData.getPolicyApiParametersMap(false), BusTopicParams.class); final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); + final XacmlApplicationParameters xacmlApplicationParameters = + testData.toObject(testData.getXacmlapplicationParametersMap(false, + applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(null, CommonTestData.PDPX_GROUP, - null, restServerParameters, policyApiParameters, topicParameterGroup, - applicationPath.getAbsolutePath()); + null, restServerParameters, policyApiParameters, topicParameterGroup, xacmlApplicationParameters); final ValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertEquals(null, pdpxParameters.getName()); @@ -105,9 +110,12 @@ public class TestXacmlPdpParameterGroup { testData.toObject(testData.getPolicyApiParametersMap(false), BusTopicParams.class); final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); + final XacmlApplicationParameters xacmlApplicationParameters = + testData.toObject(testData.getXacmlapplicationParametersMap(false, + applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup("", CommonTestData.PDPX_GROUP, CommonTestData.PDPX_TYPE, restServerParameters, policyApiParameters, topicParameterGroup, - applicationPath.getAbsolutePath()); + xacmlApplicationParameters); final ValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertEquals("", pdpxParameters.getName()); @@ -122,9 +130,12 @@ public class TestXacmlPdpParameterGroup { testData.toObject(testData.getPolicyApiParametersMap(false), BusTopicParams.class); final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); + final XacmlApplicationParameters xacmlApplicationParameters = + testData.toObject(testData.getXacmlapplicationParametersMap(false, + applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, null, null, restServerParameters, - policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); + policyApiParameters, topicParameterGroup, xacmlApplicationParameters); final ValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertEquals(null, pdpxParameters.getPdpGroup()); @@ -139,9 +150,12 @@ public class TestXacmlPdpParameterGroup { testData.toObject(testData.getPolicyApiParametersMap(false), BusTopicParams.class); final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); + final XacmlApplicationParameters xacmlApplicationParameters = + testData.toObject(testData.getXacmlapplicationParametersMap(false, + applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, "", null, restServerParameters, - policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); + policyApiParameters, topicParameterGroup, xacmlApplicationParameters); final ValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertEquals("", pdpxParameters.getPdpGroup()); @@ -156,10 +170,13 @@ public class TestXacmlPdpParameterGroup { testData.toObject(testData.getPolicyApiParametersMap(false), BusTopicParams.class); final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); + final XacmlApplicationParameters xacmlApplicationParameters = + testData.toObject(testData.getXacmlapplicationParametersMap(false, + applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, CommonTestData.PDPX_GROUP, null, restServerParameters, policyApiParameters, - topicParameterGroup, applicationPath.getAbsolutePath()); + topicParameterGroup, xacmlApplicationParameters); final ValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertThat(validationResult.getResult()).contains("\"RestServerParameters\""); @@ -173,10 +190,13 @@ public class TestXacmlPdpParameterGroup { testData.toObject(testData.getPolicyApiParametersMap(true), BusTopicParams.class); final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); + final XacmlApplicationParameters xacmlApplicationParameters = + testData.toObject(testData.getXacmlapplicationParametersMap(false, + applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, CommonTestData.PDPX_GROUP, null, restServerParameters, policyApiParameters, - topicParameterGroup, applicationPath.getAbsolutePath()); + topicParameterGroup, xacmlApplicationParameters); final ValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertThat(validationResult.getResult()).contains("\"policyApiParameters\""); @@ -190,12 +210,35 @@ public class TestXacmlPdpParameterGroup { testData.toObject(testData.getPolicyApiParametersMap(false), BusTopicParams.class); final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(true), TopicParameterGroup.class); + final XacmlApplicationParameters xacmlApplicationParameters = + testData.toObject(testData.getXacmlapplicationParametersMap(false, + applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, CommonTestData.PDPX_GROUP, null, restServerParameters, policyApiParameters, - topicParameterGroup, applicationPath.getAbsolutePath()); + topicParameterGroup, xacmlApplicationParameters); final ValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertThat(validationResult.getResult()).contains("\"TopicParameterGroup\""); } + + @Test + public void testXacmlPdpParameterGroup_EmptyApplicationParameterGroup() { + final RestServerParameters restServerParameters = + testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class); + final BusTopicParams policyApiParameters = + testData.toObject(testData.getPolicyApiParametersMap(false), BusTopicParams.class); + final TopicParameterGroup topicParameterGroup = + testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); + final XacmlApplicationParameters xacmlApplicationParameters = + testData.toObject(testData.getXacmlapplicationParametersMap(true, + applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class); + final XacmlPdpParameterGroup pdpxParameters = + new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, CommonTestData.PDPX_GROUP, + null, restServerParameters, policyApiParameters, + topicParameterGroup, xacmlApplicationParameters); + final ValidationResult validationResult = pdpxParameters.validate(); + assertFalse(validationResult.isValid()); + assertThat(validationResult.getResult()).contains("\"XacmlApplicationParameters\""); + } } diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java index 93e541de..54d7432f 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java @@ -64,6 +64,7 @@ import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils; import org.onap.policy.pdp.xacml.xacmltest.TestUtils; import org.onap.policy.pdpx.main.PolicyXacmlPdpException; import org.onap.policy.pdpx.main.parameters.CommonTestData; +import org.onap.policy.pdpx.main.parameters.XacmlApplicationParameters; import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup; import org.onap.policy.pdpx.main.startstop.Main; import org.onap.policy.pdpx.main.startstop.XacmlPdpActivator; @@ -119,9 +120,12 @@ public class TestAbbreviateDecisionResults { policyApiParameters = testData.toObject(testData.getPolicyApiParametersMap(false), BusTopicParams.class); TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); + final XacmlApplicationParameters xacmlApplicationParameters = + testData.toObject(testData.getXacmlapplicationParametersMap(false, + apps.getAbsolutePath().toString()), XacmlApplicationParameters.class); XacmlPdpParameterGroup params = new XacmlPdpParameterGroup("XacmlPdpParameters", "XacmlPdpGroup", "xacml", rest, policyApiParameters, - topicParameterGroup, apps.getAbsolutePath()); + topicParameterGroup, xacmlApplicationParameters); StandardCoder gson = new StandardCoder(); File fileParams = appsFolder.newFile("params.json"); String jsonParams = gson.encode(params); 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 7fa552f4..5f6a2796 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 @@ -59,6 +59,7 @@ import org.onap.policy.models.decisions.concepts.DecisionResponse; import org.onap.policy.models.errors.concepts.ErrorResponse; import org.onap.policy.pdpx.main.PolicyXacmlPdpException; import org.onap.policy.pdpx.main.parameters.CommonTestData; +import org.onap.policy.pdpx.main.parameters.XacmlApplicationParameters; import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup; import org.onap.policy.pdpx.main.startstop.Main; import org.onap.policy.pdpx.main.startstop.XacmlPdpActivator; @@ -108,9 +109,12 @@ public class TestDecision { testData.toObject(testData.getPolicyApiParametersMap(false), BusTopicParams.class); TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); + final XacmlApplicationParameters xacmlApplicationParameters = + testData.toObject(testData.getXacmlapplicationParametersMap(false, + apps.getAbsolutePath().toString()), XacmlApplicationParameters.class); XacmlPdpParameterGroup params = new XacmlPdpParameterGroup("XacmlPdpParameters", "XacmlPdpGroup", "xacml", rest, policyApiParameters, - topicParameterGroup, apps.getAbsolutePath()); + topicParameterGroup, xacmlApplicationParameters); final Gson gson = new GsonBuilder().create(); File fileParams = appsFolder.newFile("params.json"); String jsonParams = gson.toJson(params); diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java index 1673c043..4619b2ae 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java @@ -44,6 +44,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; import org.onap.policy.pdp.xacml.application.common.XacmlApplicationException; +import org.onap.policy.pdpx.main.parameters.CommonTestData; +import org.onap.policy.pdpx.main.parameters.XacmlApplicationParameters; import org.onap.policy.xacml.pdp.application.guard.GuardPdpApplication; import org.onap.policy.xacml.pdp.application.nativ.NativePdpApplication; import org.onap.policy.xacml.pdp.application.optimization.OptimizationPdpApplication; @@ -56,6 +58,7 @@ public class XacmlPdpApplicationManagerTest { private static final BusTopicParams params = new BusTopicParams(); private static Path appsDirectory; private static ToscaServiceTemplate completedJtst; + private static CommonTestData testData = new CommonTestData(); @ClassRule public static final TemporaryFolder appsFolder = new TemporaryFolder(); @@ -113,10 +116,13 @@ public class XacmlPdpApplicationManagerTest { // Make up a non existent directory to initialize from // Path nonExistentPath = Paths.get(appsFolder.getRoot().getAbsolutePath(), "nonexistent"); + final XacmlApplicationParameters xacmlApplicationParameters = + testData.toObject(testData.getXacmlapplicationParametersMap(false, + nonExistentPath.toString()), XacmlApplicationParameters.class); // // Create our app manager // - XacmlPdpApplicationManager manager = new XacmlPdpApplicationManager(nonExistentPath, params); + XacmlPdpApplicationManager manager = new XacmlPdpApplicationManager(xacmlApplicationParameters, params); // // Still creates the manager, but the apps were not able to initialize // @@ -126,7 +132,7 @@ public class XacmlPdpApplicationManagerTest { // Now create the directory // Files.createDirectory(nonExistentPath); - manager = new XacmlPdpApplicationManager(nonExistentPath, params); + manager = new XacmlPdpApplicationManager(xacmlApplicationParameters, params); // // Now it should have initialized the apps // @@ -136,7 +142,10 @@ public class XacmlPdpApplicationManagerTest { @Test public void testXacmlPdpApplicationManagerSimple() { - XacmlPdpApplicationManager manager = new XacmlPdpApplicationManager(appsDirectory, params); + final XacmlApplicationParameters xacmlApplicationParameters = + testData.toObject(testData.getXacmlapplicationParametersMap(false, + appsDirectory.toString()), XacmlApplicationParameters.class); + XacmlPdpApplicationManager manager = new XacmlPdpApplicationManager(xacmlApplicationParameters, params); // // Test the basics from the startup // diff --git a/main/src/test/resources/parameters/MinimumParameters.json b/main/src/test/resources/parameters/MinimumParameters.json index 48706b85..81e83522 100644 --- a/main/src/test/resources/parameters/MinimumParameters.json +++ b/main/src/test/resources/parameters/MinimumParameters.json @@ -14,7 +14,9 @@ "userName": "healthcheck", "password": "zb!XztG34" }, - "applicationPath": "apps.test", + "applicationParameters": { + "applicationPath": "apps.test" + }, "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 9ccd732b..a1b9be9d 100644 --- a/main/src/test/resources/parameters/XacmlPdpConfigParameters.json +++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters.json @@ -14,7 +14,9 @@ "userName": "healthcheck", "password": "zb!XztG34" }, - "applicationPath": "src/test/resources/apps", + "applicationParameters": { + "applicationPath": "src/test/resources/apps" + }, "topicParameterGroup": { "topicSources" : [{ "topic" : "POLICY-PDP-PAP", diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidName.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidName.json index ca779723..c78dbed7 100644 --- a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidName.json +++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidName.json @@ -14,7 +14,9 @@ "userName": "healthcheck", "password": "zb!XztG34" }, - "applicationPath": "src/test/resources/apps", + "applicationParameters": { + "applicationPath": "src/test/resources/apps" + }, "topicParameterGroup": { "topicSources" : [{ "topic" : "POLICY-PDP-PAP", diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidPdpGroup.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidPdpGroup.json index 3e1d4f57..2a249f0d 100644 --- a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidPdpGroup.json +++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidPdpGroup.json @@ -14,7 +14,9 @@ "userName": "healthcheck", "password": "zb!XztG34" }, - "applicationPath": "src/test/resources/apps", + "applicationParameters": { + "applicationPath": "src/test/resources/apps" + }, "topicParameterGroup": { "topicSources" : [{ "topic" : "POLICY-PDP-PAP", diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidPdpType.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidPdpType.json index d0c429c2..75111f71 100644 --- a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidPdpType.json +++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidPdpType.json @@ -15,7 +15,9 @@ "userName": "healthcheck", "password": "zb!XztG34" }, - "applicationPath": "src/test/resources/apps", + "applicationParameters": { + "applicationPath": "src/test/resources/apps" + }, "topicParameterGroup": { "topicSources" : [{ "topic" : "POLICY-PDP-PAP", diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json index 8211c8e6..9e05b14f 100644 --- a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json +++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json @@ -13,7 +13,9 @@ "userName": "healthcheck", "password": "zb!XztG34" }, - "applicationPath": "src/test/resources/apps", + "applicationParameters": { + "applicationPath": "src/test/resources/apps" + }, "topicParameterGroup": { "topicSources" : [{ "topic" : "POLICY-PDP-PAP", diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json index 33885b50..a0608862 100644 --- a/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json +++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json @@ -15,7 +15,9 @@ "userName": "healthcheck", "password": "zb!XztG34" }, - "applicationPath": "src/test/resources/apps", + "applicationParameters": { + "applicationPath": "src/test/resources/apps" + }, "topicParameterGroup": { "topicSources" : [{ "topic" : "POLICY-PDP-PAP", |