summaryrefslogtreecommitdiffstats
path: root/main/src/test/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/test/java/org/onap')
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java39
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java55
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java20
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java10
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyDecoderParameters.java29
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java31
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java34
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java65
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java52
9 files changed, 231 insertions, 104 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 953fa7b0..54716fc8 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
@@ -23,6 +23,11 @@ package org.onap.policy.distribution.main.parameters;
import java.util.HashMap;
import java.util.Map;
+import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
+import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters;
+import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters;
+import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters;
+
/**
* Class to hold/create all parameters for test cases.
*
@@ -30,15 +35,19 @@ import java.util.Map;
*/
public class CommonTestData {
- public static final String decoderType = "TOSCA";
- public static final String decoderClassName =
+ public static final String DISTRIBUTION_GROUP_NAME = "SDCDistributionGroup";
+ public static final String DECODER_TYPE = "TOSCA";
+ public static final String DECODER_CLASS_NAME =
"org.onap.policy.distribution.reception.decoding.pdpx.PolicyDecoderToscaPdpx";
- public static final String forwarderType = "PAPEngine";
- public static final String forwarderClassName =
+ public static final String FORWARDER_TYPE = "PAPEngine";
+ public static final String FORWARDER_CLASS_NAME =
"org.onap.policy.distribution.forwarding.pap.engine.XacmlPapServletPolicyForwarder";
- public static final String receptionHandlerType = "SDCReceptionHandler";
- public static final String receptionHandlerClassName =
+ public static final String RECEPTION_HANDLER_TYPE = "SDC";
+ public static final String RECEPTION_HANDLER_CLASS_NAME =
"org.onap.policy.distribution.reception.handling.sdc.SdcReceptionHandler";
+ public static final String SDC_RECEPTION_HANDLER_KEY = "SDCReceptionHandler";
+ public static final String PAP_ENGINE_FORWARDER_KEY = "PAPEngineForwarder";
+ public static final String TOSCA_DECODER_KEY = "TOSCADecoder";
/**
* Returns an instance of ReceptionHandlerParameters for test cases.
@@ -52,13 +61,10 @@ public class CommonTestData {
if (!isEmpty) {
final Map<String, PolicyDecoderParameters> policyDecoders = getPolicyDecoders(isEmpty);
final Map<String, PolicyForwarderParameters> policyForwarders = getPolicyForwarders(isEmpty);
- final String receptionHandlerType = "SDC";
- final String receptionHandlerClassName =
- "org.onap.policy.distribution.reception.handling.sdc.SdcReceptionHandler";
final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyDecoders, policyForwarders);
final ReceptionHandlerParameters rhParameters =
- new ReceptionHandlerParameters(receptionHandlerType, receptionHandlerClassName, pHParameters);
- receptionHandlerParameters.put("SDCReceptionHandler", rhParameters);
+ new ReceptionHandlerParameters(RECEPTION_HANDLER_TYPE, RECEPTION_HANDLER_CLASS_NAME, pHParameters);
+ receptionHandlerParameters.put(SDC_RECEPTION_HANDLER_KEY, rhParameters);
}
return receptionHandlerParameters;
}
@@ -87,12 +93,9 @@ public class CommonTestData {
final Map<String, PolicyForwarderParameters> policyForwarders =
new HashMap<String, PolicyForwarderParameters>();
if (!isEmpty) {
- final String forwarderType = "PAPEngine";
- final String forwarderClassName =
- "org.onap.policy.distribution.forwarding.pap.engine.XacmlPapServletPolicyForwarder";
final PolicyForwarderParameters pFParameters =
- new PolicyForwarderParameters(forwarderType, forwarderClassName);
- policyForwarders.put("PAPEngineForwarder", pFParameters);
+ new PolicyForwarderParameters(FORWARDER_TYPE, FORWARDER_CLASS_NAME);
+ policyForwarders.put(PAP_ENGINE_FORWARDER_KEY, pFParameters);
}
return policyForwarders;
}
@@ -106,8 +109,8 @@ public class CommonTestData {
public Map<String, PolicyDecoderParameters> getPolicyDecoders(final boolean isEmpty) {
final Map<String, PolicyDecoderParameters> policyDecoders = new HashMap<String, PolicyDecoderParameters>();
if (!isEmpty) {
- final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(decoderType, decoderClassName);
- policyDecoders.put("TOSCADecoder", pDParameters);
+ final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(DECODER_TYPE, DECODER_CLASS_NAME);
+ policyDecoders.put(TOSCA_DECODER_KEY, pDParameters);
}
return policyDecoders;
}
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 cce432dc..70317971 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,7 @@ import java.util.Map;
import org.junit.Test;
import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters;
/**
* Class to perform unit test of DistributionParameterGroup.
@@ -40,23 +41,24 @@ public class TestDistributionParameterGroup {
@Test
public void testDistributionParameterGroup() {
- final String name = "SDCDistributionGroup";
final Map<String, ReceptionHandlerParameters> receptionHandlerParameters =
commonTestData.getReceptionHandlerParameters(false);
final DistributionParameterGroup distributionParameters =
- new DistributionParameterGroup(name, receptionHandlerParameters);
+ new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, receptionHandlerParameters);
final GroupValidationResult validationResult = distributionParameters.validate();
assertTrue(validationResult.isValid());
- assertEquals(name, distributionParameters.getName());
- assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getReceptionHandlerType(),
- distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ assertEquals(CommonTestData.DISTRIBUTION_GROUP_NAME, distributionParameters.getName());
+ assertEquals(receptionHandlerParameters.get(CommonTestData.SDC_RECEPTION_HANDLER_KEY).getReceptionHandlerType(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.SDC_RECEPTION_HANDLER_KEY)
.getReceptionHandlerType());
- assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getReceptionHandlerClassName(),
- distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ assertEquals(
+ receptionHandlerParameters.get(CommonTestData.SDC_RECEPTION_HANDLER_KEY).getReceptionHandlerClassName(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.SDC_RECEPTION_HANDLER_KEY)
.getReceptionHandlerClassName());
- assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getPluginHandlerParameters(),
- distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ assertEquals(
+ receptionHandlerParameters.get(CommonTestData.SDC_RECEPTION_HANDLER_KEY).getPluginHandlerParameters(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.SDC_RECEPTION_HANDLER_KEY)
.getPluginHandlerParameters());
}
@@ -70,14 +72,16 @@ public class TestDistributionParameterGroup {
final GroupValidationResult validationResult = distributionParameters.validate();
assertFalse(validationResult.isValid());
assertEquals(null, distributionParameters.getName());
- assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getReceptionHandlerType(),
- distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ assertEquals(receptionHandlerParameters.get(CommonTestData.SDC_RECEPTION_HANDLER_KEY).getReceptionHandlerType(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.SDC_RECEPTION_HANDLER_KEY)
.getReceptionHandlerType());
- assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getReceptionHandlerClassName(),
- distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ assertEquals(
+ receptionHandlerParameters.get(CommonTestData.SDC_RECEPTION_HANDLER_KEY).getReceptionHandlerClassName(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.SDC_RECEPTION_HANDLER_KEY)
.getReceptionHandlerClassName());
- assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getPluginHandlerParameters(),
- distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ assertEquals(
+ receptionHandlerParameters.get(CommonTestData.SDC_RECEPTION_HANDLER_KEY).getPluginHandlerParameters(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.SDC_RECEPTION_HANDLER_KEY)
.getPluginHandlerParameters());
assertTrue(validationResult.getResult().contains(
"field \"name\" type \"java.lang.String\" value \"null\" INVALID, " + "must be a non-blank string"));
@@ -93,14 +97,16 @@ public class TestDistributionParameterGroup {
final GroupValidationResult validationResult = distributionParameters.validate();
assertFalse(validationResult.isValid());
assertEquals("", distributionParameters.getName());
- assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getReceptionHandlerType(),
- distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ assertEquals(receptionHandlerParameters.get(CommonTestData.SDC_RECEPTION_HANDLER_KEY).getReceptionHandlerType(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.SDC_RECEPTION_HANDLER_KEY)
.getReceptionHandlerType());
- assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getReceptionHandlerClassName(),
- distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ assertEquals(
+ receptionHandlerParameters.get(CommonTestData.SDC_RECEPTION_HANDLER_KEY).getReceptionHandlerClassName(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.SDC_RECEPTION_HANDLER_KEY)
.getReceptionHandlerClassName());
- assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getPluginHandlerParameters(),
- distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ assertEquals(
+ receptionHandlerParameters.get(CommonTestData.SDC_RECEPTION_HANDLER_KEY).getPluginHandlerParameters(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.SDC_RECEPTION_HANDLER_KEY)
.getPluginHandlerParameters());
assertTrue(validationResult.getResult().contains(
"field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
@@ -108,9 +114,9 @@ public class TestDistributionParameterGroup {
@Test
public void testDistributionParameterGroup_NullReceptionHandlerParameters() {
- final String name = "SDCDistributionGroup";
try {
- final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(name, null);
+ final DistributionParameterGroup distributionParameters =
+ new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, null);
distributionParameters.validate();
fail("test should throw an exception here");
} catch (final Exception e) {
@@ -121,12 +127,11 @@ public class TestDistributionParameterGroup {
@Test
public void testDistributionParameterGroup_EmptyReceptionHandlerParameters() {
- final String name = "SDCDistributionGroup";
final Map<String, ReceptionHandlerParameters> receptionHandlerParameters =
commonTestData.getReceptionHandlerParameters(true);
try {
final DistributionParameterGroup distributionParameters =
- new DistributionParameterGroup(name, receptionHandlerParameters);
+ new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, receptionHandlerParameters);
distributionParameters.validate();
fail("test should throw an exception here");
} catch (final Exception e) {
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 57610b23..79b12243 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
@@ -121,7 +121,7 @@ public class TestDistributionParameterHandler {
minArguments.parse(minArgumentString);
final DistributionParameterGroup parGroup = new DistributionParameterHandler().getParameters(minArguments);
- assertEquals("SDCDistributionGroup", parGroup.getName());
+ assertEquals(CommonTestData.DISTRIBUTION_GROUP_NAME, parGroup.getName());
}
@Test
@@ -132,13 +132,17 @@ public class TestDistributionParameterHandler {
arguments.parse(distributionConfigParameters);
final DistributionParameterGroup parGroup = new DistributionParameterHandler().getParameters(arguments);
- assertEquals("SDCDistributionGroup", parGroup.getName());
- assertEquals("SDC",
- parGroup.getReceptionHandlerParameters().get("SDCReceptionHandler").getReceptionHandlerType());
- assertEquals("TOSCA", parGroup.getReceptionHandlerParameters().get("SDCReceptionHandler")
- .getPluginHandlerParameters().getPolicyDecoders().get("TOSCADecoder").getDecoderType());
- assertEquals("PAPEngine", parGroup.getReceptionHandlerParameters().get("SDCReceptionHandler")
- .getPluginHandlerParameters().getPolicyForwarders().get("PAPEngineForwarder").getForwarderType());
+ assertEquals(CommonTestData.DISTRIBUTION_GROUP_NAME, parGroup.getName());
+ assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, parGroup.getReceptionHandlerParameters()
+ .get(CommonTestData.SDC_RECEPTION_HANDLER_KEY).getReceptionHandlerType());
+ assertEquals(CommonTestData.DECODER_TYPE,
+ parGroup.getReceptionHandlerParameters().get(CommonTestData.SDC_RECEPTION_HANDLER_KEY)
+ .getPluginHandlerParameters().getPolicyDecoders().get(CommonTestData.TOSCA_DECODER_KEY)
+ .getDecoderType());
+ assertEquals(CommonTestData.FORWARDER_TYPE,
+ parGroup.getReceptionHandlerParameters().get(CommonTestData.SDC_RECEPTION_HANDLER_KEY)
+ .getPluginHandlerParameters().getPolicyForwarders().get(CommonTestData.PAP_ENGINE_FORWARDER_KEY)
+ .getForwarderType());
}
@Test
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 b2d732e9..4d9e5847 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
@@ -28,6 +28,9 @@ import java.util.Map;
import org.junit.Test;
import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
+import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters;
+import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters;
/**
* Class to perform unit test of PluginHandlerParameters.
@@ -43,9 +46,10 @@ public class TestPluginHandlerParameters {
final Map<String, PolicyForwarderParameters> policyForwarders = commonTestData.getPolicyForwarders(false);
final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyDecoders, policyForwarders);
final GroupValidationResult validationResult = pHParameters.validate();
- assertEquals(policyDecoders.get("TOSCADecoder"), pHParameters.getPolicyDecoders().get("TOSCADecoder"));
- assertEquals(policyForwarders.get("PAPEngineForwarder"),
- pHParameters.getPolicyForwarders().get("PAPEngineForwarder"));
+ assertEquals(policyDecoders.get(CommonTestData.TOSCA_DECODER_KEY),
+ pHParameters.getPolicyDecoders().get(CommonTestData.TOSCA_DECODER_KEY));
+ assertEquals(policyForwarders.get(CommonTestData.PAP_ENGINE_FORWARDER_KEY),
+ pHParameters.getPolicyForwarders().get(CommonTestData.PAP_ENGINE_FORWARDER_KEY));
assertTrue(validationResult.isValid());
}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyDecoderParameters.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyDecoderParameters.java
index bcae6df6..35acdf2e 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyDecoderParameters.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyDecoderParameters.java
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters;
/**
* Class to perform unit test of PolicyDecoderParameters.
@@ -37,19 +38,19 @@ public class TestPolicyDecoderParameters {
@Test
public void testPolicyDecoderParameters() {
final PolicyDecoderParameters pDParameters =
- new PolicyDecoderParameters(CommonTestData.decoderType, CommonTestData.decoderClassName);
+ new PolicyDecoderParameters(CommonTestData.DECODER_TYPE, CommonTestData.DECODER_CLASS_NAME);
final GroupValidationResult validationResult = pDParameters.validate();
- assertEquals(CommonTestData.decoderType, pDParameters.getDecoderType());
- assertEquals(CommonTestData.decoderClassName, pDParameters.getDecoderClassName());
+ assertEquals(CommonTestData.DECODER_TYPE, pDParameters.getDecoderType());
+ assertEquals(CommonTestData.DECODER_CLASS_NAME, pDParameters.getDecoderClassName());
assertTrue(validationResult.isValid());
}
@Test
public void testPolicyDecoderParameters_InvalidDecoderType() {
- final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters("", CommonTestData.decoderClassName);
+ final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters("", CommonTestData.DECODER_CLASS_NAME);
final GroupValidationResult validationResult = pDParameters.validate();
assertEquals("", pDParameters.getDecoderType());
- assertEquals(CommonTestData.decoderClassName, pDParameters.getDecoderClassName());
+ assertEquals(CommonTestData.DECODER_CLASS_NAME, pDParameters.getDecoderClassName());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult().contains(
"field \"decoderType\" type \"java.lang.String\" value \"\" INVALID, must be a non-blank string"));
@@ -57,9 +58,9 @@ public class TestPolicyDecoderParameters {
@Test
public void testPolicyDecoderParameters_InvalidDecoderClassName() {
- final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(CommonTestData.decoderType, "");
+ final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(CommonTestData.DECODER_TYPE, "");
final GroupValidationResult validationResult = pDParameters.validate();
- assertEquals(CommonTestData.decoderType, pDParameters.getDecoderType());
+ assertEquals(CommonTestData.DECODER_TYPE, pDParameters.getDecoderType());
assertEquals("", pDParameters.getDecoderClassName());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
@@ -83,10 +84,10 @@ public class TestPolicyDecoderParameters {
@Test
public void testPolicyDecoderParameters_NullDecoderType() {
- final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(null, CommonTestData.decoderClassName);
+ final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(null, CommonTestData.DECODER_CLASS_NAME);
final GroupValidationResult validationResult = pDParameters.validate();
assertEquals(null, pDParameters.getDecoderType());
- assertEquals(CommonTestData.decoderClassName, pDParameters.getDecoderClassName());
+ assertEquals(CommonTestData.DECODER_CLASS_NAME, pDParameters.getDecoderClassName());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult().contains(
"field \"decoderType\" type \"java.lang.String\" value \"null\" INVALID, must be a non-blank string"));
@@ -94,9 +95,9 @@ public class TestPolicyDecoderParameters {
@Test
public void testPolicyDecoderParameters_NullDecoderClassName() {
- final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(CommonTestData.decoderType, null);
+ final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(CommonTestData.DECODER_TYPE, null);
final GroupValidationResult validationResult = pDParameters.validate();
- assertEquals(CommonTestData.decoderType, pDParameters.getDecoderType());
+ assertEquals(CommonTestData.DECODER_TYPE, pDParameters.getDecoderType());
assertEquals(null, pDParameters.getDecoderClassName());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
@@ -107,10 +108,10 @@ public class TestPolicyDecoderParameters {
@Test
public void testPolicyDecoderParameters_InvalidDecoderClass() {
final PolicyDecoderParameters pDParameters =
- new PolicyDecoderParameters(CommonTestData.decoderType, CommonTestData.decoderClassName + "Invalid");
+ new PolicyDecoderParameters(CommonTestData.DECODER_TYPE, CommonTestData.DECODER_CLASS_NAME + "Invalid");
final GroupValidationResult validationResult = pDParameters.validate();
- assertEquals(CommonTestData.decoderType, pDParameters.getDecoderType());
- assertEquals(CommonTestData.decoderClassName + "Invalid", pDParameters.getDecoderClassName());
+ assertEquals(CommonTestData.DECODER_TYPE, pDParameters.getDecoderType());
+ assertEquals(CommonTestData.DECODER_CLASS_NAME + "Invalid", pDParameters.getDecoderClassName());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult().contains("policy decoder class not found in classpath"));
}
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 bbcbc370..d64df1b3 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
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
/**
* Class to perform unit test of PolicyForwarderParameters.
@@ -37,20 +38,20 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters() {
final PolicyForwarderParameters pFParameters =
- new PolicyForwarderParameters(CommonTestData.forwarderType, CommonTestData.forwarderClassName);
+ new PolicyForwarderParameters(CommonTestData.FORWARDER_TYPE, CommonTestData.FORWARDER_CLASS_NAME);
final GroupValidationResult validationResult = pFParameters.validate();
- assertEquals(CommonTestData.forwarderType, pFParameters.getForwarderType());
- assertEquals(CommonTestData.forwarderClassName, pFParameters.getForwarderClassName());
+ assertEquals(CommonTestData.FORWARDER_TYPE, pFParameters.getForwarderType());
+ assertEquals(CommonTestData.FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName());
assertTrue(validationResult.isValid());
}
@Test
public void testPolicyForwarderParameters_InvalidForwarderType() {
final PolicyForwarderParameters pFParameters =
- new PolicyForwarderParameters("", CommonTestData.forwarderClassName);
+ new PolicyForwarderParameters("", CommonTestData.FORWARDER_CLASS_NAME);
final GroupValidationResult validationResult = pFParameters.validate();
assertEquals("", pFParameters.getForwarderType());
- assertEquals(CommonTestData.forwarderClassName, pFParameters.getForwarderClassName());
+ assertEquals(CommonTestData.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"));
@@ -58,9 +59,9 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters_InvalidForwarderClassName() {
- final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(CommonTestData.forwarderType, "");
+ final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(CommonTestData.FORWARDER_TYPE, "");
final GroupValidationResult validationResult = pFParameters.validate();
- assertEquals(CommonTestData.forwarderType, pFParameters.getForwarderType());
+ assertEquals(CommonTestData.FORWARDER_TYPE, pFParameters.getForwarderType());
assertEquals("", pFParameters.getForwarderClassName());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
@@ -85,10 +86,10 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters_NullForwarderType() {
final PolicyForwarderParameters pFParameters =
- new PolicyForwarderParameters(null, CommonTestData.forwarderClassName);
+ new PolicyForwarderParameters(null, CommonTestData.FORWARDER_CLASS_NAME);
final GroupValidationResult validationResult = pFParameters.validate();
assertEquals(null, pFParameters.getForwarderType());
- assertEquals(CommonTestData.forwarderClassName, pFParameters.getForwarderClassName());
+ assertEquals(CommonTestData.FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
.contains("field \"forwarderType\" type \"java.lang.String\" value \"null\" INVALID, "
@@ -98,9 +99,9 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters_NullForwarderClassName() {
final PolicyForwarderParameters pFParameters =
- new PolicyForwarderParameters(CommonTestData.forwarderType, null);
+ new PolicyForwarderParameters(CommonTestData.FORWARDER_TYPE, null);
final GroupValidationResult validationResult = pFParameters.validate();
- assertEquals(CommonTestData.forwarderType, pFParameters.getForwarderType());
+ assertEquals(CommonTestData.FORWARDER_TYPE, pFParameters.getForwarderType());
assertEquals(null, pFParameters.getForwarderClassName());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
@@ -110,11 +111,11 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters_InvalidForwarderClass() {
- final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(CommonTestData.forwarderType,
- CommonTestData.forwarderClassName + "Invalid");
+ final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(CommonTestData.FORWARDER_TYPE,
+ CommonTestData.FORWARDER_CLASS_NAME + "Invalid");
final GroupValidationResult validationResult = pFParameters.validate();
- assertEquals(CommonTestData.forwarderType, pFParameters.getForwarderType());
- assertEquals(CommonTestData.forwarderClassName + "Invalid", pFParameters.getForwarderClassName());
+ assertEquals(CommonTestData.FORWARDER_TYPE, pFParameters.getForwarderType());
+ assertEquals(CommonTestData.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/parameters/TestReceptionHandlerParameters.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java
index 5eb113de..10faed8c 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,6 +27,8 @@ import static org.junit.Assert.fail;
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.ReceptionHandlerParameters;
/**
* Class to perform unit test of ReceptionHandlerParameters.
@@ -40,10 +42,10 @@ public class TestReceptionHandlerParameters {
public void testReceptionHandlerParameters() {
final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters(
- CommonTestData.receptionHandlerType, CommonTestData.receptionHandlerClassName, pHParameters);
+ CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME, pHParameters);
final GroupValidationResult validationResult = rHParameters.validate();
- assertEquals(CommonTestData.receptionHandlerType, rHParameters.getReceptionHandlerType());
- assertEquals(CommonTestData.receptionHandlerClassName, rHParameters.getReceptionHandlerClassName());
+ assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType());
+ assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME, rHParameters.getReceptionHandlerClassName());
assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
assertTrue(validationResult.isValid());
}
@@ -52,10 +54,10 @@ public class TestReceptionHandlerParameters {
public void testReceptionHandlerParameters_NullReceptionHandlerType() {
final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
final ReceptionHandlerParameters rHParameters =
- new ReceptionHandlerParameters(null, CommonTestData.receptionHandlerClassName, pHParameters);
+ new ReceptionHandlerParameters(null, CommonTestData.RECEPTION_HANDLER_CLASS_NAME, pHParameters);
final GroupValidationResult validationResult = rHParameters.validate();
assertEquals(null, rHParameters.getReceptionHandlerType());
- assertEquals(CommonTestData.receptionHandlerClassName, rHParameters.getReceptionHandlerClassName());
+ assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME, rHParameters.getReceptionHandlerClassName());
assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
@@ -67,9 +69,9 @@ public class TestReceptionHandlerParameters {
public void testReceptionHandlerParameters_NullReceptionHandlerClassName() {
final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
final ReceptionHandlerParameters rHParameters =
- new ReceptionHandlerParameters(CommonTestData.receptionHandlerType, null, pHParameters);
+ new ReceptionHandlerParameters(CommonTestData.RECEPTION_HANDLER_TYPE, null, pHParameters);
final GroupValidationResult validationResult = rHParameters.validate();
- assertEquals(CommonTestData.receptionHandlerType, rHParameters.getReceptionHandlerType());
+ assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType());
assertEquals(null, rHParameters.getReceptionHandlerClassName());
assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
assertFalse(validationResult.isValid());
@@ -83,10 +85,10 @@ public class TestReceptionHandlerParameters {
final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
final ReceptionHandlerParameters rHParameters =
- new ReceptionHandlerParameters("", CommonTestData.receptionHandlerClassName, pHParameters);
+ new ReceptionHandlerParameters("", CommonTestData.RECEPTION_HANDLER_CLASS_NAME, pHParameters);
final GroupValidationResult validationResult = rHParameters.validate();
assertEquals("", rHParameters.getReceptionHandlerType());
- assertEquals(CommonTestData.receptionHandlerClassName, rHParameters.getReceptionHandlerClassName());
+ assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME, rHParameters.getReceptionHandlerClassName());
assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
@@ -98,9 +100,9 @@ public class TestReceptionHandlerParameters {
public void testReceptionHandlerParameters_EmptyReceptionHandlerClassName() {
final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
final ReceptionHandlerParameters rHParameters =
- new ReceptionHandlerParameters(CommonTestData.receptionHandlerType, "", pHParameters);
+ new ReceptionHandlerParameters(CommonTestData.RECEPTION_HANDLER_TYPE, "", pHParameters);
final GroupValidationResult validationResult = rHParameters.validate();
- assertEquals(CommonTestData.receptionHandlerType, rHParameters.getReceptionHandlerType());
+ assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType());
assertEquals("", rHParameters.getReceptionHandlerClassName());
assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
assertFalse(validationResult.isValid());
@@ -114,7 +116,7 @@ public class TestReceptionHandlerParameters {
try {
final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(true);
final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters(
- CommonTestData.receptionHandlerType, CommonTestData.receptionHandlerClassName, pHParameters);
+ CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME, pHParameters);
rHParameters.validate();
fail("test should throw an exception here");
} catch (final Exception e) {
@@ -126,11 +128,11 @@ public class TestReceptionHandlerParameters {
public void testReceptionHandlerParameters_InvalidReceptionHandlerClass() {
final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
final ReceptionHandlerParameters rHParameters =
- new ReceptionHandlerParameters(CommonTestData.receptionHandlerType,
- CommonTestData.receptionHandlerClassName + "Invalid", pHParameters);
+ new ReceptionHandlerParameters(CommonTestData.RECEPTION_HANDLER_TYPE,
+ CommonTestData.RECEPTION_HANDLER_CLASS_NAME + "Invalid", pHParameters);
final GroupValidationResult validationResult = rHParameters.validate();
- assertEquals(CommonTestData.receptionHandlerType, rHParameters.getReceptionHandlerType());
- assertEquals(CommonTestData.receptionHandlerClassName + "Invalid", rHParameters.getReceptionHandlerClassName());
+ assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType());
+ assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME + "Invalid", rHParameters.getReceptionHandlerClassName());
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/startstop/TestDistributionActivator.java b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java
new file mode 100644
index 00000000..6d1f83bf
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java
@@ -0,0 +1,65 @@
+/*-
+ * ============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.startstop;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+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;
+
+/**
+ * Class to perform unit test of DistributionActivator.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class TestDistributionActivator {
+
+ @Test
+ public void testDistributionActivator() throws PolicyDistributionException {
+ final String[] distributionConfigParameters = { "-c", "parameters/DistributionConfigParameters.json" };
+
+ final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
+ arguments.parse(distributionConfigParameters);
+
+ final DistributionParameterGroup parGroup = new DistributionParameterHandler().getParameters(arguments);
+
+ final DistributionActivator activator = new DistributionActivator(parGroup);
+ activator.initialize();
+ assertTrue(activator.getParameterGroup().isValid());
+ assertEquals(CommonTestData.DISTRIBUTION_GROUP_NAME, activator.getParameterGroup().getName());
+ assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE,
+ activator.getParameterGroup().getReceptionHandlerParameters()
+ .get(CommonTestData.SDC_RECEPTION_HANDLER_KEY).getReceptionHandlerType());
+ assertEquals(CommonTestData.DECODER_TYPE,
+ activator.getParameterGroup().getReceptionHandlerParameters()
+ .get(CommonTestData.SDC_RECEPTION_HANDLER_KEY).getPluginHandlerParameters().getPolicyDecoders()
+ .get(CommonTestData.TOSCA_DECODER_KEY).getDecoderType());
+ assertEquals(CommonTestData.FORWARDER_TYPE,
+ activator.getParameterGroup().getReceptionHandlerParameters()
+ .get(CommonTestData.SDC_RECEPTION_HANDLER_KEY).getPluginHandlerParameters()
+ .getPolicyForwarders().get(CommonTestData.PAP_ENGINE_FORWARDER_KEY).getForwarderType());
+ activator.deregisterToParameterService(parGroup);
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java
index 781a2ab8..124f49a6 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java
@@ -5,27 +5,69 @@
* 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.startstop;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import org.junit.Test;
+import org.onap.policy.distribution.main.PolicyDistributionException;
+import org.onap.policy.distribution.main.parameters.CommonTestData;
+/**
+ * Class to perform unit test of Main.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
public class TestMain {
@Test
- public void testMain() {
- Main.main(null);
+ public void testMain() throws PolicyDistributionException {
+ final String[] distributionConfigParameters = { "-c", "parameters/DistributionConfigParameters.json" };
+ final Main main = new Main(distributionConfigParameters);
+ assertTrue(main.getParameters().isValid());
+ assertEquals(CommonTestData.DISTRIBUTION_GROUP_NAME, main.getParameters().getName());
+ main.shutdown();
+ }
+
+ @Test
+ public void testMain_NoArguments() {
+ final String[] distributionConfigParameters = {};
+ final Main main = new Main(distributionConfigParameters);
+ assertTrue(main.getParameters() == null);
+ }
+
+ @Test
+ public void testMain_InvalidArguments() {
+ final String[] distributionConfigParameters = { "parameters/DistributionConfigParameters.json" };
+ final Main main = new Main(distributionConfigParameters);
+ assertTrue(main.getParameters() == null);
+ }
+
+ @Test
+ public void testMain_Help() {
+ final String[] distributionConfigParameters = { "-h" };
+ Main.main(distributionConfigParameters);
+ }
+
+ @Test
+ public void testMain_InvalidParameters() {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_InvalidName.json" };
+ final Main main = new Main(distributionConfigParameters);
+ assertTrue(main.getParameters() == null);
}
}