From e80efa0dbe903e976f5b2799144658c7ba02e534 Mon Sep 17 00:00:00 2001 From: ramverma Date: Thu, 13 Sep 2018 16:31:35 +0100 Subject: Adding policy decoder to extract file from csar * Adding decoder configuration parameters infrastructure to support plugin based architecture. Adding a new policy decoder after this will be just creating a new decoder class and its corresponding parameter class. * Adding a new decoder which extracts policy file from given csar. It is written in a generic way to extract file for any pdp like apex, drools. * Adding configuration parameters for the new decoder. The policy file name and policy type is passed as parameter to the decoder. * Fixing few broken package declaration in pdpx decoder tests. * Adding test cases for all code changes. Change-Id: I95e68cebce0f9747ca63b090f9b9116ce8836939 Issue-ID: POLICY-1101 Signed-off-by: ramverma --- .../ApexPdpPolicyForwarderParameterGroupTest.java | 5 ++++ .../apex/pdp/ApexPdpPolicyForwarderTest.java | 30 ++++++++++++---------- .../xacml/pdp/testclasses/DummyDecoder.java | 3 +++ 3 files changed, 24 insertions(+), 14 deletions(-) (limited to 'plugins/forwarding-plugins/src/test') diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroupTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroupTest.java index ca0efb5c..7feef452 100644 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroupTest.java +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroupTest.java @@ -27,6 +27,11 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; import org.onap.policy.common.parameters.ValidationStatus; +/** + * Class to perform unit test of {@link ApexPdpPolicyForwarderParameterGroup}. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ public class ApexPdpPolicyForwarderParameterGroupTest { @Test diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderTest.java index abf5b508..a4d1b9fd 100644 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderTest.java +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderTest.java @@ -22,11 +22,11 @@ package org.onap.policy.distribution.forwarding.apex.pdp; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.Field; @@ -45,9 +45,14 @@ import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.common.parameters.ParameterGroup; import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.distribution.forwarding.PolicyForwardingException; -import org.onap.policy.distribution.model.ApexPdpPolicy; import org.onap.policy.distribution.model.Policy; +import org.onap.policy.distribution.model.PolicyAsString; +/** + * Class to perform unit test of {@link ApexPdpPolicyForwarder}. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ @RunWith(MockitoJUnitRunner.class) public class ApexPdpPolicyForwarderTest { @@ -84,7 +89,6 @@ public class ApexPdpPolicyForwarderTest { public void testForwardPolicy() throws ApexException, FileNotFoundException, IOException, PolicyForwardingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - final FileInputStream fis = new FileInputStream(File.createTempFile("policy1", null)); final Collection policies = new ArrayList<>(); final ApexPdpPolicyForwarder forwarder = new ApexPdpPolicyForwarder(); forwarder.configure(GROUP_NAME); @@ -93,13 +97,14 @@ public class ApexPdpPolicyForwarderTest { forwarderField.setAccessible(true); forwarderField.set(forwarder, engineServiceFacade); - final ApexPdpPolicy policy = new ApexPdpPolicy("policy", fis); + final PolicyAsString policy = new PolicyAsString("policy", "APEX", "Sample Policy of apex"); policies.add(policy); try { forwarder.forward(policies); verify(engineServiceFacade, times(1)).init(); - verify(engineServiceFacade, times(1)).deployModel("policy", fis, IGNORE_CONFLICTS, FORCE_UPDATE); + verify(engineServiceFacade, times(1)).deployModel(eq("policy"), anyObject(), eq(IGNORE_CONFLICTS), + eq(FORCE_UPDATE)); } catch (final Exception exp) { fail("Test must not throw an exception"); } @@ -110,19 +115,18 @@ public class ApexPdpPolicyForwarderTest { throws ApexException, FileNotFoundException, IOException, PolicyForwardingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - final FileInputStream fis = new FileInputStream(File.createTempFile("policy1", null)); final Collection policies = new ArrayList<>(); final ApexPdpPolicyForwarder forwarder = new ApexPdpPolicyForwarder(); forwarder.configure(GROUP_NAME); - Mockito.doThrow(new ApexException("Failed")).when(engineServiceFacade).deployModel("policy1", fis, - IGNORE_CONFLICTS, FORCE_UPDATE); + Mockito.doThrow(new ApexException("Failed")).when(engineServiceFacade).deployModel(eq("policy1"), anyObject(), + eq(IGNORE_CONFLICTS), eq(FORCE_UPDATE)); final Field decodersField = forwarder.getClass().getDeclaredField("engineServiceFacade"); decodersField.setAccessible(true); decodersField.set(forwarder, engineServiceFacade); - final ApexPdpPolicy policy1 = new ApexPdpPolicy("policy1", fis); + final PolicyAsString policy1 = new PolicyAsString("policy1", "APEX", "Sample Policy of apex"); policies.add(policy1); try { @@ -147,12 +151,10 @@ public class ApexPdpPolicyForwarderTest { forwarderField.setAccessible(true); forwarderField.set(forwarder, engineServiceFacade); - final ApexPdpPolicy policy1 = - new ApexPdpPolicy("policy1", new FileInputStream(File.createTempFile("policy1", null))); + final PolicyAsString policy1 = new PolicyAsString("policy1", "APEX", "Sample Policy of apex"); policies.add(policy1); - final ApexPdpPolicy policy2 = - new ApexPdpPolicy("policy2", new FileInputStream(File.createTempFile("policy2", null))); + final PolicyAsString policy2 = new PolicyAsString("policy2", "APEX", "Sample Policy of apex"); policies.add(policy2); try { diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/DummyDecoder.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/DummyDecoder.java index e09357cf..c90917b8 100644 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/DummyDecoder.java +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/DummyDecoder.java @@ -56,4 +56,7 @@ public class DummyDecoder implements PolicyDecoder { public Collection decode(final PolicyInput input) throws PolicyDecodingException { return policesToReturn; } + + @Override + public void configure(final String parameterGroupName) {} } -- cgit 1.2.3-korg