diff options
Diffstat (limited to 'main/src/test/java')
7 files changed, 88 insertions, 24 deletions
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java b/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java index 12d832ac..6d7b3c96 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java @@ -81,7 +81,7 @@ public class XacmlStateTest { XacmlPdpActivator.setCurrent(act); - state = new XacmlState(appmgr); + state = new XacmlState(appmgr, GROUP); } @AfterClass @@ -104,6 +104,7 @@ public class XacmlStateTest { PdpStatus status = state.genHeartbeat(); assertEquals(PdpHealthStatus.NOT_HEALTHY, status.getHealthy()); assertEquals(hostName, status.getName()); + assertEquals(GROUP, status.getPdpGroup()); assertEquals(PDP_TYPE, status.getPdpType()); assertEquals(PdpState.PASSIVE, status.getState()); assertEquals("[ToscaPolicyTypeIdentifier(name=nameA, version=typeA), " @@ -122,12 +123,13 @@ public class XacmlStateTest { public void testUpdateInternalStatePdpStateChange() { PdpStateChange req = new PdpStateChange(); req.setName(hostName); - req.setPdpGroup(GROUP); + req.setPdpGroup("wrong-pdp-group"); req.setPdpSubgroup(SUBGROUP); req.setState(STATE); PdpStatus status = state.updateInternalState(req); assertEquals(PdpState.SAFE, status.getState()); + assertEquals(GROUP, status.getPdpGroup()); PdpResponseDetails resp = status.getResponse(); assertNotNull(resp); @@ -152,7 +154,7 @@ public class XacmlStateTest { @Test public void testUpdateInternalStatePdpUpdate() { PdpUpdate req = new PdpUpdate(); - req.setPdpGroup(GROUP); + req.setPdpGroup("wrong-pdp-group"); req.setPdpSubgroup(SUBGROUP); PdpStatus status = state.updateInternalState(req, ""); @@ -171,6 +173,7 @@ public class XacmlStateTest { status = state.updateInternalState(req, "Failed to load policy: failLoadPolicy1: null"); assertEquals(status.getResponse().getResponseMessage(), "Failed to load policy: failLoadPolicy1: null"); assertEquals(status.getResponse().getResponseStatus(), PdpResponseStatus.FAIL); + assertEquals(GROUP, status.getPdpGroup()); } @Test 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 76d07045..9b13a84f 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 @@ -59,7 +59,8 @@ public class CommonTestData { 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 String PDPX_PARAMETER_GROUP_NAME = "XacmlPdpParameters"; + public static final String PDPX_GROUP = "XacmlPdpGroup"; public static final List<TopicParameters> TOPIC_PARAMS = Collections.unmodifiableList(Arrays.asList(getTopicParams())); 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 c66af0ce..0eea10a1 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 @@ -62,29 +62,30 @@ public class TestXacmlPdpParameterGroup { final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); final XacmlPdpParameterGroup pdpxParameters = - new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters, - policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); + new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, + CommonTestData.PDPX_GROUP, restServerParameters, policyApiParameters, + topicParameterGroup, applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertTrue(validationResult.isValid()); assertEquals(restServerParameters.getHost(), pdpxParameters.getRestServerParameters().getHost()); assertEquals(restServerParameters.getPort(), pdpxParameters.getRestServerParameters().getPort()); assertEquals(restServerParameters.getUserName(), pdpxParameters.getRestServerParameters().getUserName()); assertEquals(restServerParameters.getPassword(), pdpxParameters.getRestServerParameters().getPassword()); - assertEquals(CommonTestData.PDPX_GROUP_NAME, pdpxParameters.getName()); + assertEquals(CommonTestData.PDPX_PARAMETER_GROUP_NAME, pdpxParameters.getName()); assertFalse(pdpxParameters.getRestServerParameters().isHttps()); assertFalse(pdpxParameters.getRestServerParameters().isAaf()); } @Test - public void testXacmlPdpParameterGroup_NullName() { + public void testXacmlPdpParameterGroup_NullParameterGroupName() { 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, - policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); + final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(null, CommonTestData.PDPX_GROUP, + restServerParameters, policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertEquals(null, pdpxParameters.getName()); @@ -93,15 +94,15 @@ public class TestXacmlPdpParameterGroup { } @Test - public void testXacmlPdpParameterGroup_EmptyName() { + public void testXacmlPdpParameterGroup_EmptyParameterGroupName() { 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, - policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); + final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup("", CommonTestData.PDPX_GROUP, + restServerParameters, policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertEquals("", pdpxParameters.getName()); @@ -110,6 +111,44 @@ public class TestXacmlPdpParameterGroup { } @Test + public void testXacmlPdpParameterGroup_NullPdpGroup() { + 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_PARAMETER_GROUP_NAME, null, restServerParameters, + policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); + final GroupValidationResult validationResult = pdpxParameters.validate(); + assertFalse(validationResult.isValid()); + assertEquals(null, pdpxParameters.getPdpGroup()); + assertTrue(validationResult.getResult() + .contains("field \"pdpGroup\" type \"java.lang.String\" value \"null\" INVALID, " + + "must be a non-blank string")); + } + + @Test + public void testXacmlPdpParameterGroup_EmptyPdpGroup() { + 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_PARAMETER_GROUP_NAME, "", restServerParameters, + policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); + final GroupValidationResult validationResult = pdpxParameters.validate(); + assertFalse(validationResult.isValid()); + assertEquals("", pdpxParameters.getPdpGroup()); + assertTrue(validationResult.getResult() + .contains("field \"pdpGroup\" type \"java.lang.String\" value \"\" INVALID, " + + "must be a non-blank string")); + } + + @Test public void testXacmlPdpParameterGroup_EmptyRestServerParameters() { final RestServerParameters restServerParameters = testData.toObject(testData.getRestServerParametersMap(true), RestServerParameters.class); @@ -118,8 +157,9 @@ public class TestXacmlPdpParameterGroup { final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); final XacmlPdpParameterGroup pdpxParameters = - new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters, - policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); + new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, CommonTestData.PDPX_GROUP, + restServerParameters, policyApiParameters, + topicParameterGroup, applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult() @@ -135,8 +175,9 @@ public class TestXacmlPdpParameterGroup { final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); final XacmlPdpParameterGroup pdpxParameters = - new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters, - policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); + new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, CommonTestData.PDPX_GROUP, + restServerParameters, policyApiParameters, + topicParameterGroup, applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult() @@ -152,8 +193,9 @@ public class TestXacmlPdpParameterGroup { final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(true), TopicParameterGroup.class); final XacmlPdpParameterGroup pdpxParameters = - new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters, - policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath()); + new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, CommonTestData.PDPX_GROUP, + restServerParameters, policyApiParameters, + topicParameterGroup, applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult() diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java index de55282e..a59fee32 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java @@ -99,6 +99,8 @@ public class TestXacmlPdpParameterHandler { + " INVALID, parameter group has status INVALID\n" + " field \"name\" type \"java.lang.String\" value \"null\" INVALID, " + "must be a non-blank string\n" + + " field \"pdpGroup\" type \"java.lang.String\" value \"null\" INVALID, " + + "must be a non-blank string\n" + " field \"applicationPath\" type \"java.lang.String\" value \"null\" INVALID, " + "must have application path for applications to store policies and data.\n"); } @@ -111,7 +113,8 @@ public class TestXacmlPdpParameterHandler { minArguments.parse(minArgumentString); final XacmlPdpParameterGroup parGroup = new XacmlPdpParameterHandler().getParameters(minArguments); - assertEquals(CommonTestData.PDPX_GROUP_NAME, parGroup.getName()); + assertEquals(CommonTestData.PDPX_PARAMETER_GROUP_NAME, parGroup.getName()); + assertEquals(CommonTestData.PDPX_GROUP, parGroup.getPdpGroup()); } @Test @@ -123,7 +126,8 @@ public class TestXacmlPdpParameterHandler { final XacmlPdpParameterGroup parGroup = new XacmlPdpParameterHandler().getParameters(arguments); assertTrue(arguments.checkSetConfigurationFilePath()); - assertEquals(CommonTestData.PDPX_GROUP_NAME, parGroup.getName()); + assertEquals(CommonTestData.PDPX_PARAMETER_GROUP_NAME, parGroup.getName()); + assertEquals(CommonTestData.PDPX_GROUP, parGroup.getPdpGroup()); } @Test @@ -138,6 +142,17 @@ public class TestXacmlPdpParameterHandler { } @Test + public void testXacmlPdpParameterGroup_InvalidPdpGroup() throws PolicyXacmlPdpException { + final String[] xacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters_InvalidPdpGroup.json"}; + + final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments(); + arguments.parse(xacmlPdpConfigParameters); + + assertThatThrownBy(() -> new XacmlPdpParameterHandler().getParameters(arguments)).hasMessageContaining( + "field \"pdpGroup\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string"); + } + + @Test public void testXacmlPdpParameterGroup_InvalidRestServerParameters() throws PolicyXacmlPdpException, IOException { final String[] xacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json"}; 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 d416cd3b..a4469a35 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 @@ -120,7 +120,8 @@ public class TestAbbreviateDecisionResults { policyApiParameters = testData.toObject(testData.getPolicyApiParametersMap(false), RestServerParameters.class); TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); - XacmlPdpParameterGroup params = new XacmlPdpParameterGroup("XacmlPdpGroup", rest, policyApiParameters, + XacmlPdpParameterGroup params = + new XacmlPdpParameterGroup("XacmlPdpParameters", "XacmlPdpGroup", rest, policyApiParameters, topicParameterGroup, apps.getAbsolutePath()); StandardCoder gson = new StandardCoder(); File fileParams = appsFolder.newFile("params.json"); 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 6c6e35b9..e3ad7b67 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 @@ -106,7 +106,8 @@ public class TestDecision { testData.toObject(testData.getPolicyApiParametersMap(false), RestServerParameters.class); TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); - XacmlPdpParameterGroup params = new XacmlPdpParameterGroup("XacmlPdpGroup", rest, policyApiParameters, + XacmlPdpParameterGroup params = + new XacmlPdpParameterGroup("XacmlPdpParameters", "XacmlPdpGroup", rest, policyApiParameters, topicParameterGroup, apps.getAbsolutePath()); final Gson gson = new GsonBuilder().create(); File fileParams = appsFolder.newFile("params.json"); diff --git a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java index 5223bcd8..bb814d37 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java @@ -80,7 +80,8 @@ public class TestXacmlPdpActivator extends CommonRest { // XacmlPdp starts in PASSIVE state so the rest controller should not be alive assertFalse(activator.isXacmlRestControllerAlive()); assertTrue(activator.getParameterGroup().isValid()); - assertEquals(CommonTestData.PDPX_GROUP_NAME, activator.getParameterGroup().getName()); + assertEquals(CommonTestData.PDPX_PARAMETER_GROUP_NAME, activator.getParameterGroup().getName()); + assertEquals(CommonTestData.PDPX_GROUP, activator.getParameterGroup().getPdpGroup()); activator.startXacmlRestController(); assertTrue(activator.isXacmlRestControllerAlive()); |