diff options
author | ramverma <ram.krishna.verma@est.tech> | 2019-07-21 13:15:10 +0000 |
---|---|---|
committer | ramverma <ram.krishna.verma@est.tech> | 2019-07-21 13:15:10 +0000 |
commit | 38c95a9e7810bb6563667df1933f7ed22cda0db1 (patch) | |
tree | 48c9e4b817e4e3f3b01100cc097ca5b690c9fa4f /plugins/reception-plugins/src/test/java | |
parent | 538a204455ca708eaf20785972be3ac1c2a7ed3f (diff) |
Changing policy decoder to support Tosca
1) Updated PolicyDecoderFileInCsarToPolicy to parse ToscaPolicy &
TocsaPolicyType from the given csar.
2) Change the parameters
3) Tests cases updated/added.
Change-Id: Ic8d652ae8043d5d332f663a6862eb08e282591cf
Issue-ID: POLICY-1889
Signed-off-by: ramverma <ram.krishna.verma@est.tech>
Diffstat (limited to 'plugins/reception-plugins/src/test/java')
2 files changed, 37 insertions, 19 deletions
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroupTest.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroupTest.java index 0ea08905..2dd09985 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroupTest.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroupTest.java @@ -24,7 +24,6 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; import org.onap.policy.common.parameters.ValidationStatus; -import org.onap.policy.distribution.reception.decoding.policy.file.PolicyDecoderFileInCsarToPolicyParameterGroup; /** * Class to perform unit test of {@link PolicyDecoderFileInCsarToPolicyParameterGroup}. @@ -36,30 +35,30 @@ public class PolicyDecoderFileInCsarToPolicyParameterGroupTest { @Test public void testConstructorAndGetters() { final PolicyDecoderFileInCsarToPolicyParameterGroup configurationParameters = - new PolicyDecoderFileInCsarToPolicyParameterGroup("SamplePolicy", "APEX"); + new PolicyDecoderFileInCsarToPolicyParameterGroup("SamplePolicy", "SamplePolicyType"); configurationParameters.setName("myConfiguration"); assertEquals("myConfiguration", configurationParameters.getName()); assertEquals("SamplePolicy", configurationParameters.getPolicyFileName()); - assertEquals("APEX", configurationParameters.getPolicyType()); + assertEquals("SamplePolicyType", configurationParameters.getPolicyTypeFileName()); assertEquals(ValidationStatus.CLEAN, configurationParameters.validate().getStatus()); } @Test public void testInvalidPolicyFileName() { final PolicyDecoderFileInCsarToPolicyParameterGroup configurationParameters = - new PolicyDecoderFileInCsarToPolicyParameterGroup("", "APEX"); + new PolicyDecoderFileInCsarToPolicyParameterGroup("", "SamplePolicyType"); configurationParameters.setName("myConfiguration"); assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus()); } @Test - public void testInvalidPolicyType() { + public void testEmptyPolicyType() { final PolicyDecoderFileInCsarToPolicyParameterGroup configurationParameters = new PolicyDecoderFileInCsarToPolicyParameterGroup("SamplePolicy", ""); configurationParameters.setName("myConfiguration"); - assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus()); + assertEquals(ValidationStatus.CLEAN, configurationParameters.validate().getStatus()); } } diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java index f3f0217b..2d0ba3ba 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java @@ -34,8 +34,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.runners.MockitoJUnitRunner; import org.onap.policy.common.parameters.ParameterService; +import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.distribution.model.Csar; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; /** * Class to perform unit test of {@link PolicyDecoderFileInCsarToPolicy}. @@ -45,8 +46,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; @RunWith(MockitoJUnitRunner.class) public class PolicyDecoderFileInCsarToPolicyTest { - private static final String POLICY_FILE_NAME = "SamplePolicyModelJAVASCRIPT"; - private static final String POLICY_TYPE = "APEX"; + private static final String POLICY_FILE_NAME = "apex_ddf_policy"; + private static final String POLICY_TYPE_FILE_NAME = "apex_ddf_policy_type"; private static final String GROUP_NAME = "apexPdpDecoderConfiguration"; /** @@ -55,7 +56,7 @@ public class PolicyDecoderFileInCsarToPolicyTest { @BeforeClass public static void setUp() { final PolicyDecoderFileInCsarToPolicyParameterGroup configurationParameters = - new PolicyDecoderFileInCsarToPolicyParameterGroup(POLICY_FILE_NAME, POLICY_TYPE); + new PolicyDecoderFileInCsarToPolicyParameterGroup(POLICY_FILE_NAME, POLICY_TYPE_FILE_NAME); configurationParameters.setName(GROUP_NAME); ParameterService.register(configurationParameters); } @@ -74,23 +75,20 @@ public class PolicyDecoderFileInCsarToPolicyTest { final PolicyDecoderFileInCsarToPolicy decoder = new PolicyDecoderFileInCsarToPolicy(); decoder.configure(GROUP_NAME); - final File file = new File("src/test/resources/sampleTestService.csar"); + final File file = new File("src/test/resources/service-Sampleservice.csar"); final Csar csar = new Csar(file.getAbsolutePath()); try { - decoder.canHandle(csar); - final Collection<ToscaPolicy> policyHolders = decoder.decode(csar); - for (final ToscaPolicy policy : policyHolders) { - assertEquals(POLICY_FILE_NAME, policy.getName()); - assertEquals(POLICY_TYPE, policy.getType()); - } + assertTrue(decoder.canHandle(csar)); + final Collection<ToscaEntity> policyHolders = decoder.decode(csar); + assertEquals(2, policyHolders.size()); } catch (final Exception exp) { fail("Test must not throw an exception"); } } @Test - public void testDecodePolicyError() throws IOException { + public void testDecodePolicyZipError() { final PolicyDecoderFileInCsarToPolicy decoder = new PolicyDecoderFileInCsarToPolicy(); decoder.configure(GROUP_NAME); @@ -99,10 +97,31 @@ public class PolicyDecoderFileInCsarToPolicyTest { final Csar csar = new Csar(file.getAbsolutePath()); try { - decoder.canHandle(csar); + assertTrue(decoder.canHandle(csar)); decoder.decode(csar); fail("Test must throw an exception"); } catch (final Exception exp) { + assertTrue(exp.getCause() instanceof IOException); + assertTrue(exp.getMessage().contains("Failed decoding the policy")); + } + } + + + @Test + public void testDecodePolicyCoderError() { + + final PolicyDecoderFileInCsarToPolicy decoder = new PolicyDecoderFileInCsarToPolicy(); + decoder.configure(GROUP_NAME); + + final File file = new File("src/test/resources/service-Sampleservice-test.csar"); + final Csar csar = new Csar(file.getAbsolutePath()); + + try { + assertTrue(decoder.canHandle(csar)); + decoder.decode(csar); + fail("Test must throw an exception"); + } catch (final Exception exp) { + assertTrue(exp.getCause() instanceof CoderException); assertTrue(exp.getMessage().contains("Failed decoding the policy")); } } |