aboutsummaryrefslogtreecommitdiffstats
path: root/reception/src/test
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/src/test
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/src/test')
-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
5 files changed, 208 insertions, 66 deletions
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() {}
+}