summaryrefslogtreecommitdiffstats
path: root/reception
diff options
context:
space:
mode:
authorramverma <ram.krishna.verma@ericsson.com>2018-08-16 16:43:20 +0100
committerramverma <ram.krishna.verma@ericsson.com>2018-08-16 16:43:58 +0100
commit612196451afe9b16b8914858dd58f3bb0dae8579 (patch)
tree0a3d2c5991fe33594224dbf359db8fcdda588084 /reception
parent84beaf8d12f1badc27b4744a4949f8a586370ea9 (diff)
Adding termination code changes for distribution
* Code changes for terminating the handlers started by distribution activator. * More test cases to increase coverage. * Fixes for checkstyle issues. * Fixes for sonar issues. Change-Id: I3299317c83fa643ac1d0ba1105ac1a932c0a83f6 Issue-ID: POLICY-1035 Signed-off-by: ramverma <ram.krishna.verma@ericsson.com>
Diffstat (limited to 'reception')
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java6
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java35
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/handling/ReceptionHandler.java8
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/parameters/PluginHandlerParameters.java4
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java8
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java10
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/decoding/PolicyDecodingExceptionTest.java13
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java115
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyDecoder.java59
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyPolicyForwarder.java52
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyReceptionHandler.java35
11 files changed, 255 insertions, 90 deletions
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java b/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java
index 94bcc65a..eeb1ead1 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java
@@ -34,10 +34,10 @@ import org.onap.policy.distribution.reception.decoding.PolicyDecoder;
import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters;
-/***
+/**
* Base implementation of {@link ReceptionHandler}. All reception handlers should extend this base class by implementing
* the {@link #initializeReception(String)} method to perform the specific initialization required to receive inputs and
- * by invoking {@link #inputReceived(PolicyInput)} when the reception handler receives input
+ * by invoking {@link #inputReceived(PolicyInput)} when the reception handler receives input.
*/
public abstract class AbstractReceptionHandler implements ReceptionHandler {
@@ -55,7 +55,7 @@ public abstract class AbstractReceptionHandler implements ReceptionHandler {
/**
* Sub classes must implement this method to perform the specific initialization required to receive inputs, for
- * example setting up subscriptions
+ * example setting up subscriptions.
*
* @param parameterGroupName the parameter group name
*/
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java b/reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java
index 7afc5814..37638b59 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java
@@ -24,6 +24,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.distribution.forwarding.PolicyForwarder;
import org.onap.policy.distribution.forwarding.PolicyForwardingException;
@@ -40,6 +42,8 @@ import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters
*/
public class PluginHandler {
+ private static final Logger LOGGER = FlexLogger.getLogger(PluginHandler.class);
+
private Collection<PolicyDecoder<PolicyInput, Policy>> policyDecoders;
private Collection<PolicyForwarder> policyForwarders;
@@ -47,8 +51,8 @@ public class PluginHandler {
* Create an instance to instantiate plugins based on the given parameter group.
*
* @param parameterGroupName the name of the parameter group
- * @throws PolicyDecodingException
- * @throws PolicyForwardingException
+ * @throws PolicyDecodingException exception if it occurs
+ * @throws PolicyForwardingException exception if it occurs
*/
public PluginHandler(final String parameterGroupName) throws PolicyDecodingException, PolicyForwardingException {
final PluginHandlerParameters params = (PluginHandlerParameters) ParameterService.get(parameterGroupName);
@@ -77,41 +81,44 @@ public class PluginHandler {
/**
* Initialize policy decoders.
*
- * @param policyDecoderParameters
- * @throws PolicyDecodingException
+ * @param policyDecoderParameters exception if it occurs
+ * @throws PolicyDecodingException exception if it occurs
*/
@SuppressWarnings("unchecked")
private void initializePolicyDecoders(final Map<String, PolicyDecoderParameters> policyDecoderParameters)
throws PolicyDecodingException {
- policyDecoders = new ArrayList<PolicyDecoder<PolicyInput, Policy>>();
- for (final PolicyDecoderParameters pDParameters : policyDecoderParameters.values()) {
+ policyDecoders = new ArrayList<>();
+ for (final PolicyDecoderParameters decoderParameters : policyDecoderParameters.values()) {
try {
final Class<PolicyDecoder<PolicyInput, Policy>> policyDecoderClass =
- (Class<PolicyDecoder<PolicyInput, Policy>>) Class.forName(pDParameters.getDecoderClassName());
+ (Class<PolicyDecoder<PolicyInput, Policy>>) Class
+ .forName(decoderParameters.getDecoderClassName());
final PolicyDecoder<PolicyInput, Policy> decoder = policyDecoderClass.newInstance();
policyDecoders.add(decoder);
} catch (final ClassNotFoundException | InstantiationException | IllegalAccessException exp) {
- throw new PolicyDecodingException(exp.getMessage());
+ LOGGER.error("exception occured while initializing decoders", exp);
+ throw new PolicyDecodingException(exp.getMessage(), exp.getCause());
}
}
}
/**
- * Initialize policy forwarders
+ * Initialize policy forwarders.
*
- * @param policyForwarderParameters
- * @throws PolicyForwardingException
+ * @param policyForwarderParameters exception if it occurs
+ * @throws PolicyForwardingException exception if it occurs
*/
@SuppressWarnings("unchecked")
private void initializePolicyForwarders(final Map<String, PolicyForwarderParameters> policyForwarderParameters)
throws PolicyForwardingException {
- policyForwarders = new ArrayList<PolicyForwarder>();
- for (final PolicyForwarderParameters pFParameters : policyForwarderParameters.values()) {
+ policyForwarders = new ArrayList<>();
+ for (final PolicyForwarderParameters forwarderParameters : policyForwarderParameters.values()) {
try {
final Class<PolicyForwarder> policyForwarderClass =
- (Class<PolicyForwarder>) Class.forName(pFParameters.getForwarderClassName());
+ (Class<PolicyForwarder>) Class.forName(forwarderParameters.getForwarderClassName());
policyForwarders.add(policyForwarderClass.newInstance());
} catch (final ClassNotFoundException | InstantiationException | IllegalAccessException exp) {
+ LOGGER.error("exception occured while initializing forwarders", exp);
throw new PolicyForwardingException(exp.getMessage(), exp.getCause());
}
}
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/handling/ReceptionHandler.java b/reception/src/main/java/org/onap/policy/distribution/reception/handling/ReceptionHandler.java
index c3a7544d..5f2e3716 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/handling/ReceptionHandler.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/handling/ReceptionHandler.java
@@ -29,16 +29,16 @@ import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
public interface ReceptionHandler {
/**
- * Initialize the reception handler with the given parameters
+ * Initialize the reception handler with the given parameters.
*
* @param parameterGroupName the name of the parameter group containing the configuration for the reception handler
- * @throws PolicyDecodingException
- * @throws PolicyForwardingException
+ * @throws PolicyDecodingException exception if it occurs
+ * @throws PolicyForwardingException exception if it occurs
*/
void initialize(String parameterGroupName) throws PolicyDecodingException, PolicyForwardingException;
/**
- * Destroy the reception handler, removing any subscriptions and releasing all resources
+ * Destroy the reception handler, removing any subscriptions and releasing all resources.
*/
void destroy();
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PluginHandlerParameters.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PluginHandlerParameters.java
index 7e16518b..c752020b 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PluginHandlerParameters.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PluginHandlerParameters.java
@@ -105,7 +105,9 @@ public class PluginHandlerParameters implements ParameterGroup {
}
/**
- * @param name the name to set
+ * Set the name of this group.
+ *
+ * @param name the name to set.
*/
public void setName(final String name) {
this.name = name;
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java
index 59c59e16..6157b8b6 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java
@@ -20,6 +20,8 @@
package org.onap.policy.distribution.reception.parameters;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.parameters.ParameterGroup;
import org.onap.policy.common.parameters.ValidationStatus;
@@ -30,6 +32,9 @@ import org.onap.policy.common.parameters.ValidationStatus;
* @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
*/
public class PolicyDecoderParameters implements ParameterGroup {
+
+ private static final Logger LOGGER = FlexLogger.getLogger(PolicyDecoderParameters.class);
+
private String decoderType;
private String decoderClassName;
@@ -89,7 +94,8 @@ public class PolicyDecoderParameters implements ParameterGroup {
private void validatePolicyDecoderClass(final GroupValidationResult validationResult) {
try {
Class.forName(decoderClassName);
- } catch (final ClassNotFoundException e) {
+ } catch (final ClassNotFoundException exp) {
+ LOGGER.error("policy decoder class not found in classpath", exp);
validationResult.setResult("decoderClassName", ValidationStatus.INVALID,
"policy decoder class not found in classpath");
}
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java
index 54979ab2..974436aa 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java
@@ -20,6 +20,8 @@
package org.onap.policy.distribution.reception.parameters;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.parameters.ParameterGroup;
import org.onap.policy.common.parameters.ValidationStatus;
@@ -30,6 +32,9 @@ import org.onap.policy.common.parameters.ValidationStatus;
* @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
*/
public class ReceptionHandlerParameters implements ParameterGroup {
+
+ private static final Logger LOGGER = FlexLogger.getLogger(ReceptionHandlerParameters.class);
+
private String name;
private String receptionHandlerType;
private String receptionHandlerClassName;
@@ -109,13 +114,16 @@ public class ReceptionHandlerParameters implements ParameterGroup {
private void validateReceptionHandlerClass(final GroupValidationResult validationResult) {
try {
Class.forName(receptionHandlerClassName);
- } catch (final ClassNotFoundException e) {
+ } catch (final ClassNotFoundException exp) {
+ LOGGER.error("reception handler class not found in classpath", exp);
validationResult.setResult("receptionHandlerClassName", ValidationStatus.INVALID,
"reception handler class not found in classpath");
}
}
/**
+ * Set the name of this group.
+ *
* @param name the name to set
*/
public void setName(final String name) {
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/decoding/PolicyDecodingExceptionTest.java b/reception/src/test/java/org/onap/policy/distribution/reception/decoding/PolicyDecodingExceptionTest.java
index eba19503..a5bc072e 100644
--- a/reception/src/test/java/org/onap/policy/distribution/reception/decoding/PolicyDecodingExceptionTest.java
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/decoding/PolicyDecodingExceptionTest.java
@@ -5,15 +5,15 @@
* 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=========================================================
*/
@@ -21,20 +21,21 @@
package org.onap.policy.distribution.reception.decoding;
import static org.junit.Assert.assertEquals;
+
import org.junit.Test;
public class PolicyDecodingExceptionTest {
@Test
public void testPolicyDecodingExceptionString() {
- PolicyDecodingException policyDecodingException = new PolicyDecodingException("error message");
+ final PolicyDecodingException policyDecodingException = new PolicyDecodingException("error message");
assertEquals("error message", policyDecodingException.getMessage());
}
@Test
public void testPolicyDecodingExceptionStringThrowable() {
- Exception cause = new IllegalArgumentException();
- PolicyDecodingException policyDecodingException = new PolicyDecodingException("error message", cause);
+ final Exception cause = new IllegalArgumentException();
+ final PolicyDecodingException policyDecodingException = new PolicyDecodingException("error message", cause);
assertEquals("error message", policyDecodingException.getMessage());
assertEquals(cause, policyDecodingException.getCause());
}
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java b/reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java
index 7f9bb403..bb9b542a 100644
--- a/reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java
@@ -27,19 +27,38 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Test;
+import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.distribution.forwarding.PolicyForwarder;
import org.onap.policy.distribution.forwarding.PolicyForwardingException;
+import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
import org.onap.policy.distribution.model.Policy;
import org.onap.policy.distribution.model.PolicyInput;
import org.onap.policy.distribution.reception.decoding.PolicyDecoder;
import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
+import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters;
+import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters;
+/**
+ * Class to perform unit test of AbstractReceptionHandler.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
public class AbstractReceptionHandlerTest {
- // These tests won't work any more because we use Parameter Service for starting the plugins.
- // Will rewrite them while implementing AbstractReceptionHandler.inputRecieved() method.
- // @Test
+ private static final String DISTRIBUTION_GROUP = "DummyDistributionGroup";
+ private static final String DECODER_TYPE = "DummyDecoder";
+ private static final String DECODER_CLASS_NAME = "org.onap.policy.distribution.reception.handling.DummyDecoder";
+ private static final String DECODER_KEY = "DummyDecoderKey";
+ private static final String FORWARDER_KEY = "DummyForwarderKey";
+ private static final String FORWARDER_TYPE = "DummyForwarder";
+ private static final String FORWARDER_CLASS_NAME =
+ "org.onap.policy.distribution.reception.handling.DummyPolicyForwarder";
+
+ @Test
public void testInputReceived() throws PolicyDecodingException, NoSuchFieldException, SecurityException,
IllegalArgumentException, IllegalAccessException, PolicyForwardingException {
final AbstractReceptionHandler handler = new DummyReceptionHandler();
@@ -75,7 +94,7 @@ public class AbstractReceptionHandlerTest {
assertTrue(policyForwarder2.receivedPolicy(generatedPolicy2));
}
- // @Test(expected = PolicyDecodingException.class)
+ @Test(expected = PolicyDecodingException.class)
public void testInputReceivedNoSupportingDecoder() throws PolicyDecodingException, NoSuchFieldException,
SecurityException, IllegalArgumentException, IllegalAccessException, PolicyForwardingException {
final AbstractReceptionHandler handler = new DummyReceptionHandler();
@@ -87,7 +106,7 @@ public class AbstractReceptionHandlerTest {
handler.inputReceived(new DummyPolicyInput());
}
- // @Test(expected = PolicyDecodingException.class)
+ @Test(expected = PolicyDecodingException.class)
public void testInputReceivedNoDecoder() throws PolicyDecodingException, NoSuchFieldException, SecurityException,
IllegalArgumentException, IllegalAccessException, PolicyForwardingException {
final AbstractReceptionHandler handler = new DummyReceptionHandler();
@@ -98,72 +117,23 @@ public class AbstractReceptionHandlerTest {
handler.inputReceived(new DummyPolicyInput());
}
- class DummyReceptionHandler extends AbstractReceptionHandler {
- @Override
- protected void initializeReception(final String parameterGroupName) {}
-
- @Override
- public void destroy() {}
- }
-
class DummyPolicyInput implements PolicyInput {
}
- class DummyPolicy1 implements Policy {
- }
- class DummyPolicy2 implements Policy {
- }
-
- public class DummyDecoder implements PolicyDecoder<PolicyInput, Policy> {
-
- private boolean canHandleValue;
- private Collection<Policy> policesToReturn;
-
- public DummyDecoder(final boolean canHandleValue, final Collection<Policy> policesToReturn) {
- this.canHandleValue = canHandleValue;
- this.policesToReturn = policesToReturn;
- }
- @Override
- public boolean canHandle(final PolicyInput policyInput) {
- return canHandleValue;
- }
-
- @Override
- public Collection<Policy> decode(final PolicyInput input) throws PolicyDecodingException {
- return policesToReturn;
- }
+ class DummyPolicy1 implements Policy {
}
- public class DummyPolicyForwarder implements PolicyForwarder {
- private int numberOfPoliciesReceived = 0;
- private Collection<Policy> policiesReceived = new ArrayList<>();
-
- @Override
- public void forward(final Collection<Policy> policies) throws PolicyForwardingException {
- numberOfPoliciesReceived += policies.size();
- policiesReceived.addAll(policies);
- }
-
- public int getNumberOfPoliciesReceived() {
- return numberOfPoliciesReceived;
- }
-
- public boolean receivedPolicy(final Policy policy) {
- return policiesReceived.contains(policy);
- }
+ class DummyPolicy2 implements Policy {
}
- /**
- * Only needed until code is added for instantiating plugins from paramater file
- *
- * @throws PolicyForwardingException
- * @throws PolicyDecodingException
- */
private void setUpPlugins(final AbstractReceptionHandler receptionHandler,
final Collection<PolicyDecoder<PolicyInput, Policy>> decoders, final Collection<PolicyForwarder> forwarders)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException,
PolicyDecodingException, PolicyForwardingException {
- final PluginHandler pluginHandler = new PluginHandler("");
+ final PluginHandlerParameters pluginParameters = getPluginHandlerParameters();
+ pluginParameters.setName(DISTRIBUTION_GROUP);
+ ParameterService.register(pluginParameters);
+ final PluginHandler pluginHandler = new PluginHandler(pluginParameters.getName());
final Field decodersField = pluginHandler.getClass().getDeclaredField("policyDecoders");
decodersField.setAccessible(true);
@@ -176,6 +146,31 @@ public class AbstractReceptionHandlerTest {
final Field pluginHandlerField = AbstractReceptionHandler.class.getDeclaredField("pluginHandler");
pluginHandlerField.setAccessible(true);
pluginHandlerField.set(receptionHandler, pluginHandler);
+ ParameterService.deregister(pluginParameters.getName());
+ }
+
+ private Map<String, PolicyDecoderParameters> getPolicyDecoders() {
+ final Map<String, PolicyDecoderParameters> policyDecoders = new HashMap<String, PolicyDecoderParameters>();
+ final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(DECODER_TYPE, DECODER_CLASS_NAME);
+ policyDecoders.put(DECODER_KEY, pDParameters);
+ return policyDecoders;
+ }
+
+ private Map<String, PolicyForwarderParameters> getPolicyForwarders() {
+ final Map<String, PolicyForwarderParameters> policyForwarders =
+ new HashMap<String, PolicyForwarderParameters>();
+ final PolicyForwarderParameters pFParameters =
+ new PolicyForwarderParameters(FORWARDER_TYPE, FORWARDER_CLASS_NAME);
+ policyForwarders.put(FORWARDER_KEY, pFParameters);
+ return policyForwarders;
+ }
+
+ private PluginHandlerParameters getPluginHandlerParameters() {
+ final Map<String, PolicyDecoderParameters> policyDecoders = getPolicyDecoders();
+ final Map<String, PolicyForwarderParameters> policyForwarders = getPolicyForwarders();
+ final PluginHandlerParameters pluginHandlerParameters =
+ new PluginHandlerParameters(policyDecoders, policyForwarders);
+ return pluginHandlerParameters;
}
}
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyDecoder.java b/reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyDecoder.java
new file mode 100644
index 00000000..2de1737e
--- /dev/null
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyDecoder.java
@@ -0,0 +1,59 @@
+/*-
+ * ============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.reception.handling;
+
+import java.util.Collection;
+
+import org.onap.policy.distribution.model.Policy;
+import org.onap.policy.distribution.model.PolicyInput;
+import org.onap.policy.distribution.reception.decoding.PolicyDecoder;
+import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
+
+/**
+ * Class to create a dummy decoder for test cases in AbstractReceptionHandlerTest.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class DummyDecoder implements PolicyDecoder<PolicyInput, Policy> {
+
+ private boolean canHandleValue;
+ private Collection<Policy> policesToReturn;
+
+ public DummyDecoder() {
+ this.canHandleValue = false;
+ this.policesToReturn = null;
+ }
+
+ public DummyDecoder(final boolean canHandleValue, final Collection<Policy> policesToReturn) {
+ this.canHandleValue = canHandleValue;
+ this.policesToReturn = policesToReturn;
+ }
+
+ @Override
+ public boolean canHandle(final PolicyInput policyInput) {
+ return canHandleValue;
+ }
+
+ @Override
+ public Collection<Policy> decode(final PolicyInput input) throws PolicyDecodingException {
+ return policesToReturn;
+ }
+}
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyPolicyForwarder.java b/reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyPolicyForwarder.java
new file mode 100644
index 00000000..acee4697
--- /dev/null
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyPolicyForwarder.java
@@ -0,0 +1,52 @@
+/*-
+ * ============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.reception.handling;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.onap.policy.distribution.forwarding.PolicyForwarder;
+import org.onap.policy.distribution.forwarding.PolicyForwardingException;
+import org.onap.policy.distribution.model.Policy;
+
+/**
+ * Class to create a dummy forwarder for test cases in AbstractReceptionHandlerTest.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class DummyPolicyForwarder implements PolicyForwarder {
+ private int numberOfPoliciesReceived = 0;
+ private Collection<Policy> policiesReceived = new ArrayList<>();
+
+ @Override
+ public void forward(final Collection<Policy> policies) throws PolicyForwardingException {
+ numberOfPoliciesReceived += policies.size();
+ policiesReceived.addAll(policies);
+ }
+
+ public int getNumberOfPoliciesReceived() {
+ return numberOfPoliciesReceived;
+ }
+
+ public boolean receivedPolicy(final Policy policy) {
+ return policiesReceived.contains(policy);
+ }
+}
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyReceptionHandler.java b/reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyReceptionHandler.java
new file mode 100644
index 00000000..43596ff2
--- /dev/null
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyReceptionHandler.java
@@ -0,0 +1,35 @@
+/*-
+ * ============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.reception.handling;
+
+/**
+ * Class to create a dummy reception handler for test cases in AbstractReceptionHandlerTest.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+class DummyReceptionHandler extends AbstractReceptionHandler {
+
+ @Override
+ protected void initializeReception(final String parameterGroupName) {}
+
+ @Override
+ public void destroy() {}
+}