From cf748512392e5d3257de629dc57fb353dc073c92 Mon Sep 17 00:00:00 2001 From: ramverma Date: Wed, 17 Jul 2019 11:03:26 +0000 Subject: Changing policy/distribution to use policy/models 1) Changed policy distribution framework to use entities from policy/models 2) Changed all the test cases. 3) Commented few test cases which will be fixed along with code fixes. 4) Will be removing the old policy entities once all the pieces are ready. Change-Id: I1fd7b975b2e072c0b24e429903c9ca4796173929 Issue-ID: POLICY-1888 Signed-off-by: ramverma --- .../reception/decoding/PolicyDecoder.java | 4 +-- .../handling/AbstractReceptionHandler.java | 12 +++---- .../reception/handling/PluginHandler.java | 12 +++---- .../handling/AbstractReceptionHandlerTest.java | 38 ++++++++-------------- .../reception/handling/DummyDecoder.java | 10 +++--- .../reception/handling/DummyPolicyForwarder.java | 11 ++++--- 6 files changed, 39 insertions(+), 48 deletions(-) (limited to 'reception/src') diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PolicyDecoder.java b/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PolicyDecoder.java index 9cd660a9..04150205 100644 --- a/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PolicyDecoder.java +++ b/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PolicyDecoder.java @@ -22,8 +22,8 @@ package org.onap.policy.distribution.reception.decoding; import java.util.Collection; -import org.onap.policy.distribution.model.Policy; import org.onap.policy.distribution.model.PolicyInput; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; /** * Decodes polices from a given input. @@ -31,7 +31,7 @@ import org.onap.policy.distribution.model.PolicyInput; * @param the type of policy that will be created * @param the type of input to be decoded */ -public interface PolicyDecoder { +public interface PolicyDecoder { /** * Configure the policy decoder. This method will be invoked immediately after instantiation in order for the policy 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 5b2d1671..2ea18704 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 @@ -27,12 +27,12 @@ import java.util.Collection; 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.model.Policy; import org.onap.policy.distribution.model.PolicyInput; import org.onap.policy.distribution.reception.decoding.PluginInitializationException; import org.onap.policy.distribution.reception.decoding.PolicyDecoder; import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -76,8 +76,8 @@ public abstract class AbstractReceptionHandler implements ReceptionHandler { */ protected void inputReceived(final PolicyInput policyInput) throws PolicyDecodingException { - final Collection policies = new ArrayList<>(); - for (final PolicyDecoder policyDecoder : getRelevantPolicyDecoders(policyInput)) { + final Collection policies = new ArrayList<>(); + for (final PolicyDecoder policyDecoder : getRelevantPolicyDecoders(policyInput)) { policies.addAll(policyDecoder.decode(policyInput)); } @@ -90,10 +90,10 @@ public abstract class AbstractReceptionHandler implements ReceptionHandler { } } - private Collection> getRelevantPolicyDecoders(final PolicyInput policyInput) + private Collection> getRelevantPolicyDecoders(final PolicyInput policyInput) throws PolicyDecodingException { - final Collection> relevantPolicyDecoders = new ArrayList<>(); - for (final PolicyDecoder policyDecoder : pluginHandler.getPolicyDecoders()) { + final Collection> relevantPolicyDecoders = new ArrayList<>(); + for (final PolicyDecoder policyDecoder : pluginHandler.getPolicyDecoders()) { if (policyDecoder.canHandle(policyInput)) { relevantPolicyDecoders.add(policyDecoder); } 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 afa703ab..f837e520 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 @@ -28,12 +28,12 @@ import java.util.Map; import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.distribution.forwarding.PolicyForwarder; 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.PluginInitializationException; import org.onap.policy.distribution.reception.decoding.PolicyDecoder; import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters; import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,7 +44,7 @@ public class PluginHandler { private static final Logger LOGGER = LoggerFactory.getLogger(PluginHandler.class); - private Collection> policyDecoders; + private Collection> policyDecoders; private Collection policyForwarders; /** @@ -64,7 +64,7 @@ public class PluginHandler { * * @return the policy decoders */ - public Collection> getPolicyDecoders() { + public Collection> getPolicyDecoders() { return policyDecoders; } @@ -89,10 +89,10 @@ public class PluginHandler { policyDecoders = new ArrayList<>(); for (final PolicyDecoderParameters decoderParameters : policyDecoderParameters.values()) { try { - final Class> policyDecoderClass = - (Class>) Class + final Class> policyDecoderClass = + (Class>) Class .forName(decoderParameters.getDecoderClassName()); - final PolicyDecoder decoder = policyDecoderClass.newInstance(); + final PolicyDecoder decoder = policyDecoderClass.newInstance(); decoder.configure(decoderParameters.getDecoderConfigurationName()); policyDecoders.add(decoder); } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException exp) { 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 8dc84621..f76f599c 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 @@ -34,13 +34,13 @@ import org.junit.Test; import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.distribution.forwarding.PolicyForwarder; 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.PluginInitializationException; 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; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; /** * Class to perform unit test of AbstractReceptionHandler. @@ -65,15 +65,15 @@ public class AbstractReceptionHandlerTest { IllegalArgumentException, IllegalAccessException, PluginInitializationException { final AbstractReceptionHandler handler = new DummyReceptionHandler(); - final Policy generatedPolicy1 = new DummyPolicy1(); - final Policy generatedPolicy2 = new DummyPolicy2(); + final ToscaEntity generatedPolicy1 = new DummyPolicy1(); + final ToscaEntity generatedPolicy2 = new DummyPolicy2(); - final PolicyDecoder policyDecoder1 = + final PolicyDecoder policyDecoder1 = new DummyDecoder(true, Collections.singletonList(generatedPolicy1)); - final PolicyDecoder policyDecoder2 = + final PolicyDecoder policyDecoder2 = new DummyDecoder(true, Collections.singletonList(generatedPolicy2)); - final Collection> policyDecoders = new ArrayList<>(); + final Collection> policyDecoders = new ArrayList<>(); policyDecoders.add(policyDecoder1); policyDecoders.add(policyDecoder2); @@ -101,7 +101,7 @@ public class AbstractReceptionHandlerTest { SecurityException, IllegalArgumentException, IllegalAccessException, PluginInitializationException { final AbstractReceptionHandler handler = new DummyReceptionHandler(); - final PolicyDecoder policyDecoder = new DummyDecoder(false, Collections.emptyList()); + final PolicyDecoder policyDecoder = new DummyDecoder(false, Collections.emptyList()); final DummyPolicyForwarder policyForwarder = new DummyPolicyForwarder(); setUpPlugins(handler, Collections.singleton(policyDecoder), Collections.singleton(policyForwarder)); @@ -122,36 +122,26 @@ public class AbstractReceptionHandlerTest { class DummyPolicyInput implements PolicyInput { } - class DummyPolicy1 implements Policy { + class DummyPolicy1 extends ToscaEntity { @Override - public String getPolicyName() { - return null; - } - - @Override - public String getPolicyType() { + public String getName() { return null; } } - class DummyPolicy2 implements Policy { + class DummyPolicy2 extends ToscaEntity { @Override - public String getPolicyName() { - return null; - } - - @Override - public String getPolicyType() { + public String getName() { return null; } } private void setUpPlugins(final AbstractReceptionHandler receptionHandler, - final Collection> decoders, final Collection forwarders) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, - PluginInitializationException { + final Collection> decoders, + final Collection forwarders) throws NoSuchFieldException, SecurityException, + IllegalArgumentException, IllegalAccessException, PluginInitializationException { final PluginHandlerParameters pluginParameters = getPluginHandlerParameters(); pluginParameters.setName(DISTRIBUTION_GROUP); ParameterService.register(pluginParameters); 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 index 74792b1e..aa61c1c2 100644 --- 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 @@ -22,27 +22,27 @@ 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; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; /** * 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 { +public class DummyDecoder implements PolicyDecoder { private boolean canHandleValue; - private Collection policesToReturn; + private Collection policesToReturn; public DummyDecoder() { this.canHandleValue = false; this.policesToReturn = null; } - public DummyDecoder(final boolean canHandleValue, final Collection policesToReturn) { + public DummyDecoder(final boolean canHandleValue, final Collection policesToReturn) { this.canHandleValue = canHandleValue; this.policesToReturn = policesToReturn; } @@ -53,7 +53,7 @@ public class DummyDecoder implements PolicyDecoder { } @Override - public Collection decode(final PolicyInput input) throws PolicyDecodingException { + public Collection 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 index a665c546..588adc8f 100644 --- 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 @@ -22,9 +22,10 @@ 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; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; /** * Class to create a dummy forwarder for test cases in AbstractReceptionHandlerTest. @@ -33,10 +34,10 @@ import org.onap.policy.distribution.model.Policy; */ public class DummyPolicyForwarder implements PolicyForwarder { private int numberOfPoliciesReceived = 0; - private Collection policiesReceived = new ArrayList<>(); + private Collection policiesReceived = new ArrayList<>(); @Override - public void forward(final Collection policies) throws PolicyForwardingException { + public void forward(final Collection policies) throws PolicyForwardingException { numberOfPoliciesReceived += policies.size(); policiesReceived.addAll(policies); } @@ -45,10 +46,10 @@ public class DummyPolicyForwarder implements PolicyForwarder { return numberOfPoliciesReceived; } - public boolean receivedPolicy(final Policy policy) { + public boolean receivedPolicy(final ToscaEntity policy) { return policiesReceived.contains(policy); } @Override - public void configure(String parameterGroupName) {} + public void configure(final String parameterGroupName) {} } -- cgit 1.2.3-korg