diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2021-07-13 10:12:14 -0400 |
---|---|---|
committer | Pamela Dragosh <pd1248@att.com> | 2021-07-13 10:29:14 -0400 |
commit | 6803c3b370560217215be30514396f75be780a0f (patch) | |
tree | 9752d4f298d41d1914ef31843fb1c2b76098844e /main/src/test/java/org | |
parent | ab0c6ca485c20fea9bcf894d27e0935afda17042 (diff) |
Change config to add Application group
First step for configuration which applications should
be loaded and mapped to actions is to add a new parameter
group for application parameters.
Issue-ID: POLICY-3326
Change-Id: I3867b4e927d57e1e81519dee32d10eed3dabc667
Signed-off-by: Pamela Dragosh <pd1248@att.com>
Diffstat (limited to 'main/src/test/java/org')
5 files changed, 89 insertions, 14 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 // |