aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java/org/onap
diff options
context:
space:
mode:
authorramverma <ram.krishna.verma@ericsson.com>2018-08-08 23:17:37 +0100
committerramverma <ram.krishna.verma@ericsson.com>2018-08-09 21:51:51 +0100
commit550d0d986713f4da7b37b8f2b16264884c05b9ab (patch)
tree20efa2af8b1d11f13fca43fdd6d67834b4a03816 /main/src/test/java/org/onap
parentf85f63f52d38ca962fc0e68eae184dd7018dc47b (diff)
Adding configuration parameters for distribution
* Adding main configuration parameters to distribution component. The intention is to define a top level parameter group that should be capable of handling all the parameters needed for the framework. * Added validation to check the actuall class by loading it from classpath. * Added Test Cases for configuration parameter. The coverage of the package is 95.3 %. Change-Id: I87c4c34d9df2c9b5a0ab75bef2bbe0d25e38747b Issue-ID: POLICY-1035 Signed-off-by: ramverma <ram.krishna.verma@ericsson.com>
Diffstat (limited to 'main/src/test/java/org/onap')
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java114
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java137
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java356
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterGroup.java46
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterHandler.java127
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java101
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyDecoderParameters.java117
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java121
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java138
9 files changed, 1084 insertions, 173 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
new file mode 100644
index 00000000..953fa7b0
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java
@@ -0,0 +1,114 @@
+/*-
+ * ============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.parameters;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Class to hold/create all parameters for test cases.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class CommonTestData {
+
+ public static final String decoderType = "TOSCA";
+ public static final String decoderClassName =
+ "org.onap.policy.distribution.reception.decoding.pdpx.PolicyDecoderToscaPdpx";
+ public static final String forwarderType = "PAPEngine";
+ public static final String forwarderClassName =
+ "org.onap.policy.distribution.forwarding.pap.engine.XacmlPapServletPolicyForwarder";
+ public static final String receptionHandlerType = "SDCReceptionHandler";
+ public static final String receptionHandlerClassName =
+ "org.onap.policy.distribution.reception.handling.sdc.SdcReceptionHandler";
+
+ /**
+ * Returns an instance of ReceptionHandlerParameters for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return the receptionHandlerParameters object
+ */
+ public Map<String, ReceptionHandlerParameters> getReceptionHandlerParameters(final boolean isEmpty) {
+ final Map<String, ReceptionHandlerParameters> receptionHandlerParameters =
+ new HashMap<String, ReceptionHandlerParameters>();
+ 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);
+ }
+ return receptionHandlerParameters;
+ }
+
+ /**
+ * Returns an instance of PluginHandlerParameters for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return the pluginHandlerParameters object
+ */
+ public PluginHandlerParameters getPluginHandlerParameters(final boolean isEmpty) {
+ final Map<String, PolicyDecoderParameters> policyDecoders = getPolicyDecoders(isEmpty);
+ final Map<String, PolicyForwarderParameters> policyForwarders = getPolicyForwarders(isEmpty);
+ final PluginHandlerParameters pluginHandlerParameters =
+ new PluginHandlerParameters(policyDecoders, policyForwarders);
+ return pluginHandlerParameters;
+ }
+
+ /**
+ * Returns an instance of PolicyForwarderParameters for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return the policyForwarders object
+ */
+ public Map<String, PolicyForwarderParameters> getPolicyForwarders(final boolean isEmpty) {
+ 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);
+ }
+ return policyForwarders;
+ }
+
+ /**
+ * Returns an instance of PolicyDecoderParameters for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return the policyDecoders object
+ */
+ 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);
+ }
+ 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
new file mode 100644
index 00000000..cce432dc
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java
@@ -0,0 +1,137 @@
+/*-
+ * ============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.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+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;
+
+/**
+ * Class to perform unit test of DistributionParameterGroup.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class TestDistributionParameterGroup {
+ CommonTestData commonTestData = new CommonTestData();
+
+ @Test
+ public void testDistributionParameterGroup() {
+ final String name = "SDCDistributionGroup";
+ final Map<String, ReceptionHandlerParameters> receptionHandlerParameters =
+ commonTestData.getReceptionHandlerParameters(false);
+
+ final DistributionParameterGroup distributionParameters =
+ new DistributionParameterGroup(name, receptionHandlerParameters);
+ final GroupValidationResult validationResult = distributionParameters.validate();
+ assertTrue(validationResult.isValid());
+ assertEquals(name, distributionParameters.getName());
+ assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getReceptionHandlerType(),
+ distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ .getReceptionHandlerType());
+ assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getReceptionHandlerClassName(),
+ distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ .getReceptionHandlerClassName());
+ assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getPluginHandlerParameters(),
+ distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ .getPluginHandlerParameters());
+ }
+
+ @Test
+ public void testDistributionParameterGroup_NullName() {
+ final Map<String, ReceptionHandlerParameters> receptionHandlerParameters =
+ commonTestData.getReceptionHandlerParameters(false);
+
+ final DistributionParameterGroup distributionParameters =
+ new DistributionParameterGroup(null, receptionHandlerParameters);
+ final GroupValidationResult validationResult = distributionParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertEquals(null, distributionParameters.getName());
+ assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getReceptionHandlerType(),
+ distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ .getReceptionHandlerType());
+ assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getReceptionHandlerClassName(),
+ distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ .getReceptionHandlerClassName());
+ assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getPluginHandlerParameters(),
+ distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ .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 Map<String, ReceptionHandlerParameters> receptionHandlerParameters =
+ commonTestData.getReceptionHandlerParameters(false);
+
+ final DistributionParameterGroup distributionParameters =
+ new DistributionParameterGroup("", receptionHandlerParameters);
+ final GroupValidationResult validationResult = distributionParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertEquals("", distributionParameters.getName());
+ assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getReceptionHandlerType(),
+ distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ .getReceptionHandlerType());
+ assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getReceptionHandlerClassName(),
+ distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ .getReceptionHandlerClassName());
+ assertEquals(receptionHandlerParameters.get("SDCReceptionHandler").getPluginHandlerParameters(),
+ distributionParameters.getReceptionHandlerParameters().get("SDCReceptionHandler")
+ .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 String name = "SDCDistributionGroup";
+ try {
+ final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(name, null);
+ distributionParameters.validate();
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains("map parameter \"receptionHandlerParameters\" is null"));
+ }
+
+ }
+
+ @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);
+ distributionParameters.validate();
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains("parameter not a regular parameter: receptionHandlerParameters"));
+ }
+
+ }
+}
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
new file mode 100644
index 00000000..57610b23
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java
@@ -0,0 +1,356 @@
+/*-
+ * ============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.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.distribution.main.PolicyDistributionException;
+import org.onap.policy.distribution.main.startstop.DistributionCommandLineArguments;
+
+/**
+ * Class to perform unit test of DistributionParameterHandler.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class TestDistributionParameterHandler {
+ @Test
+ public void testParameterHandlerNoParameterFile() throws PolicyDistributionException {
+ final String[] noArgumentString = { "-c", "parameters/NoParameterFile.json" };
+
+ final DistributionCommandLineArguments noArguments = new DistributionCommandLineArguments();
+ noArguments.parse(noArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(noArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains("FileNotFoundException"));
+ }
+ }
+
+ @Test
+ public void testParameterHandlerEmptyParameters() throws PolicyDistributionException {
+ final String[] emptyArgumentString = { "-c", "parameters/EmptyParameters.json" };
+
+ final DistributionCommandLineArguments emptyArguments = new DistributionCommandLineArguments();
+ emptyArguments.parse(emptyArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(emptyArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("no parameters found in \"parameters/EmptyParameters.json\"", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerBadParameters() throws PolicyDistributionException {
+ final String[] badArgumentString = { "-c", "parameters/BadParameters.json" };
+
+ final DistributionCommandLineArguments badArguments = new DistributionCommandLineArguments();
+ badArguments.parse(badArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(badArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("error reading parameters from \"parameters/BadParameters.json\"\n"
+ + "(JsonSyntaxException):java.lang.IllegalStateException: "
+ + "Expected a string but was BEGIN_ARRAY at line 2 column 15 path $.name", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerInvalidParameters() throws PolicyDistributionException {
+ final String[] invalidArgumentString = { "-c", "parameters/InvalidParameters.json" };
+
+ final DistributionCommandLineArguments invalidArguments = new DistributionCommandLineArguments();
+ invalidArguments.parse(invalidArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(invalidArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("error reading parameters from \"parameters/InvalidParameters.json\"\n"
+ + "(JsonSyntaxException):java.lang.IllegalStateException: "
+ + "Expected a string but was BEGIN_ARRAY at line 2 column 15 path $.name", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerNoParameters() throws PolicyDistributionException {
+ final String[] noArgumentString = { "-c", "parameters/NoParameters.json" };
+
+ final DistributionCommandLineArguments noArguments = new DistributionCommandLineArguments();
+ noArguments.parse(noArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(noArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("map parameter \"receptionHandlerParameters\" is null", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerMinumumParameters() throws PolicyDistributionException {
+ final String[] minArgumentString = { "-c", "parameters/MinimumParameters.json" };
+
+ final DistributionCommandLineArguments minArguments = new DistributionCommandLineArguments();
+ minArguments.parse(minArgumentString);
+
+ final DistributionParameterGroup parGroup = new DistributionParameterHandler().getParameters(minArguments);
+ assertEquals("SDCDistributionGroup", parGroup.getName());
+ }
+
+ @Test
+ public void testDistributionParameterGroup() throws PolicyDistributionException {
+ final String[] distributionConfigParameters = { "-c", "parameters/DistributionConfigParameters.json" };
+
+ final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
+ 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());
+ }
+
+ @Test
+ public void testDistributionParameterGroup_InvalidName() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_InvalidName.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(
+ "field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_InvalidReceptionHandlerType() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_InvalidReceptionHandlerType.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("field \"receptionHandlerType\" type \"java.lang.String\" value \" \" INVALID, "
+ + "must be a non-blank string"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_InvalidPolicyDecoderType() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_InvalidPolicyDecoderType.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(
+ "field \"decoderType\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_InvalidPolicyForwarderType() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_InvalidPolicyForwarderType.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("field \"forwarderType\" type \"java.lang.String\" value \" \" INVALID, "
+ + "must be a non-blank string"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_NoReceptionHandler() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_NoReceptionHandler.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("map parameter \"receptionHandlerParameters\" is null"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_EmptyReceptionHandler() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_EmptyReceptionHandler.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 not a regular parameter: receptionHandlerParameters"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_NoPolicyDecoder() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_NoPolicyDecoder.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("map parameter \"policyDecoders\" is null"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_NoPolicyForwarder() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_NoPolicyForwarder.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("map parameter \"policyForwarders\" is null"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_EmptyPolicyDecoder() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_EmptyPolicyDecoder.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 not a regular parameter: policyDecoders"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_EmptyPolicyForwarder() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_EmptyPolicyForwarder.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 not a regular parameter: policyForwarders"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_InvalidReceptionHandlerClass() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_InvalidReceptionHandlerClass.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("reception handler class not found in classpath"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_InvalidPolicyDecoderClass() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_InvalidPolicyDecoderClass.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("policy decoder class not found in classpath"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_InvalidPolicyForwarderClass() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_InvalidPolicyForwarderClass.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("policy forwarder class not found in classpath"));
+ }
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterGroup.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterGroup.java
deleted file mode 100644
index bf553918..00000000
--- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterGroup.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*-
- * ============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.parameters;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-public class TestParameterGroup {
-
- @Test
- public void testParameterGroup() {
- DistributionParameterGroup parameterGroup = new DistributionParameterGroup("groupName");
- assertEquals("groupName", parameterGroup.getName());
- assertTrue(parameterGroup.isValid());
-
- parameterGroup = new DistributionParameterGroup(null);
- assertNull(parameterGroup.getName());
- assertFalse(parameterGroup.isValid());
-
- parameterGroup = new DistributionParameterGroup("");
- assertEquals("", parameterGroup.getName());
- assertFalse(parameterGroup.isValid());
- }
-}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterHandler.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterHandler.java
deleted file mode 100644
index 5b938988..00000000
--- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterHandler.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*-
- * ============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.parameters;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import org.junit.Test;
-import org.onap.policy.distribution.main.PolicyDistributionException;
-import org.onap.policy.distribution.main.startstop.DistributionCommandLineArguments;
-
-public class TestParameterHandler {
- @Test
- public void testParameterHandlerNoParameterFile() throws PolicyDistributionException {
- String[] noArgumentString = { "-c", "parameters/NoParameterFile.json" };
-
- DistributionCommandLineArguments noArguments = new DistributionCommandLineArguments();
- noArguments.parse(noArgumentString);
-
- try {
- new DistributionParameterHandler().getParameters(noArguments);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("error reading parameters from \"parameters/NoParameterFile.json\"\n"
- + "(FileNotFoundException):parameters/NoParameterFile.json (No such file or directory)",
- e.getMessage());
- }
- }
-
- @Test
- public void testParameterHandlerEmptyParameters() throws PolicyDistributionException {
- String[] emptyArgumentString = { "-c", "parameters/EmptyParameters.json" };
-
- DistributionCommandLineArguments emptyArguments = new DistributionCommandLineArguments();
- emptyArguments.parse(emptyArgumentString);
-
- try {
- new DistributionParameterHandler().getParameters(emptyArguments);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("no parameters found in \"parameters/EmptyParameters.json\"", e.getMessage());
- }
- }
-
- @Test
- public void testParameterHandlerBadParameters() throws PolicyDistributionException {
- String[] badArgumentString = { "-c", "parameters/BadParameters.json" };
-
- DistributionCommandLineArguments badArguments = new DistributionCommandLineArguments();
- badArguments.parse(badArgumentString);
-
- try {
- new DistributionParameterHandler().getParameters(badArguments);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("error reading parameters from \"parameters/BadParameters.json\"\n"
- + "(JsonSyntaxException):java.lang.IllegalStateException: "
- + "Expected a string but was BEGIN_ARRAY at line 2 column 15 path $.name", e.getMessage());
- }
- }
-
- @Test
- public void testParameterHandlerInvalidParameters() throws PolicyDistributionException {
- String[] invalidArgumentString = { "-c", "parameters/InvalidParameters.json" };
-
- DistributionCommandLineArguments invalidArguments = new DistributionCommandLineArguments();
- invalidArguments.parse(invalidArgumentString);
-
- try {
- new DistributionParameterHandler().getParameters(invalidArguments);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("error reading parameters from \"parameters/InvalidParameters.json\"\n"
- + "(JsonSyntaxException):java.lang.IllegalStateException: "
- + "Expected a string but was BEGIN_ARRAY at line 2 column 15 path $.name", e.getMessage());
- }
- }
-
- @Test
- public void testParameterHandlerNoParameters() throws PolicyDistributionException {
- String[] noArgumentString = { "-c", "parameters/NoParameters.json" };
-
- DistributionCommandLineArguments noArguments = new DistributionCommandLineArguments();
- noArguments.parse(noArgumentString);
-
- try {
- new DistributionParameterHandler().getParameters(noArguments);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("validation error(s) on parameters from \"parameters/NoParameters.json\"\n"
- + "parameter group \"null\" type "
- + "\"org.onap.policy.distribution.main.parameters.DistributionParameterGroup\""
- + " INVALID, parameter group has status INVALID\n"
- + " field \"name\" type \"java.lang.String\" value \"null\" INVALID, must be a non-blank string\n",
- e.getMessage());
- }
- }
-
- @Test
- public void testParameterHandlerMinumumParameters() throws PolicyDistributionException {
- String[] minArgumentString = { "-c", "parameters/MinimumParameters.json" };
-
- DistributionCommandLineArguments minArguments = new DistributionCommandLineArguments();
- minArguments.parse(minArgumentString);
-
- DistributionParameterGroup parGroup = new DistributionParameterHandler().getParameters(minArguments);
- assertEquals("nameFromFile", parGroup.getName());
- }
-}
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
new file mode 100644
index 00000000..b2d732e9
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java
@@ -0,0 +1,101 @@
+/*-
+ * ============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.parameters;
+
+import static org.junit.Assert.assertEquals;
+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;
+
+/**
+ * Class to perform unit test of PluginHandlerParameters.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class TestPluginHandlerParameters {
+ CommonTestData commonTestData = new CommonTestData();
+
+ @Test
+ public void testPluginHandlerParameters() {
+ final Map<String, PolicyDecoderParameters> policyDecoders = commonTestData.getPolicyDecoders(false);
+ 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"));
+ assertTrue(validationResult.isValid());
+ }
+
+ @Test
+ public void testPluginHandlerParameters_NullPolicyDecoders() {
+ try {
+ final Map<String, PolicyForwarderParameters> policyForwarders = commonTestData.getPolicyForwarders(false);
+ final PluginHandlerParameters pHParameters = new PluginHandlerParameters(null, policyForwarders);
+ pHParameters.validate();
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains("map parameter \"policyDecoders\" is null"));
+ }
+ }
+
+ @Test
+ public void testPluginHandlerParameters_NullPolicyForwarders() {
+ try {
+ final Map<String, PolicyDecoderParameters> policyDecoders = commonTestData.getPolicyDecoders(false);
+ final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyDecoders, null);
+ pHParameters.validate();
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains("map parameter \"policyForwarders\" is null"));
+ }
+ }
+
+ @Test
+ public void testPluginHandlerParameters_EmptyPolicyDecoders() {
+ try {
+ final Map<String, PolicyDecoderParameters> policyDecoders = commonTestData.getPolicyDecoders(true);
+ final Map<String, PolicyForwarderParameters> policyForwarders = commonTestData.getPolicyForwarders(false);
+ final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyDecoders, policyForwarders);
+ pHParameters.validate();
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains("parameter not a regular parameter: policyDecoders"));
+ }
+ }
+
+ @Test
+ public void testPluginHandlerParameters_EmptyPolicyForwarders() {
+ try {
+ final Map<String, PolicyForwarderParameters> policyForwarders = commonTestData.getPolicyForwarders(true);
+ final Map<String, PolicyDecoderParameters> policyDecoders = commonTestData.getPolicyDecoders(false);
+ final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyDecoders, policyForwarders);
+ pHParameters.validate();
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains("parameter not a regular parameter: policyForwarders"));
+ }
+ }
+}
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
new file mode 100644
index 00000000..bcae6df6
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyDecoderParameters.java
@@ -0,0 +1,117 @@
+/*-
+ * ============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.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+
+/**
+ * Class to perform unit test of PolicyDecoderParameters.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class TestPolicyDecoderParameters {
+
+ @Test
+ public void testPolicyDecoderParameters() {
+ final PolicyDecoderParameters pDParameters =
+ new PolicyDecoderParameters(CommonTestData.decoderType, CommonTestData.decoderClassName);
+ final GroupValidationResult validationResult = pDParameters.validate();
+ assertEquals(CommonTestData.decoderType, pDParameters.getDecoderType());
+ assertEquals(CommonTestData.decoderClassName, pDParameters.getDecoderClassName());
+ assertTrue(validationResult.isValid());
+ }
+
+ @Test
+ public void testPolicyDecoderParameters_InvalidDecoderType() {
+ final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters("", CommonTestData.decoderClassName);
+ final GroupValidationResult validationResult = pDParameters.validate();
+ assertEquals("", pDParameters.getDecoderType());
+ assertEquals(CommonTestData.decoderClassName, pDParameters.getDecoderClassName());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult().contains(
+ "field \"decoderType\" type \"java.lang.String\" value \"\" INVALID, must be a non-blank string"));
+ }
+
+ @Test
+ public void testPolicyDecoderParameters_InvalidDecoderClassName() {
+ final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(CommonTestData.decoderType, "");
+ final GroupValidationResult validationResult = pDParameters.validate();
+ assertEquals(CommonTestData.decoderType, pDParameters.getDecoderType());
+ assertEquals("", pDParameters.getDecoderClassName());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("field \"decoderClassName\" type \"java.lang.String\" value \"\" INVALID, "
+ + "must be a non-blank string containing full class name of the decoder"));
+ }
+
+ @Test
+ public void testPolicyDecoderParameters_InvalidDecoderTypeAndClassName() {
+ final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters("", "");
+ final GroupValidationResult validationResult = pDParameters.validate();
+ assertEquals("", pDParameters.getDecoderType());
+ assertEquals("", pDParameters.getDecoderClassName());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult().contains(
+ "field \"decoderType\" type \"java.lang.String\" value \"\" INVALID, must be a non-blank string"));
+ assertTrue(validationResult.getResult()
+ .contains("field \"decoderClassName\" type \"java.lang.String\" value \"\" INVALID, "
+ + "must be a non-blank string containing full class name of the decoder"));
+ }
+
+ @Test
+ public void testPolicyDecoderParameters_NullDecoderType() {
+ final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(null, CommonTestData.decoderClassName);
+ final GroupValidationResult validationResult = pDParameters.validate();
+ assertEquals(null, pDParameters.getDecoderType());
+ assertEquals(CommonTestData.decoderClassName, pDParameters.getDecoderClassName());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult().contains(
+ "field \"decoderType\" type \"java.lang.String\" value \"null\" INVALID, must be a non-blank string"));
+ }
+
+ @Test
+ public void testPolicyDecoderParameters_NullDecoderClassName() {
+ final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(CommonTestData.decoderType, null);
+ final GroupValidationResult validationResult = pDParameters.validate();
+ assertEquals(CommonTestData.decoderType, pDParameters.getDecoderType());
+ assertEquals(null, pDParameters.getDecoderClassName());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("field \"decoderClassName\" type \"java.lang.String\" value \"null\" INVALID, "
+ + "must be a non-blank string containing full class name of the decoder"));
+ }
+
+ @Test
+ public void testPolicyDecoderParameters_InvalidDecoderClass() {
+ final PolicyDecoderParameters pDParameters =
+ new PolicyDecoderParameters(CommonTestData.decoderType, CommonTestData.decoderClassName + "Invalid");
+ final GroupValidationResult validationResult = pDParameters.validate();
+ assertEquals(CommonTestData.decoderType, pDParameters.getDecoderType());
+ assertEquals(CommonTestData.decoderClassName + "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
new file mode 100644
index 00000000..bbcbc370
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java
@@ -0,0 +1,121 @@
+/*-
+ * ============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.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+
+/**
+ * Class to perform unit test of PolicyForwarderParameters.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class TestPolicyForwarderParameters {
+
+ @Test
+ public void testPolicyForwarderParameters() {
+ final PolicyForwarderParameters pFParameters =
+ new PolicyForwarderParameters(CommonTestData.forwarderType, CommonTestData.forwarderClassName);
+ final GroupValidationResult validationResult = pFParameters.validate();
+ assertEquals(CommonTestData.forwarderType, pFParameters.getForwarderType());
+ assertEquals(CommonTestData.forwarderClassName, pFParameters.getForwarderClassName());
+ assertTrue(validationResult.isValid());
+ }
+
+ @Test
+ public void testPolicyForwarderParameters_InvalidForwarderType() {
+ final PolicyForwarderParameters pFParameters =
+ new PolicyForwarderParameters("", CommonTestData.forwarderClassName);
+ final GroupValidationResult validationResult = pFParameters.validate();
+ assertEquals("", pFParameters.getForwarderType());
+ assertEquals(CommonTestData.forwarderClassName, pFParameters.getForwarderClassName());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult().contains(
+ "field \"forwarderType\" type \"java.lang.String\" value \"\" INVALID, must be a non-blank string"));
+ }
+
+ @Test
+ public void testPolicyForwarderParameters_InvalidForwarderClassName() {
+ final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(CommonTestData.forwarderType, "");
+ final GroupValidationResult validationResult = pFParameters.validate();
+ assertEquals(CommonTestData.forwarderType, pFParameters.getForwarderType());
+ assertEquals("", pFParameters.getForwarderClassName());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("field \"forwarderClassName\" type \"java.lang.String\" value \"\" INVALID, "
+ + "must be a non-blank string containing full class name of the forwarder"));
+ }
+
+ @Test
+ public void testPolicyForwarderParameters_InvalidForwarderTypeAndClassName() {
+ final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters("", "");
+ final GroupValidationResult validationResult = pFParameters.validate();
+ assertEquals("", pFParameters.getForwarderType());
+ assertEquals("", pFParameters.getForwarderClassName());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult().contains(
+ "field \"forwarderType\" type \"java.lang.String\" value \"\" INVALID, must be a non-blank string"));
+ assertTrue(validationResult.getResult()
+ .contains("field \"forwarderClassName\" type \"java.lang.String\" value \"\" INVALID, "
+ + "must be a non-blank string containing full class name of the forwarder"));
+ }
+
+ @Test
+ public void testPolicyForwarderParameters_NullForwarderType() {
+ final PolicyForwarderParameters pFParameters =
+ new PolicyForwarderParameters(null, CommonTestData.forwarderClassName);
+ final GroupValidationResult validationResult = pFParameters.validate();
+ assertEquals(null, pFParameters.getForwarderType());
+ assertEquals(CommonTestData.forwarderClassName, pFParameters.getForwarderClassName());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("field \"forwarderType\" type \"java.lang.String\" value \"null\" INVALID, "
+ + "must be a non-blank string"));
+ }
+
+ @Test
+ public void testPolicyForwarderParameters_NullForwarderClassName() {
+ final PolicyForwarderParameters pFParameters =
+ new PolicyForwarderParameters(CommonTestData.forwarderType, null);
+ final GroupValidationResult validationResult = pFParameters.validate();
+ assertEquals(CommonTestData.forwarderType, pFParameters.getForwarderType());
+ assertEquals(null, pFParameters.getForwarderClassName());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("field \"forwarderClassName\" type \"java.lang.String\" value \"null\" INVALID, "
+ + "must be a non-blank string containing full class name of the forwarder"));
+ }
+
+ @Test
+ public void testPolicyForwarderParameters_InvalidForwarderClass() {
+ final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(CommonTestData.forwarderType,
+ CommonTestData.forwarderClassName + "Invalid");
+ final GroupValidationResult validationResult = pFParameters.validate();
+ assertEquals(CommonTestData.forwarderType, pFParameters.getForwarderType());
+ assertEquals(CommonTestData.forwarderClassName + "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
new file mode 100644
index 00000000..5eb113de
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java
@@ -0,0 +1,138 @@
+/*-
+ * ============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.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+
+/**
+ * Class to perform unit test of ReceptionHandlerParameters.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class TestReceptionHandlerParameters {
+ CommonTestData commonTestData = new CommonTestData();
+
+ @Test
+ public void testReceptionHandlerParameters() {
+ final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
+ final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters(
+ CommonTestData.receptionHandlerType, CommonTestData.receptionHandlerClassName, pHParameters);
+ final GroupValidationResult validationResult = rHParameters.validate();
+ assertEquals(CommonTestData.receptionHandlerType, rHParameters.getReceptionHandlerType());
+ assertEquals(CommonTestData.receptionHandlerClassName, rHParameters.getReceptionHandlerClassName());
+ assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
+ assertTrue(validationResult.isValid());
+ }
+
+ @Test
+ public void testReceptionHandlerParameters_NullReceptionHandlerType() {
+ final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
+ final ReceptionHandlerParameters rHParameters =
+ new ReceptionHandlerParameters(null, CommonTestData.receptionHandlerClassName, pHParameters);
+ final GroupValidationResult validationResult = rHParameters.validate();
+ assertEquals(null, rHParameters.getReceptionHandlerType());
+ assertEquals(CommonTestData.receptionHandlerClassName, rHParameters.getReceptionHandlerClassName());
+ 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"));
+ }
+
+ @Test
+ public void testReceptionHandlerParameters_NullReceptionHandlerClassName() {
+ final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
+ final ReceptionHandlerParameters rHParameters =
+ new ReceptionHandlerParameters(CommonTestData.receptionHandlerType, null, pHParameters);
+ final GroupValidationResult validationResult = rHParameters.validate();
+ assertEquals(CommonTestData.receptionHandlerType, rHParameters.getReceptionHandlerType());
+ assertEquals(null, rHParameters.getReceptionHandlerClassName());
+ 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"));
+ }
+
+ @Test
+ public void testReceptionHandlerParameters_EmptyReceptionHandlerType() {
+ final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
+
+ final ReceptionHandlerParameters rHParameters =
+ new ReceptionHandlerParameters("", CommonTestData.receptionHandlerClassName, pHParameters);
+ final GroupValidationResult validationResult = rHParameters.validate();
+ assertEquals("", rHParameters.getReceptionHandlerType());
+ assertEquals(CommonTestData.receptionHandlerClassName, 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"));
+ }
+
+ @Test
+ public void testReceptionHandlerParameters_EmptyReceptionHandlerClassName() {
+ final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
+ final ReceptionHandlerParameters rHParameters =
+ new ReceptionHandlerParameters(CommonTestData.receptionHandlerType, "", pHParameters);
+ final GroupValidationResult validationResult = rHParameters.validate();
+ assertEquals(CommonTestData.receptionHandlerType, rHParameters.getReceptionHandlerType());
+ assertEquals("", rHParameters.getReceptionHandlerClassName());
+ 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"));
+ }
+
+ @Test
+ public void testReceptionHandlerParameters_EmptyPluginHandler() {
+ try {
+ final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(true);
+ final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters(
+ CommonTestData.receptionHandlerType, CommonTestData.receptionHandlerClassName, pHParameters);
+ rHParameters.validate();
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains("parameter not a regular parameter: policyDecoders"));
+ }
+ }
+
+ @Test
+ public void testReceptionHandlerParameters_InvalidReceptionHandlerClass() {
+ final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
+ final ReceptionHandlerParameters rHParameters =
+ new ReceptionHandlerParameters(CommonTestData.receptionHandlerType,
+ CommonTestData.receptionHandlerClassName + "Invalid", pHParameters);
+ final GroupValidationResult validationResult = rHParameters.validate();
+ assertEquals(CommonTestData.receptionHandlerType, rHParameters.getReceptionHandlerType());
+ assertEquals(CommonTestData.receptionHandlerClassName + "Invalid", rHParameters.getReceptionHandlerClassName());
+ assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult().contains("reception handler class not found in classpath"));
+ }
+}