diff options
author | mmis <michael.morris@ericsson.com> | 2018-09-05 17:12:03 +0100 |
---|---|---|
committer | mmis <michael.morris@ericsson.com> | 2018-09-05 17:34:25 +0100 |
commit | 0089e8bc429001eca2997b44168b05889cb75d38 (patch) | |
tree | 943152987d7aa192fa35bdd76db713bec2463d55 /main/src/test/java/org/onap | |
parent | 461cafda67a99f4cc27ea41539d1748b6c87a79c (diff) |
Refactored reception handler parameter handling
Refactored parameter handling for configuration of reception handlers as
the previous implementation does not align with the plugin architecture
(.e. plugin specific parameters being handled in core code)
Issue-ID: POLICY-1094
Change-Id: I31a9fc7f712ca43f0f69c42a6d99fa481b02cd4b
Signed-off-by: mmis <michael.morris@ericsson.com>
Diffstat (limited to 'main/src/test/java/org/onap')
4 files changed, 251 insertions, 126 deletions
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java index 186aa821..b1903152 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java +++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java @@ -27,9 +27,11 @@ import java.util.Map; import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters; import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup; import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup.DummyPolicyForwarderParameterGroupBuilder; +import org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup; +import org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup.DummyReceptionHandlerParameterGroupBuilder; import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters; import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters; -import org.onap.policy.distribution.reception.parameters.PssdConfigurationParametersGroup; +import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup; import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters; /** @@ -54,6 +56,11 @@ public class CommonTestData { public static final String RECEPTION_HANDLER_TYPE = "DummyReceptionHandler"; public static final String RECEPTION_HANDLER_CLASS_NAME = "org.onap.policy.distribution.main.testclasses.DummyReceptionHandler"; + public static final String RECEPTION_CONFIGURATION_PARAMETERS = "dummyReceptionHandlerConfiguration"; + public static final String MY_STRING_PARAMETER_VALUE = "aStringValue"; + public static final Boolean MY_BOOLEAN_PARAMETER_VALUE = true; + public static final int MY_INTEGER_PARAMETER_VALUE = 1234; + public static final String DUMMY_RECEPTION_HANDLER_KEY = "DummyReceptionHandler"; public static final String DUMMY_ENGINE_FORWARDER_KEY = "DummyForwarder"; public static final String DUMMY_DECODER_KEY = "DummyDecoder"; @@ -87,38 +94,37 @@ public class CommonTestData { if (!isEmpty) { final Map<String, PolicyDecoderParameters> policyDecoders = getPolicyDecoders(isEmpty); final Map<String, PolicyForwarderParameters> policyForwarders = getPolicyForwarders(isEmpty); - final PssdConfigurationParametersGroup pssdConfiguration = getPssdConfigurationParametersGroup(isEmpty);; final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyDecoders, policyForwarders); final ReceptionHandlerParameters rhParameters = new ReceptionHandlerParameters(RECEPTION_HANDLER_TYPE, - RECEPTION_HANDLER_CLASS_NAME, pssdConfiguration, pHParameters); + RECEPTION_HANDLER_CLASS_NAME, RECEPTION_CONFIGURATION_PARAMETERS, pHParameters); receptionHandlerParameters.put(DUMMY_RECEPTION_HANDLER_KEY, rhParameters); } return receptionHandlerParameters; } /** - * Returns an instance of PssdConfigurationParametersGroup for test cases. + * Returns ReceptionHandlerConfigurationParameterGroups for test cases. * * @param isEmpty boolean value to represent that object created should be empty or not - * @return the PssdConfigurationParametersGroup object + * @return the ReceptionHandlerConfigurationParameterGroups */ - public PssdConfigurationParametersGroup getPssdConfigurationParametersGroup(final boolean isEmpty) { - final PssdConfigurationParametersGroup pssdConfiguration; + public Map<String, ReceptionHandlerConfigurationParameterGroup> getReceptionHandlerConfigurationParameters( + final boolean isEmpty) { + final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurationParameters = + new HashMap<String, ReceptionHandlerConfigurationParameterGroup>(); if (!isEmpty) { final List<String> messageBusAddress = new ArrayList<>(); messageBusAddress.add("localhost"); final List<String> artifactTypes = new ArrayList<>(); artifactTypes.add("TOSCA_CSAR"); - pssdConfiguration = new PssdConfigurationParametersGroup.PssdConfigurationBuilder() - .setAsdcAddress("localhost").setMessageBusAddress(messageBusAddress).setUser("policy") - .setPassword("policy").setPollingInterval(20).setPollingTimeout(30).setConsumerId("policy-id") - .setArtifactTypes(artifactTypes).setConsumerGroup("policy-group").setEnvironmentName("TEST") - .setKeystorePath("").setKeystorePassword("").setActiveserverTlsAuth(false) - .setIsFilterinEmptyResources(true).setIsUseHttpsWithDmaap(false).build(); - } else { - pssdConfiguration = new PssdConfigurationParametersGroup.PssdConfigurationBuilder().build(); + DummyReceptionHandlerParameterGroup dummyReceptionHandlerParameterGroup = + new DummyReceptionHandlerParameterGroupBuilder().setMyStringParameter(MY_STRING_PARAMETER_VALUE) + .setMyIntegerParameter(MY_INTEGER_PARAMETER_VALUE) + .setMyBooleanParameter(MY_BOOLEAN_PARAMETER_VALUE).build(); + receptionHandlerConfigurationParameters.put(RECEPTION_CONFIGURATION_PARAMETERS, + dummyReceptionHandlerParameterGroup); } - return pssdConfiguration; + return receptionHandlerConfigurationParameters; } /** diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java index 0c8c80d6..2df1cd47 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java +++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java @@ -29,6 +29,8 @@ import java.util.Map; import org.junit.Test; import org.onap.policy.common.parameters.GroupValidationResult; import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup; +import org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup; +import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup; import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters; /** @@ -42,36 +44,50 @@ public class TestDistributionParameterGroup { @Test public void testDistributionParameterGroup() { final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false); - final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = commonTestData - .getReceptionHandlerParameters(false); + final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = + commonTestData.getReceptionHandlerParameters(false); + final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurations = + commonTestData.getReceptionHandlerConfigurationParameters(false); final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations = commonTestData.getPolicyForwarderConfigurationParameters(false); final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, - receptionHandlerParameters, forwarderConfigurations); + receptionHandlerParameters, receptionHandlerConfigurations, forwarderConfigurations); final GroupValidationResult validationResult = distributionParameters.validate(); assertTrue(validationResult.isValid()); assertEquals(restServerParameters.getHost(), distributionParameters.getRestServerParameters().getHost()); assertEquals(restServerParameters.getPort(), distributionParameters.getRestServerParameters().getPort()); assertEquals(restServerParameters.getUserName(), - distributionParameters.getRestServerParameters().getUserName()); + distributionParameters.getRestServerParameters().getUserName()); assertEquals(restServerParameters.getPassword(), - distributionParameters.getRestServerParameters().getPassword()); + distributionParameters.getRestServerParameters().getPassword()); assertEquals(CommonTestData.DISTRIBUTION_GROUP_NAME, distributionParameters.getName()); - assertEquals(receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) - .getReceptionHandlerType(), - distributionParameters.getReceptionHandlerParameters() - .get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getReceptionHandlerType()); - assertEquals(receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) + assertEquals( + receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getReceptionHandlerType(), + distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) + .getReceptionHandlerType()); + assertEquals( + receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) .getReceptionHandlerClassName(), - distributionParameters.getReceptionHandlerParameters() - .get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) - .getReceptionHandlerClassName()); - assertEquals(receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) - .getPluginHandlerParameters(), - distributionParameters.getReceptionHandlerParameters() - .get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getPluginHandlerParameters()); + distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) + .getReceptionHandlerClassName()); + assertEquals( + receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getPluginHandlerParameters(), + distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) + .getPluginHandlerParameters()); + assertEquals(CommonTestData.MY_STRING_PARAMETER_VALUE, + ((DummyReceptionHandlerParameterGroup) distributionParameters + .getReceptionHandlerConfigurationParameters() + .get(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS)).getMyStringParameter()); + assertEquals(CommonTestData.MY_INTEGER_PARAMETER_VALUE, + ((DummyReceptionHandlerParameterGroup) distributionParameters + .getReceptionHandlerConfigurationParameters() + .get(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS)).getMyIntegerParameter()); + assertEquals(CommonTestData.MY_BOOLEAN_PARAMETER_VALUE, + ((DummyReceptionHandlerParameterGroup) distributionParameters + .getReceptionHandlerConfigurationParameters() + .get(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS)).getMyBooleanParameter()); assertEquals(CommonTestData.FORWARDER_HOST, ((DummyPolicyForwarderParameterGroup) distributionParameters.getPolicyForwarderConfigurationParameters() .get(CommonTestData.FORWARDER_CONFIGURATION_PARAMETERS)).getHostname()); @@ -80,72 +96,80 @@ public class TestDistributionParameterGroup { @Test public void testDistributionParameterGroup_NullName() { final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false); - final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = commonTestData - .getReceptionHandlerParameters(false); + final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = + commonTestData.getReceptionHandlerParameters(false); + final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurations = + commonTestData.getReceptionHandlerConfigurationParameters(false); final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations = commonTestData.getPolicyForwarderConfigurationParameters(false); - final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(null, - restServerParameters, receptionHandlerParameters, forwarderConfigurations); + final DistributionParameterGroup distributionParameters = + new DistributionParameterGroup(null, restServerParameters, receptionHandlerParameters, + receptionHandlerConfigurations, forwarderConfigurations); final GroupValidationResult validationResult = distributionParameters.validate(); assertFalse(validationResult.isValid()); assertEquals(null, distributionParameters.getName()); - assertEquals(receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) - .getReceptionHandlerType(), - distributionParameters.getReceptionHandlerParameters() - .get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getReceptionHandlerType()); - assertEquals(receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) + assertEquals( + receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getReceptionHandlerType(), + distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) + .getReceptionHandlerType()); + assertEquals( + receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) .getReceptionHandlerClassName(), - distributionParameters.getReceptionHandlerParameters() - .get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) - .getReceptionHandlerClassName()); - assertEquals(receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) - .getPluginHandlerParameters(), - distributionParameters.getReceptionHandlerParameters() - .get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getPluginHandlerParameters()); - assertTrue(validationResult.getResult() - .contains("field \"name\" type \"java.lang.String\" value \"null\" INVALID, " - + "must be a non-blank string")); + distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) + .getReceptionHandlerClassName()); + assertEquals( + receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getPluginHandlerParameters(), + distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) + .getPluginHandlerParameters()); + assertTrue(validationResult.getResult().contains( + "field \"name\" type \"java.lang.String\" value \"null\" INVALID, " + "must be a non-blank string")); } @Test public void testDistributionParameterGroup_EmptyName() { final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false); - final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = commonTestData - .getReceptionHandlerParameters(false); + final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = + commonTestData.getReceptionHandlerParameters(false); + final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurations = + commonTestData.getReceptionHandlerConfigurationParameters(false); final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations = commonTestData.getPolicyForwarderConfigurationParameters(false); - final DistributionParameterGroup distributionParameters = new DistributionParameterGroup("", - restServerParameters, receptionHandlerParameters, forwarderConfigurations); + final DistributionParameterGroup distributionParameters = + new DistributionParameterGroup("", restServerParameters, receptionHandlerParameters, + receptionHandlerConfigurations, forwarderConfigurations); final GroupValidationResult validationResult = distributionParameters.validate(); assertFalse(validationResult.isValid()); assertEquals("", distributionParameters.getName()); - assertEquals(receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) - .getReceptionHandlerType(), - distributionParameters.getReceptionHandlerParameters() - .get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getReceptionHandlerType()); - assertEquals(receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) + assertEquals( + receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getReceptionHandlerType(), + distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) + .getReceptionHandlerType()); + assertEquals( + receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) .getReceptionHandlerClassName(), - distributionParameters.getReceptionHandlerParameters() - .get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) - .getReceptionHandlerClassName()); - assertEquals(receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) - .getPluginHandlerParameters(), - distributionParameters.getReceptionHandlerParameters() - .get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getPluginHandlerParameters()); - assertTrue(validationResult.getResult().contains("field \"name\" type \"java.lang.String\" value \"\" INVALID, " - + "must be a non-blank string")); + distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) + .getReceptionHandlerClassName()); + assertEquals( + receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getPluginHandlerParameters(), + distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY) + .getPluginHandlerParameters()); + assertTrue(validationResult.getResult().contains( + "field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string")); } @Test public void testDistributionParameterGroup_NullReceptionHandlerParameters() { final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false); + final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurations = + commonTestData.getReceptionHandlerConfigurationParameters(false); final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations = commonTestData.getPolicyForwarderConfigurationParameters(false); try { - final DistributionParameterGroup distributionParameters = new DistributionParameterGroup( - CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, null, forwarderConfigurations); + final DistributionParameterGroup distributionParameters = + new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, null, + receptionHandlerConfigurations, forwarderConfigurations); distributionParameters.validate(); fail("test should throw an exception here"); } catch (final Exception e) { @@ -157,13 +181,15 @@ public class TestDistributionParameterGroup { @Test public void testDistributionParameterGroup_EmptyReceptionHandlerParameters() { final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false); - final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = commonTestData - .getReceptionHandlerParameters(true); + final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = + commonTestData.getReceptionHandlerParameters(true); + final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurations = + commonTestData.getReceptionHandlerConfigurationParameters(false); final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations = commonTestData.getPolicyForwarderConfigurationParameters(false); final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, - receptionHandlerParameters, forwarderConfigurations); + receptionHandlerParameters, receptionHandlerConfigurations, forwarderConfigurations); distributionParameters.validate(); GroupValidationResult result = distributionParameters.validate(); assertFalse(result.isValid()); @@ -173,18 +199,20 @@ public class TestDistributionParameterGroup { @Test public void testDistributionParameterGroup_EmptyRestServerParameters() { final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(true); - final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = commonTestData - .getReceptionHandlerParameters(false); + final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = + commonTestData.getReceptionHandlerParameters(false); + final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurations = + commonTestData.getReceptionHandlerConfigurationParameters(false); final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations = commonTestData.getPolicyForwarderConfigurationParameters(false); final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, - receptionHandlerParameters, forwarderConfigurations); + receptionHandlerParameters, receptionHandlerConfigurations, forwarderConfigurations); final GroupValidationResult validationResult = distributionParameters.validate(); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult() - .contains("\"org.onap.policy.distribution.main.parameters.RestServerParameters\" INVALID, " - + "parameter group has status INVALID")); + .contains("\"org.onap.policy.distribution.main.parameters.RestServerParameters\" INVALID, " + + "parameter group has status INVALID")); } } diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java index ab86cb65..2dde9666 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java +++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java @@ -27,7 +27,6 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; import org.onap.policy.common.parameters.GroupValidationResult; import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters; -import org.onap.policy.distribution.reception.parameters.PssdConfigurationParametersGroup; import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters; /** @@ -41,15 +40,14 @@ public class TestReceptionHandlerParameters { @Test public void testReceptionHandlerParameters() { final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false); - final PssdConfigurationParametersGroup pssdConfiguration = commonTestData - .getPssdConfigurationParametersGroup(false); final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters( - CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME, - pssdConfiguration, pHParameters); + CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME, + CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters); final GroupValidationResult validationResult = rHParameters.validate(); assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType()); assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME, rHParameters.getReceptionHandlerClassName()); - assertEquals(pssdConfiguration, rHParameters.getPssdConfigurationParametersGroup()); + assertEquals(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, + rHParameters.getReceptionHandlerConfigurationName()); assertEquals(pHParameters, rHParameters.getPluginHandlerParameters()); assertTrue(validationResult.isValid()); } @@ -57,84 +55,79 @@ public class TestReceptionHandlerParameters { @Test public void testReceptionHandlerParameters_NullReceptionHandlerType() { final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false); - final PssdConfigurationParametersGroup pssdConfiguration = commonTestData - .getPssdConfigurationParametersGroup(false); - final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters(null, - CommonTestData.RECEPTION_HANDLER_CLASS_NAME, pssdConfiguration, pHParameters); + final ReceptionHandlerParameters rHParameters = + new ReceptionHandlerParameters(null, CommonTestData.RECEPTION_HANDLER_CLASS_NAME, + CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters); final GroupValidationResult validationResult = rHParameters.validate(); assertEquals(null, rHParameters.getReceptionHandlerType()); assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME, rHParameters.getReceptionHandlerClassName()); - assertEquals(pssdConfiguration, rHParameters.getPssdConfigurationParametersGroup()); + assertEquals(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, + rHParameters.getReceptionHandlerConfigurationName()); assertEquals(pHParameters, rHParameters.getPluginHandlerParameters()); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult() - .contains("field \"receptionHandlerType\" type \"java.lang.String\" value \"null\" INVALID, " - + "must be a non-blank string")); + .contains("field \"receptionHandlerType\" type \"java.lang.String\" value \"null\" INVALID, " + + "must be a non-blank string")); } @Test public void testReceptionHandlerParameters_NullReceptionHandlerClassName() { final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false); - final PssdConfigurationParametersGroup pssdConfiguration = commonTestData - .getPssdConfigurationParametersGroup(false); - final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters( - CommonTestData.RECEPTION_HANDLER_TYPE, null, pssdConfiguration, pHParameters); + final ReceptionHandlerParameters rHParameters = + new ReceptionHandlerParameters(CommonTestData.RECEPTION_HANDLER_TYPE, null, + CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters); final GroupValidationResult validationResult = rHParameters.validate(); assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType()); assertEquals(null, rHParameters.getReceptionHandlerClassName()); - assertEquals(pssdConfiguration, rHParameters.getPssdConfigurationParametersGroup()); + assertEquals(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, + rHParameters.getReceptionHandlerConfigurationName()); assertEquals(pHParameters, rHParameters.getPluginHandlerParameters()); assertFalse(validationResult.isValid()); - assertTrue(validationResult.getResult().contains( - "field \"receptionHandlerClassName\" type \"java.lang.String\" value \"null\" INVALID, " - + "must be a non-blank string containing full class name " - + "of the reception handler")); + assertTrue(validationResult.getResult() + .contains("field \"receptionHandlerClassName\" type \"java.lang.String\" value \"null\" INVALID, " + + "must be a non-blank string containing full class name " + "of the reception handler")); } @Test public void testReceptionHandlerParameters_EmptyReceptionHandlerType() { final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false); - final PssdConfigurationParametersGroup pssdConfiguration = commonTestData - .getPssdConfigurationParametersGroup(false); - final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters("", - CommonTestData.RECEPTION_HANDLER_CLASS_NAME, pssdConfiguration, pHParameters); + final ReceptionHandlerParameters rHParameters = + new ReceptionHandlerParameters("", CommonTestData.RECEPTION_HANDLER_CLASS_NAME, + CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters); final GroupValidationResult validationResult = rHParameters.validate(); assertEquals("", rHParameters.getReceptionHandlerType()); assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME, rHParameters.getReceptionHandlerClassName()); assertEquals(pHParameters, rHParameters.getPluginHandlerParameters()); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult() - .contains("field \"receptionHandlerType\" type \"java.lang.String\" value \"\" INVALID, " - + "must be a non-blank string")); + .contains("field \"receptionHandlerType\" type \"java.lang.String\" value \"\" INVALID, " + + "must be a non-blank string")); } @Test public void testReceptionHandlerParameters_EmptyReceptionHandlerClassName() { final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false); - final PssdConfigurationParametersGroup pssdConfiguration = commonTestData - .getPssdConfigurationParametersGroup(false); - final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters( - CommonTestData.RECEPTION_HANDLER_TYPE, "", pssdConfiguration, pHParameters); + final ReceptionHandlerParameters rHParameters = + new ReceptionHandlerParameters(CommonTestData.RECEPTION_HANDLER_TYPE, "", + CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters); final GroupValidationResult validationResult = rHParameters.validate(); assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType()); assertEquals("", rHParameters.getReceptionHandlerClassName()); - assertEquals(pssdConfiguration, rHParameters.getPssdConfigurationParametersGroup()); + assertEquals(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, + rHParameters.getReceptionHandlerConfigurationName()); assertEquals(pHParameters, rHParameters.getPluginHandlerParameters()); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult() - .contains("field \"receptionHandlerClassName\" type \"java.lang.String\" value \"\" INVALID, " - + "must be a non-blank string containing full class name " - + "of the reception handler")); + .contains("field \"receptionHandlerClassName\" type \"java.lang.String\" value \"\" INVALID, " + + "must be a non-blank string containing full class name " + "of the reception handler")); } @Test public void testReceptionHandlerParameters_EmptyPluginHandler() { final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(true); - final PssdConfigurationParametersGroup pssdConfiguration = commonTestData - .getPssdConfigurationParametersGroup(false); final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters( - CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME, - pssdConfiguration, pHParameters); + CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME, + CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters); GroupValidationResult result = rHParameters.validate(); assertFalse(result.isValid()); assertTrue(result.getResult().endsWith("must have at least one policy forwarder\n")); @@ -143,16 +136,16 @@ public class TestReceptionHandlerParameters { @Test public void testReceptionHandlerParameters_InvalidReceptionHandlerClass() { final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false); - final PssdConfigurationParametersGroup pssdConfiguration = commonTestData - .getPssdConfigurationParametersGroup(false); + final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters( - CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME + "Invalid", - pssdConfiguration, pHParameters); + CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME + "Invalid", + CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters); final GroupValidationResult validationResult = rHParameters.validate(); assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType()); assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME + "Invalid", - rHParameters.getReceptionHandlerClassName()); - assertEquals(pssdConfiguration, rHParameters.getPssdConfigurationParametersGroup()); + rHParameters.getReceptionHandlerClassName()); + assertEquals(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, + rHParameters.getReceptionHandlerConfigurationName()); assertEquals(pHParameters, rHParameters.getPluginHandlerParameters()); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult().contains("reception handler class not found in classpath")); diff --git a/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyReceptionHandlerParameterGroup.java b/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyReceptionHandlerParameterGroup.java new file mode 100644 index 00000000..d452e96c --- /dev/null +++ b/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyReceptionHandlerParameterGroup.java @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.main.testclasses; + +import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup; + +public class DummyReceptionHandlerParameterGroup extends ReceptionHandlerConfigurationParameterGroup { + + private String myStringParameter; + private int myIntegerParameter; + private boolean myBooleanParameter; + + /** + * Inner static class is to used as a Builder. + * + */ + public static class DummyReceptionHandlerParameterGroupBuilder { + private String myStringParameter; + private int myIntegerParameter; + private boolean myBooleanParameter; + + public DummyReceptionHandlerParameterGroupBuilder setMyStringParameter(final String val) { + myStringParameter = val; + return this; + } + + public DummyReceptionHandlerParameterGroupBuilder setMyIntegerParameter(final int val) { + myIntegerParameter = val; + return this; + } + + public DummyReceptionHandlerParameterGroupBuilder setMyBooleanParameter(final boolean val) { + myBooleanParameter = val; + return this; + } + + /** + * Creates a new DummyReceptionHandlerConfigurationParameterGroup instance. + */ + public DummyReceptionHandlerParameterGroup build() { + return new DummyReceptionHandlerParameterGroup(this); + } + } + + /** + * The constructor for instantiating PssdConfigurationParameterGroup. It is kept private so that + * it could only be called by PssdConfigurationBuilder. + * + * @param builder stores all the values used by PssdConfigurationParametersGroup + */ + private DummyReceptionHandlerParameterGroup(final DummyReceptionHandlerParameterGroupBuilder builder) { + myStringParameter = builder.myStringParameter; + myIntegerParameter = builder.myIntegerParameter; + myBooleanParameter = builder.myBooleanParameter; + } + + public String getMyStringParameter() { + return myStringParameter; + } + + public int getMyIntegerParameter() { + return myIntegerParameter; + } + + public boolean getMyBooleanParameter() { + return myBooleanParameter; + } + + + /** + * {@inheritDoc}. + */ + @Override + public GroupValidationResult validate() { + return new GroupValidationResult(this); + } + +} + |