diff options
author | ramverma <ram.krishna.verma@est.tech> | 2019-07-17 11:03:26 +0000 |
---|---|---|
committer | ramverma <ram.krishna.verma@est.tech> | 2019-07-17 11:03:26 +0000 |
commit | cf748512392e5d3257de629dc57fb353dc073c92 (patch) | |
tree | 8e81a773d1f9556669b344d5f31dd139999ef2f6 /reception/src | |
parent | 5f032e0363703239f30dff29914dc41dd3abca48 (diff) |
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 <ram.krishna.verma@est.tech>
Diffstat (limited to 'reception/src')
6 files changed, 39 insertions, 48 deletions
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 <T> the type of policy that will be created * @param <S> the type of input to be decoded */ -public interface PolicyDecoder<S extends PolicyInput, T extends Policy> { +public interface PolicyDecoder<S extends PolicyInput, T extends ToscaEntity> { /** * 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<Policy> policies = new ArrayList<>(); - for (final PolicyDecoder<PolicyInput, Policy> policyDecoder : getRelevantPolicyDecoders(policyInput)) { + final Collection<ToscaEntity> policies = new ArrayList<>(); + for (final PolicyDecoder<PolicyInput, ToscaEntity> policyDecoder : getRelevantPolicyDecoders(policyInput)) { policies.addAll(policyDecoder.decode(policyInput)); } @@ -90,10 +90,10 @@ public abstract class AbstractReceptionHandler implements ReceptionHandler { } } - private Collection<PolicyDecoder<PolicyInput, Policy>> getRelevantPolicyDecoders(final PolicyInput policyInput) + private Collection<PolicyDecoder<PolicyInput, ToscaEntity>> getRelevantPolicyDecoders(final PolicyInput policyInput) throws PolicyDecodingException { - final Collection<PolicyDecoder<PolicyInput, Policy>> relevantPolicyDecoders = new ArrayList<>(); - for (final PolicyDecoder<PolicyInput, Policy> policyDecoder : pluginHandler.getPolicyDecoders()) { + final Collection<PolicyDecoder<PolicyInput, ToscaEntity>> relevantPolicyDecoders = new ArrayList<>(); + for (final PolicyDecoder<PolicyInput, ToscaEntity> 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<PolicyDecoder<PolicyInput, Policy>> policyDecoders; + private Collection<PolicyDecoder<PolicyInput, ToscaEntity>> policyDecoders; private Collection<PolicyForwarder> policyForwarders; /** @@ -64,7 +64,7 @@ public class PluginHandler { * * @return the policy decoders */ - public Collection<PolicyDecoder<PolicyInput, Policy>> getPolicyDecoders() { + public Collection<PolicyDecoder<PolicyInput, ToscaEntity>> getPolicyDecoders() { return policyDecoders; } @@ -89,10 +89,10 @@ public class PluginHandler { policyDecoders = new ArrayList<>(); for (final PolicyDecoderParameters decoderParameters : policyDecoderParameters.values()) { try { - final Class<PolicyDecoder<PolicyInput, Policy>> policyDecoderClass = - (Class<PolicyDecoder<PolicyInput, Policy>>) Class + final Class<PolicyDecoder<PolicyInput, ToscaEntity>> policyDecoderClass = + (Class<PolicyDecoder<PolicyInput, ToscaEntity>>) Class .forName(decoderParameters.getDecoderClassName()); - final PolicyDecoder<PolicyInput, Policy> decoder = policyDecoderClass.newInstance(); + final PolicyDecoder<PolicyInput, ToscaEntity> 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<PolicyInput, Policy> policyDecoder1 = + final PolicyDecoder<PolicyInput, ToscaEntity> policyDecoder1 = new DummyDecoder(true, Collections.singletonList(generatedPolicy1)); - final PolicyDecoder<PolicyInput, Policy> policyDecoder2 = + final PolicyDecoder<PolicyInput, ToscaEntity> policyDecoder2 = new DummyDecoder(true, Collections.singletonList(generatedPolicy2)); - final Collection<PolicyDecoder<PolicyInput, Policy>> policyDecoders = new ArrayList<>(); + final Collection<PolicyDecoder<PolicyInput, ToscaEntity>> 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<PolicyInput, Policy> policyDecoder = new DummyDecoder(false, Collections.emptyList()); + final PolicyDecoder<PolicyInput, ToscaEntity> 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<PolicyDecoder<PolicyInput, Policy>> decoders, final Collection<PolicyForwarder> forwarders) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, - PluginInitializationException { + final Collection<PolicyDecoder<PolicyInput, ToscaEntity>> decoders, + final Collection<PolicyForwarder> 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<PolicyInput, Policy> { +public class DummyDecoder implements PolicyDecoder<PolicyInput, ToscaEntity> { private boolean canHandleValue; - private Collection<Policy> policesToReturn; + private Collection<ToscaEntity> policesToReturn; public DummyDecoder() { this.canHandleValue = false; this.policesToReturn = null; } - public DummyDecoder(final boolean canHandleValue, final Collection<Policy> policesToReturn) { + public DummyDecoder(final boolean canHandleValue, final Collection<ToscaEntity> policesToReturn) { this.canHandleValue = canHandleValue; this.policesToReturn = policesToReturn; } @@ -53,7 +53,7 @@ public class DummyDecoder implements PolicyDecoder<PolicyInput, Policy> { } @Override - public Collection<Policy> decode(final PolicyInput input) throws PolicyDecodingException { + public Collection<ToscaEntity> 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<Policy> policiesReceived = new ArrayList<>(); + private Collection<ToscaEntity> policiesReceived = new ArrayList<>(); @Override - public void forward(final Collection<Policy> policies) throws PolicyForwardingException { + public void forward(final Collection<ToscaEntity> 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) {} } |