aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/test/java')
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java29
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java39
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java90
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java1
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java35
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java7
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarder.java4
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarderParameterGroup.java131
8 files changed, 272 insertions, 64 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 ac58b830..186aa821 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
@@ -24,8 +24,9 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
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.reception.parameters.PluginHandlerParameters;
import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters;
import org.onap.policy.distribution.reception.parameters.PssdConfigurationParametersGroup;
@@ -48,6 +49,8 @@ public class CommonTestData {
public static final String FORWARDER_TYPE = "DummyForwarder";
public static final String FORWARDER_CLASS_NAME =
"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder";
+ public static final String FORWARDER_CONFIGURATION_PARAMETERS = "dummyConfiguration";
+ public static final String FORWARDER_HOST = "192.168.99.100";
public static final String RECEPTION_HANDLER_TYPE = "DummyReceptionHandler";
public static final String RECEPTION_HANDLER_CLASS_NAME =
"org.onap.policy.distribution.main.testclasses.DummyReceptionHandler";
@@ -142,8 +145,8 @@ public class CommonTestData {
final Map<String, PolicyForwarderParameters> policyForwarders =
new HashMap<String, PolicyForwarderParameters>();
if (!isEmpty) {
- final PolicyForwarderParameters pFParameters =
- new PolicyForwarderParameters(FORWARDER_TYPE, FORWARDER_CLASS_NAME);
+ final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(FORWARDER_TYPE,
+ FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS);
policyForwarders.put(DUMMY_ENGINE_FORWARDER_KEY, pFParameters);
}
return policyForwarders;
@@ -163,4 +166,24 @@ public class CommonTestData {
}
return policyDecoders;
}
+
+ /**
+ * Returns PolicyForwarderConfigurationParameterGroups for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return the PolicyForwarderConfigurationParameterGroups
+ */
+ public Map<String, PolicyForwarderConfigurationParameterGroup> getPolicyForwarderConfigurationParameters(
+ final boolean isEmpty) {
+ final Map<String, PolicyForwarderConfigurationParameterGroup> policyForwarderConfigurationParameters =
+ new HashMap<String, PolicyForwarderConfigurationParameterGroup>();
+ if (!isEmpty) {
+ DummyPolicyForwarderParameterGroup dummyPolicyForwarderParameterGroup =
+ new DummyPolicyForwarderParameterGroupBuilder().setUseHttps(true).setHostname(FORWARDER_HOST)
+ .setPort(1234).setUserName("myUser").setPassword("myPassword").setIsManaged(true).build();
+ policyForwarderConfigurationParameters.put(FORWARDER_CONFIGURATION_PARAMETERS,
+ dummyPolicyForwarderParameterGroup);
+ }
+ return policyForwarderConfigurationParameters;
+ }
}
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 a2d72585..0c8c80d6 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
@@ -26,9 +26,9 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
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.reception.parameters.ReceptionHandlerParameters;
/**
@@ -44,9 +44,12 @@ public class TestDistributionParameterGroup {
final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = commonTestData
.getReceptionHandlerParameters(false);
+ final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getPolicyForwarderConfigurationParameters(false);
- final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(
- CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, receptionHandlerParameters);
+ final DistributionParameterGroup distributionParameters =
+ new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters,
+ receptionHandlerParameters, forwarderConfigurations);
final GroupValidationResult validationResult = distributionParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(restServerParameters.getHost(), distributionParameters.getRestServerParameters().getHost());
@@ -69,6 +72,9 @@ public class TestDistributionParameterGroup {
.getPluginHandlerParameters(),
distributionParameters.getReceptionHandlerParameters()
.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getPluginHandlerParameters());
+ assertEquals(CommonTestData.FORWARDER_HOST,
+ ((DummyPolicyForwarderParameterGroup) distributionParameters.getPolicyForwarderConfigurationParameters()
+ .get(CommonTestData.FORWARDER_CONFIGURATION_PARAMETERS)).getHostname());
}
@Test
@@ -76,9 +82,11 @@ public class TestDistributionParameterGroup {
final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = commonTestData
.getReceptionHandlerParameters(false);
+ final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getPolicyForwarderConfigurationParameters(false);
final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(null,
- restServerParameters, receptionHandlerParameters);
+ restServerParameters, receptionHandlerParameters, forwarderConfigurations);
final GroupValidationResult validationResult = distributionParameters.validate();
assertFalse(validationResult.isValid());
assertEquals(null, distributionParameters.getName());
@@ -105,9 +113,11 @@ public class TestDistributionParameterGroup {
final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = commonTestData
.getReceptionHandlerParameters(false);
+ final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getPolicyForwarderConfigurationParameters(false);
final DistributionParameterGroup distributionParameters = new DistributionParameterGroup("",
- restServerParameters, receptionHandlerParameters);
+ restServerParameters, receptionHandlerParameters, forwarderConfigurations);
final GroupValidationResult validationResult = distributionParameters.validate();
assertFalse(validationResult.isValid());
assertEquals("", distributionParameters.getName());
@@ -131,9 +141,11 @@ public class TestDistributionParameterGroup {
@Test
public void testDistributionParameterGroup_NullReceptionHandlerParameters() {
final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
+ final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getPolicyForwarderConfigurationParameters(false);
try {
final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(
- CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, null);
+ CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, null, forwarderConfigurations);
distributionParameters.validate();
fail("test should throw an exception here");
} catch (final Exception e) {
@@ -147,9 +159,11 @@ public class TestDistributionParameterGroup {
final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = commonTestData
.getReceptionHandlerParameters(true);
-
- final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(
- CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, receptionHandlerParameters);
+ final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getPolicyForwarderConfigurationParameters(false);
+ final DistributionParameterGroup distributionParameters =
+ new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters,
+ receptionHandlerParameters, forwarderConfigurations);
distributionParameters.validate();
GroupValidationResult result = distributionParameters.validate();
assertFalse(result.isValid());
@@ -161,9 +175,12 @@ public class TestDistributionParameterGroup {
final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(true);
final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = commonTestData
.getReceptionHandlerParameters(false);
+ final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getPolicyForwarderConfigurationParameters(false);
- final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(
- CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, receptionHandlerParameters);
+ final DistributionParameterGroup distributionParameters =
+ new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters,
+ receptionHandlerParameters, forwarderConfigurations);
final GroupValidationResult validationResult = distributionParameters.validate();
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java
index 8b474984..14d1a105 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java
@@ -27,10 +27,10 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
-
import org.junit.Test;
import org.onap.policy.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.startstop.DistributionCommandLineArguments;
+import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup;
/**
* Class to perform unit test of DistributionParameterHandler.
@@ -40,8 +40,7 @@ import org.onap.policy.distribution.main.startstop.DistributionCommandLineArgume
public class TestDistributionParameterHandler {
@Test
public void testParameterHandlerNoParameterFile() throws PolicyDistributionException {
- final String[] noArgumentString =
- { "-c", "parameters/NoParameterFile.json" };
+ final String[] noArgumentString = {"-c", "parameters/NoParameterFile.json"};
final DistributionCommandLineArguments noArguments = new DistributionCommandLineArguments();
noArguments.parse(noArgumentString);
@@ -56,8 +55,7 @@ public class TestDistributionParameterHandler {
@Test
public void testParameterHandlerEmptyParameters() throws PolicyDistributionException {
- final String[] emptyArgumentString =
- { "-c", "parameters/EmptyParameters.json" };
+ final String[] emptyArgumentString = {"-c", "parameters/EmptyParameters.json"};
final DistributionCommandLineArguments emptyArguments = new DistributionCommandLineArguments();
emptyArguments.parse(emptyArgumentString);
@@ -72,8 +70,7 @@ public class TestDistributionParameterHandler {
@Test
public void testParameterHandlerBadParameters() throws PolicyDistributionException {
- final String[] badArgumentString =
- { "-c", "parameters/BadParameters.json" };
+ final String[] badArgumentString = {"-c", "parameters/BadParameters.json"};
final DistributionCommandLineArguments badArguments = new DistributionCommandLineArguments();
badArguments.parse(badArgumentString);
@@ -90,8 +87,7 @@ public class TestDistributionParameterHandler {
@Test
public void testParameterHandlerInvalidParameters() throws PolicyDistributionException {
- final String[] invalidArgumentString =
- { "-c", "parameters/InvalidParameters.json" };
+ final String[] invalidArgumentString = {"-c", "parameters/InvalidParameters.json"};
final DistributionCommandLineArguments invalidArguments = new DistributionCommandLineArguments();
invalidArguments.parse(invalidArgumentString);
@@ -108,8 +104,7 @@ public class TestDistributionParameterHandler {
@Test
public void testParameterHandlerNoParameters() throws PolicyDistributionException {
- final String[] noArgumentString =
- { "-c", "parameters/NoParameters.json" };
+ final String[] noArgumentString = {"-c", "parameters/NoParameters.json"};
final DistributionCommandLineArguments noArguments = new DistributionCommandLineArguments();
noArguments.parse(noArgumentString);
@@ -124,8 +119,7 @@ public class TestDistributionParameterHandler {
@Test
public void testParameterHandlerMinumumParameters() throws PolicyDistributionException {
- final String[] minArgumentString =
- { "-c", "parameters/MinimumParameters.json" };
+ final String[] minArgumentString = {"-c", "parameters/MinimumParameters.json"};
final DistributionCommandLineArguments minArguments = new DistributionCommandLineArguments();
minArguments.parse(minArgumentString);
@@ -136,8 +130,7 @@ public class TestDistributionParameterHandler {
@Test
public void testDistributionParameterGroup() throws PolicyDistributionException {
- final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters.json" };
+ final String[] distributionConfigParameters = {"-c", "parameters/DistributionConfigParameters.json"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
@@ -155,12 +148,50 @@ public class TestDistributionParameterHandler {
parGroup.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY)
.getPluginHandlerParameters().getPolicyForwarders()
.get(CommonTestData.DUMMY_ENGINE_FORWARDER_KEY).getForwarderType());
+ assertEquals(CommonTestData.FORWARDER_HOST,
+ ((DummyPolicyForwarderParameterGroup) parGroup.getPolicyForwarderConfigurationParameters()
+ .get(CommonTestData.FORWARDER_CONFIGURATION_PARAMETERS)).getHostname());
+ }
+
+ @Test
+ public void testDistributionParameterGroup_InvalidForwarderConfigurationClassName()
+ throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ {"-c", "parameters/DistributionConfigParameters_InvalidForwarderConfigurationClassName.json"};
+
+ final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
+ arguments.parse(distributionConfigParameters);
+
+ try {
+ new DistributionParameterHandler().getParameters(arguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains("parameter \"parameterClassName\" value \"\" invalid in JSON file"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_UnknownForwarderConfigurationClassName()
+ throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ {"-c", "parameters/DistributionConfigParameters_UnknownForwarderConfigurationClassName.json"};
+
+ final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
+ arguments.parse(distributionConfigParameters);
+
+ try {
+ new DistributionParameterHandler().getParameters(arguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains(
+ "parameter \"parameterClassName\" value \"org.onap.policy.Unknown\", could not find class"));
+ }
}
@Test
public void testDistributionParameterGroup_InvalidName() throws PolicyDistributionException {
final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters_InvalidName.json" };
+ {"-c", "parameters/DistributionConfigParameters_InvalidName.json"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
@@ -177,7 +208,7 @@ public class TestDistributionParameterHandler {
@Test
public void testDistributionParameterGroup_NoReceptionHandler() throws PolicyDistributionException {
final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters_NoReceptionHandler.json" };
+ {"-c", "parameters/DistributionConfigParameters_NoReceptionHandler.json"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
@@ -193,7 +224,7 @@ public class TestDistributionParameterHandler {
@Test
public void testDistributionParameterGroup_EmptyReceptionHandler() throws PolicyDistributionException {
final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters_EmptyReceptionHandler.json" };
+ {"-c", "parameters/DistributionConfigParameters_EmptyReceptionHandler.json"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
@@ -209,7 +240,7 @@ public class TestDistributionParameterHandler {
@Test
public void testDistributionParameterGroup_NoPolicyDecoder() throws PolicyDistributionException {
final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters_NoPolicyDecoder.json" };
+ {"-c", "parameters/DistributionConfigParameters_NoPolicyDecoder.json"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
@@ -225,7 +256,7 @@ public class TestDistributionParameterHandler {
@Test
public void testDistributionParameterGroup_NoPolicyForwarder() throws PolicyDistributionException {
final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters_NoPolicyForwarder.json" };
+ {"-c", "parameters/DistributionConfigParameters_NoPolicyForwarder.json"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
@@ -241,7 +272,7 @@ public class TestDistributionParameterHandler {
@Test
public void testDistributionParameterGroup_EmptyPolicyDecoder() throws PolicyDistributionException {
final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters_EmptyPolicyDecoder.json" };
+ {"-c", "parameters/DistributionConfigParameters_EmptyPolicyDecoder.json"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
@@ -257,7 +288,7 @@ public class TestDistributionParameterHandler {
@Test
public void testDistributionParameterGroup_EmptyPolicyForwarder() throws PolicyDistributionException {
final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters_EmptyPolicyForwarder.json" };
+ {"-c", "parameters/DistributionConfigParameters_EmptyPolicyForwarder.json"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
@@ -274,7 +305,7 @@ public class TestDistributionParameterHandler {
public void testDistributionParameterGroup_InvalidReceptionHandlerParameters()
throws PolicyDistributionException, IOException {
final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters_InvalidReceptionHandlerParameters.json" };
+ {"-c", "parameters/DistributionConfigParameters_InvalidReceptionHandlerParameters.json"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
@@ -294,7 +325,7 @@ public class TestDistributionParameterHandler {
public void testDistributionParameterGroup_InvalidDecoderAndForwarderParameters()
throws PolicyDistributionException, IOException {
final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters_InvalidDecoderAndForwarderParameters.json" };
+ {"-c", "parameters/DistributionConfigParameters_InvalidDecoderAndForwarderParameters.json"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
@@ -314,7 +345,7 @@ public class TestDistributionParameterHandler {
public void testDistributionParameterGroup_InvalidRestServerParameters()
throws PolicyDistributionException, IOException {
final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters_InvalidRestServerParameters.json" };
+ {"-c", "parameters/DistributionConfigParameters_InvalidRestServerParameters.json"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
@@ -332,8 +363,7 @@ public class TestDistributionParameterHandler {
@Test
public void testDistributionVersion() throws PolicyDistributionException {
- final String[] distributionConfigParameters =
- { "-v" };
+ final String[] distributionConfigParameters = {"-v"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
final String version = arguments.parse(distributionConfigParameters);
assertTrue(version.startsWith("ONAP Policy Framework Distribution Service"));
@@ -341,8 +371,7 @@ public class TestDistributionParameterHandler {
@Test
public void testDistributionHelp() throws PolicyDistributionException {
- final String[] distributionConfigParameters =
- { "-h" };
+ final String[] distributionConfigParameters = {"-h"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
final String help = arguments.parse(distributionConfigParameters);
assertTrue(help.startsWith("usage:"));
@@ -350,8 +379,7 @@ public class TestDistributionParameterHandler {
@Test
public void testDistributionInvalidOption() throws PolicyDistributionException {
- final String[] distributionConfigParameters =
- { "-d" };
+ final String[] distributionConfigParameters = {"-d"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
try {
arguments.parse(distributionConfigParameters);
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java
index 552ee50c..9eeae354 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java
@@ -26,7 +26,6 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Map;
-
import org.junit.Test;
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java
index d64df1b3..9907bfb8 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java
@@ -23,6 +23,9 @@ package org.onap.policy.distribution.main.parameters;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.onap.policy.distribution.main.parameters.CommonTestData.FORWARDER_CLASS_NAME;
+import static org.onap.policy.distribution.main.parameters.CommonTestData.FORWARDER_CONFIGURATION_PARAMETERS;
+import static org.onap.policy.distribution.main.parameters.CommonTestData.FORWARDER_TYPE;
import org.junit.Test;
import org.onap.policy.common.parameters.GroupValidationResult;
@@ -38,20 +41,20 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters() {
final PolicyForwarderParameters pFParameters =
- new PolicyForwarderParameters(CommonTestData.FORWARDER_TYPE, CommonTestData.FORWARDER_CLASS_NAME);
+ new PolicyForwarderParameters(FORWARDER_TYPE, FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS);
final GroupValidationResult validationResult = pFParameters.validate();
- assertEquals(CommonTestData.FORWARDER_TYPE, pFParameters.getForwarderType());
- assertEquals(CommonTestData.FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName());
+ assertEquals(FORWARDER_TYPE, pFParameters.getForwarderType());
+ assertEquals(FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName());
assertTrue(validationResult.isValid());
}
@Test
public void testPolicyForwarderParameters_InvalidForwarderType() {
final PolicyForwarderParameters pFParameters =
- new PolicyForwarderParameters("", CommonTestData.FORWARDER_CLASS_NAME);
+ new PolicyForwarderParameters("", FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS);
final GroupValidationResult validationResult = pFParameters.validate();
assertEquals("", pFParameters.getForwarderType());
- assertEquals(CommonTestData.FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName());
+ assertEquals(FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult().contains(
"field \"forwarderType\" type \"java.lang.String\" value \"\" INVALID, must be a non-blank string"));
@@ -59,7 +62,8 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters_InvalidForwarderClassName() {
- final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(CommonTestData.FORWARDER_TYPE, "");
+ final PolicyForwarderParameters pFParameters =
+ new PolicyForwarderParameters(FORWARDER_TYPE, "", FORWARDER_CONFIGURATION_PARAMETERS);
final GroupValidationResult validationResult = pFParameters.validate();
assertEquals(CommonTestData.FORWARDER_TYPE, pFParameters.getForwarderType());
assertEquals("", pFParameters.getForwarderClassName());
@@ -71,7 +75,8 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters_InvalidForwarderTypeAndClassName() {
- final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters("", "");
+ final PolicyForwarderParameters pFParameters =
+ new PolicyForwarderParameters("", "", FORWARDER_CONFIGURATION_PARAMETERS);
final GroupValidationResult validationResult = pFParameters.validate();
assertEquals("", pFParameters.getForwarderType());
assertEquals("", pFParameters.getForwarderClassName());
@@ -86,10 +91,10 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters_NullForwarderType() {
final PolicyForwarderParameters pFParameters =
- new PolicyForwarderParameters(null, CommonTestData.FORWARDER_CLASS_NAME);
+ new PolicyForwarderParameters(null, FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS);
final GroupValidationResult validationResult = pFParameters.validate();
assertEquals(null, pFParameters.getForwarderType());
- assertEquals(CommonTestData.FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName());
+ assertEquals(FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
.contains("field \"forwarderType\" type \"java.lang.String\" value \"null\" INVALID, "
@@ -99,9 +104,9 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters_NullForwarderClassName() {
final PolicyForwarderParameters pFParameters =
- new PolicyForwarderParameters(CommonTestData.FORWARDER_TYPE, null);
+ new PolicyForwarderParameters(FORWARDER_TYPE, null, FORWARDER_CONFIGURATION_PARAMETERS);
final GroupValidationResult validationResult = pFParameters.validate();
- assertEquals(CommonTestData.FORWARDER_TYPE, pFParameters.getForwarderType());
+ assertEquals(FORWARDER_TYPE, pFParameters.getForwarderType());
assertEquals(null, pFParameters.getForwarderClassName());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
@@ -111,11 +116,11 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters_InvalidForwarderClass() {
- final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(CommonTestData.FORWARDER_TYPE,
- CommonTestData.FORWARDER_CLASS_NAME + "Invalid");
+ final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(FORWARDER_TYPE,
+ FORWARDER_CLASS_NAME + "Invalid", FORWARDER_CONFIGURATION_PARAMETERS);
final GroupValidationResult validationResult = pFParameters.validate();
- assertEquals(CommonTestData.FORWARDER_TYPE, pFParameters.getForwarderType());
- assertEquals(CommonTestData.FORWARDER_CLASS_NAME + "Invalid", pFParameters.getForwarderClassName());
+ assertEquals(FORWARDER_TYPE, pFParameters.getForwarderType());
+ assertEquals(FORWARDER_CLASS_NAME + "Invalid", pFParameters.getForwarderClassName());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult().contains("policy forwarder class not found in classpath"));
}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java
index c901b5d9..47ac82b1 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java
@@ -28,6 +28,7 @@ import org.onap.policy.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.parameters.CommonTestData;
import org.onap.policy.distribution.main.parameters.DistributionParameterGroup;
import org.onap.policy.distribution.main.parameters.DistributionParameterHandler;
+import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup;
/**
* Class to perform unit test of DistributionActivator.
@@ -38,8 +39,7 @@ public class TestDistributionActivator {
@Test
public void testDistributionActivator() throws PolicyDistributionException {
- final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters.json" };
+ final String[] distributionConfigParameters = {"-c", "parameters/DistributionConfigParameters.json"};
final DistributionCommandLineArguments arguments =
new DistributionCommandLineArguments(distributionConfigParameters);
@@ -61,6 +61,9 @@ public class TestDistributionActivator {
activator.getParameterGroup().getReceptionHandlerParameters()
.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getPluginHandlerParameters()
.getPolicyForwarders().get(CommonTestData.DUMMY_ENGINE_FORWARDER_KEY).getForwarderType());
+ assertEquals(DummyPolicyForwarderParameterGroup.class,
+ activator.getParameterGroup().getPolicyForwarderConfigurationParameters()
+ .get(CommonTestData.FORWARDER_CONFIGURATION_PARAMETERS).getClass());
activator.terminate();
}
}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarder.java b/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarder.java
index 5cae0c6a..c9c7fef2 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarder.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarder.java
@@ -22,7 +22,6 @@ package org.onap.policy.distribution.main.testclasses;
import java.util.ArrayList;
import java.util.Collection;
-
import org.onap.policy.distribution.forwarding.PolicyForwarder;
import org.onap.policy.distribution.forwarding.PolicyForwardingException;
import org.onap.policy.distribution.model.Policy;
@@ -49,4 +48,7 @@ public class DummyPolicyForwarder implements PolicyForwarder {
public boolean receivedPolicy(final Policy policy) {
return policiesReceived.contains(policy);
}
+
+ @Override
+ public void configure(String parameterGroupName) {}
}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarderParameterGroup.java b/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarderParameterGroup.java
new file mode 100644
index 00000000..66217d18
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarderParameterGroup.java
@@ -0,0 +1,131 @@
+/*-
+ * ============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.main.parameters.PolicyForwarderConfigurationParameterGroup;
+
+/**
+ * Dummy policy forwarder parameter group.
+ */
+public class DummyPolicyForwarderParameterGroup extends PolicyForwarderConfigurationParameterGroup {
+
+ private boolean useHttps;
+ private String hostname;
+ private int port;
+ private String userName;
+ private String password;
+ private boolean isManaged;
+
+ public boolean isUseHttps() {
+ return useHttps;
+ }
+
+ public String getHostname() {
+ return hostname;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public boolean isManaged() {
+ return isManaged;
+ }
+
+ /**
+ * Builder for DummyPolicyForwarderParameterGroup.
+ */
+ public static class DummyPolicyForwarderParameterGroupBuilder {
+ private boolean useHttps;
+ private String hostname;
+ private int port;
+ private String userName;
+ private String password;
+ private boolean isManaged;
+
+ public DummyPolicyForwarderParameterGroupBuilder setUseHttps(final boolean useHttps) {
+ this.useHttps = useHttps;
+ return this;
+ }
+
+ public DummyPolicyForwarderParameterGroupBuilder setHostname(final String hostname) {
+ this.hostname = hostname;
+ return this;
+ }
+
+ public DummyPolicyForwarderParameterGroupBuilder setPort(final int port) {
+ this.port = port;
+ return this;
+ }
+
+ public DummyPolicyForwarderParameterGroupBuilder setUserName(final String userName) {
+ this.userName = userName;
+ return this;
+ }
+
+ public DummyPolicyForwarderParameterGroupBuilder setPassword(final String password) {
+ this.password = password;
+ return this;
+ }
+
+ public DummyPolicyForwarderParameterGroupBuilder setIsManaged(final boolean isManaged) {
+ this.isManaged = isManaged;
+ return this;
+ }
+
+ /**
+ * Creates a new DummyPolicyForwarderParameterGroup instance.
+ */
+ public DummyPolicyForwarderParameterGroup build() {
+ return new DummyPolicyForwarderParameterGroup(this);
+ }
+ }
+
+ /**
+ * Construct an instance.
+ *
+ * @param builder the builder create the instance from
+ */
+ private DummyPolicyForwarderParameterGroup(final DummyPolicyForwarderParameterGroupBuilder builder) {
+ this.useHttps = builder.useHttps;
+ this.hostname = builder.hostname;
+ this.port = builder.port;
+ this.userName = builder.userName;
+ this.password = builder.password;
+ this.isManaged = builder.isManaged;
+ }
+
+ @Override
+ public GroupValidationResult validate() {
+ final GroupValidationResult validationResult = new GroupValidationResult(this);
+ return validationResult;
+ }
+
+}