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 --- .../apex/pdp/ApexPdpPolicyForwarder.java | 18 ++-- .../ApexPdpPolicyForwarderParameterGroupTest.java | 5 + .../apex/pdp/ApexPdpPolicyForwarderTest.java | 30 +++--- .../xacml/pdp/testclasses/DummyDecoder.java | 3 + .../decoding/pdpx/PolicyDecoderCsarPdpx.java | 55 +++++------ .../decoding/pdpx/PolicyDecoderToscaPdpx.java | 14 ++- .../file/PolicyDecoderFileInCsarToPolicy.java | 94 ++++++++++++++++++ ...icyDecoderFileInCsarToPolicyParameterGroup.java | 70 +++++++++++++ .../reception/decoding/pdpx/TestAttribute.java | 49 +++++++++ .../reception/decoding/pdpx/TestContent.java | 64 ++++++++++++ .../reception/decoding/pdpx/TestDirective.java | 52 ++++++++++ .../reception/decoding/pdpx/TestFlavorFeature.java | 63 ++++++++++++ .../decoding/pdpx/TestFlavorProperty.java | 70 +++++++++++++ .../decoding/pdpx/TestHpaFeatureAttribute.java | 56 +++++++++++ .../decoding/pdpx/TestPolicyDecoderCsarPdpx.java | 66 +++++++++++++ ...ecoderFileInCsarToPolicyParameterGroupTest.java | 65 ++++++++++++ .../file/PolicyDecoderFileInCsarToPolicyTest.java | 109 +++++++++++++++++++++ .../handling/decoding/pdpx/TestAttribute.java | 49 --------- .../handling/decoding/pdpx/TestContent.java | 64 ------------ .../handling/decoding/pdpx/TestDirective.java | 52 ---------- .../handling/decoding/pdpx/TestFlavorFeature.java | 63 ------------ .../handling/decoding/pdpx/TestFlavorProperty.java | 70 ------------- .../decoding/pdpx/TestHpaFeatureAttribute.java | 56 ----------- .../decoding/pdpx/TestPolicyDecoderCsarPdpx.java | 66 ------------- .../reception/handling/sdc/DummyDecoder.java | 3 + .../handling/sdc/TestSdcReceptionHandler.java | 2 +- .../src/test/resources/sampleTestService.csar | Bin 0 -> 198643 bytes 27 files changed, 832 insertions(+), 476 deletions(-) create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java create mode 100644 plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroup.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestAttribute.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestContent.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestDirective.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorFeature.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorProperty.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestHpaFeatureAttribute.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroupTest.java create mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestAttribute.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestContent.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestDirective.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorFeature.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorProperty.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestHpaFeatureAttribute.java delete mode 100644 plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestPolicyDecoderCsarPdpx.java create mode 100644 plugins/reception-plugins/src/test/resources/sampleTestService.csar (limited to 'plugins') diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarder.java index 1a603f04..f71c6aee 100644 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarder.java +++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarder.java @@ -20,8 +20,11 @@ package org.onap.policy.distribution.forwarding.apex.pdp; +import java.io.IOException; +import java.io.InputStream; import java.util.Collection; +import org.apache.commons.io.IOUtils; import org.onap.policy.apex.core.deployment.EngineServiceFacade; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.common.logging.flexlogger.FlexLogger; @@ -30,8 +33,8 @@ 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.xacml.pdp.XacmlPdpPolicyForwarder; -import org.onap.policy.distribution.model.ApexPdpPolicy; import org.onap.policy.distribution.model.Policy; +import org.onap.policy.distribution.model.PolicyAsString; /** * This class provides an implementation of {@link PolicyForwarder} interface for forwarding the given policies to @@ -42,6 +45,7 @@ import org.onap.policy.distribution.model.Policy; public class ApexPdpPolicyForwarder implements PolicyForwarder { private static final Logger LOGGER = FlexLogger.getLogger(XacmlPdpPolicyForwarder.class); + private static final String POLICY_TYPE = "APEX"; private ApexPdpPolicyForwarderParameterGroup apexForwarderParameters; private EngineServiceFacade engineServiceFacade; @@ -69,8 +73,9 @@ public class ApexPdpPolicyForwarder implements PolicyForwarder { } else { final Policy policy = (Policy) policies.toArray()[0]; - if (policy.getClass().isAssignableFrom(ApexPdpPolicy.class)) { - forwardPolicy((ApexPdpPolicy) policy); + if (policy.getClass().isAssignableFrom(PolicyAsString.class) + && policy.getPolicyType().equalsIgnoreCase(POLICY_TYPE)) { + forwardPolicy((PolicyAsString) policy); } else { final String message = "Ignoring the policy as it is not an apex-pdp policy"; LOGGER.debug(message); @@ -85,16 +90,17 @@ public class ApexPdpPolicyForwarder implements PolicyForwarder { * @param apexPolicy the apex policy * @throws PolicyForwardingException if any exception occurs while forwarding policy */ - private void forwardPolicy(final ApexPdpPolicy apexPolicy) throws PolicyForwardingException { + private void forwardPolicy(final PolicyAsString apexPolicy) throws PolicyForwardingException { try { engineServiceFacade.init(); - engineServiceFacade.deployModel(apexPolicy.getPolicyName(), apexPolicy.getPolicyInputStream(), + final InputStream policyInputStream = IOUtils.toInputStream(apexPolicy.getPolicy(), "UTF-8"); + engineServiceFacade.deployModel(apexPolicy.getPolicyName(), policyInputStream, apexForwarderParameters.isIgnoreConflicts(), apexForwarderParameters.isForceUpdate()); LOGGER.debug("Sucessfully forwarded the policy to apex-pdp egine at " + apexForwarderParameters.getHostname() + ":" + apexForwarderParameters.getPort()); - } catch (final ApexException exp) { + } catch (final ApexException | IOException exp) { final String message = "Error sending policy to apex-pdp engine at" + apexForwarderParameters.getHostname() + ":" + apexForwarderParameters.getPort(); LOGGER.error(message, exp); 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) {} } diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java index 0cd7bc16..6c4f285a 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpx.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========================================================= */ @@ -22,26 +22,18 @@ package org.onap.policy.distribution.reception.decoding.pdpx; import java.io.File; import java.util.ArrayList; -import java.util.List; - import java.util.Collection; -import java.util.Collections; - +import java.util.List; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; - -import org.onap.policy.distribution.model.PolicyInput; import org.onap.policy.distribution.model.Csar; +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.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.tosca.parser.impl.SdcCsarHelperImpl; import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; - import org.onap.sdc.toscaparser.api.NodeTemplate; -import org.onap.sdc.toscaparser.api.elements.Metadata; /** * Decodes PDP-X policies from a TOSCA file. @@ -51,16 +43,16 @@ public class PolicyDecoderCsarPdpx implements PolicyDecoder { private static final Logger LOGGER = FlexLogger.getLogger(PolicyDecoderCsarPdpx.class); @Override - public Collection decode(Csar csar) throws PolicyDecodingException { - // logic for generating the policies from the CSAR. - List lPdpxPolicy = new ArrayList<>(); - ISdcCsarHelper sdcCsarHelper = parseCsar(csar); - List lnodeVf = sdcCsarHelper.getServiceVfList(); + public Collection decode(final Csar csar) throws PolicyDecodingException { + // logic for generating the policies from the CSAR. + final List lPdpxPolicy = new ArrayList<>(); + final ISdcCsarHelper sdcCsarHelper = parseCsar(csar); + final List lnodeVf = sdcCsarHelper.getServiceVfList(); LOGGER.debug("the size of Vf = " + lnodeVf.size()); - ExtractFromNode extractFromNode = new ExtractFromNode(); + final ExtractFromNode extractFromNode = new ExtractFromNode(); extractFromNode.setSdcCsarHelper(sdcCsarHelper); - for ( NodeTemplate node : lnodeVf) { - PdpxPolicy ret = extractFromNode.extractInfo(node); + for (final NodeTemplate node : lnodeVf) { + final PdpxPolicy ret = extractFromNode.extractInfo(node); if (ret != null) { lPdpxPolicy.add(ret); } @@ -69,34 +61,37 @@ public class PolicyDecoderCsarPdpx implements PolicyDecoder { } @Override - public boolean canHandle(PolicyInput policyInput) { + public boolean canHandle(final PolicyInput policyInput) { return policyInput.getClass().isAssignableFrom(Csar.class); } - /** + /** * Parse the input Csar by SDC tosca tool. * * @param csar represents the service TOSCA Csar * @return the object to represents the content of input csar * @throws PolicyDecodingException if parse fails */ - public ISdcCsarHelper parseCsar(Csar csar) throws PolicyDecodingException { - ISdcCsarHelper sdcCsarHelper ; + public ISdcCsarHelper parseCsar(final Csar csar) throws PolicyDecodingException { + ISdcCsarHelper sdcCsarHelper; try { - SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();//Autoclosable + final SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();// Autoclosable LOGGER.debug("tosca File Path = " + csar.getCsarPath()); - File spoolFile = new File(csar.getCsarPath()); + final File spoolFile = new File(csar.getCsarPath()); sdcCsarHelper = factory.getSdcCsarHelper(spoolFile.getAbsolutePath()); - } catch (Exception e) { - LOGGER.error("Exception got in parseTosca",e); - throw new PolicyDecodingException ("Exception caught when passing the csar file to the parser ", e); + } catch (final Exception e) { + LOGGER.error("Exception got in parseTosca", e); + throw new PolicyDecodingException("Exception caught when passing the csar file to the parser ", e); } return sdcCsarHelper; } + @Override + public void configure(final String parameterGroupName) {} + } diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderToscaPdpx.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderToscaPdpx.java index fa993579..40b33359 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderToscaPdpx.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderToscaPdpx.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========================================================= */ @@ -22,6 +22,7 @@ package org.onap.policy.distribution.reception.decoding.pdpx; import java.util.Collection; import java.util.Collections; + import org.onap.policy.distribution.model.PolicyInput; import org.onap.policy.distribution.model.Tosca; import org.onap.policy.distribution.reception.decoding.PolicyDecoder; @@ -32,14 +33,17 @@ import org.onap.policy.distribution.reception.decoding.PolicyDecoder; public class PolicyDecoderToscaPdpx implements PolicyDecoder { @Override - public Collection decode(Tosca tosca) { + public Collection decode(final Tosca tosca) { // Add logic for generating the policies from the TOSCA return Collections.emptySet(); } @Override - public boolean canHandle(PolicyInput policyInput) { + public boolean canHandle(final PolicyInput policyInput) { return policyInput.getClass().isAssignableFrom(Tosca.class); } + @Override + public void configure(final String parameterGroupName) {} + } diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java new file mode 100644 index 00000000..9516ad70 --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java @@ -0,0 +1,94 @@ +/*- + * ============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.decoding.policy.file; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.apache.commons.io.IOUtils; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; +import org.onap.policy.common.parameters.ParameterService; +import org.onap.policy.distribution.model.Csar; +import org.onap.policy.distribution.model.PolicyAsString; +import org.onap.policy.distribution.model.PolicyInput; +import org.onap.policy.distribution.reception.decoding.PolicyDecoder; +import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; + +/** + * This class extracts policy files from a CSAR file. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public class PolicyDecoderFileInCsarToPolicy implements PolicyDecoder { + + private static final Logger LOGGER = FlexLogger.getLogger(PolicyDecoderFileInCsarToPolicy.class); + PolicyDecoderFileInCsarToPolicyParameterGroup decoderParameters; + + /** + * {@inheritDoc}. + */ + @Override + public void configure(final String parameterGroupName) { + decoderParameters = ParameterService.get(parameterGroupName); + } + + /** + * {@inheritDoc}. + */ + @Override + public boolean canHandle(final PolicyInput policyInput) { + return policyInput.getClass().isAssignableFrom(Csar.class); + } + + /** + * {@inheritDoc}. + */ + @Override + public Collection decode(final Csar csar) throws PolicyDecodingException { + final Collection policyList = new ArrayList<>(); + + try (ZipFile zipFile = new ZipFile(csar.getCsarPath())) { + final Enumeration entries = zipFile.entries(); + while (entries.hasMoreElements()) { + final ZipEntry entry = entries.nextElement(); + if (entry.getName().contains(decoderParameters.getPolicyFileName())) { + final StringWriter writer = new StringWriter(); + IOUtils.copy(zipFile.getInputStream(entry), writer, "UTF-8"); + final PolicyAsString poilcy = new PolicyAsString(decoderParameters.getPolicyFileName(), + decoderParameters.getPolicyType(), writer.toString()); + policyList.add(poilcy); + } + } + } catch (final IOException exp) { + final String message = "Failed decoding the policy"; + LOGGER.error(message, exp); + throw new PolicyDecodingException(message, exp); + } + + return policyList; + } +} diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroup.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroup.java new file mode 100644 index 00000000..958180db --- /dev/null +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroup.java @@ -0,0 +1,70 @@ +/*- + * ============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.decoding.policy.file; + +import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.ValidationStatus; +import org.onap.policy.common.utils.validation.ParameterValidationUtils; +import org.onap.policy.distribution.reception.parameters.PolicyDecoderConfigurationParameterGroup; + +/** + * Holds the parameters for the{@link PolicyDecoderFileInCsarToPolicy}. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public class PolicyDecoderFileInCsarToPolicyParameterGroup extends PolicyDecoderConfigurationParameterGroup { + + private String policyFileName; + private String policyType; + + /** + * Constructor for instantiating {@link PolicyDecoderFileInCsarToPolicyParameterGroup} class. + * + * @param policyFileName the policy file name + * @param policyType the policy type + */ + public PolicyDecoderFileInCsarToPolicyParameterGroup(final String policyFileName, final String policyType) { + this.policyFileName = policyFileName; + this.policyType = policyType; + } + + public String getPolicyFileName() { + return policyFileName; + } + + public String getPolicyType() { + return policyType; + } + + @Override + public GroupValidationResult validate() { + final GroupValidationResult validationResult = new GroupValidationResult(this); + if (!ParameterValidationUtils.validateStringParameter(policyFileName)) { + validationResult.setResult("policyFileName", ValidationStatus.INVALID, + "must be a non-blank string containing the policy file name"); + } + if (!ParameterValidationUtils.validateStringParameter(policyType)) { + validationResult.setResult("policyType", ValidationStatus.INVALID, + "must be a non-blank string containing the policy type"); + } + return validationResult; + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestAttribute.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestAttribute.java new file mode 100644 index 00000000..f11a7ecd --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestAttribute.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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.decoding.pdpx; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * Class to perform unit test for Attribute 0f {@link Attribute}. + * + */ +public class TestAttribute { + + @Test + public void testAttribute() { + final String attributeName = "dummyName"; + final String attributeValue = "dummyValue"; + + final Attribute attribute = new Attribute(); + attribute.setAttributeName(attributeName); + attribute.setAttributeValue(attributeValue); + + validateReport(attributeName,attributeValue,attribute); + } + + private void validateReport(final String name, final String value, final Attribute attribute) { + assertEquals(name, attribute.getAttributeName()); + assertEquals(value, attribute.getAttributeValue()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestContent.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestContent.java new file mode 100644 index 00000000..a329a3ee --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestContent.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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.decoding.pdpx; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * Class to perform unit test for Content 0f {@link Content}. + * + */ +public class TestContent { + + @Test + public void testContent() { + final String resources = "dummyresource"; + final String identity = "dummyidentity"; + final String policyType = "optimization"; + + final Content content = new Content(); + content.setResources(resources); + content.setIdentity(identity); + content.setPolicyType(policyType); + + validateReport(resources, identity, policyType,content); + } + + private void validateReport(final String resources, final String identity, final String policyType, + final Content content) { + assertEquals(resources, content.getResources()); + assertEquals(identity, content.getIdentity()); + assertEquals(policyType, content.getPolicyType()); + assertEquals(0, content.getPolicyScope().size()); + content.getPolicyScope().add("vFW"); + assertEquals(1, content.getPolicyScope().size()); + content.getPolicyScope().remove("vFW"); + assertEquals(0, content.getPolicyScope().size()); + assertEquals(0, content.getFlavorFeatures().size()); + FlavorFeature flavorFeature = new FlavorFeature(); + content.getFlavorFeatures().add(flavorFeature); + assertEquals(1, content.getFlavorFeatures().size()); + content.getFlavorFeatures().remove(flavorFeature); + assertEquals(0, content.getFlavorFeatures().size()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestDirective.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestDirective.java new file mode 100644 index 00000000..48d11d32 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestDirective.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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.decoding.pdpx; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * Class to perform unit test for Directive 0f {@link Directive}. + * + */ +public class TestDirective { + + @Test + public void testDirective() { + final String type = "dummytype"; + + final Directive directive = new Directive(); + directive.setType(type); + + validateReport(type,directive); + } + + private void validateReport(final String type, final Directive directive) { + assertEquals(type, directive.getType()); + assertEquals(0, directive.getAttributes().size()); + Attribute attribute = new Attribute(); + directive.getAttributes().add(attribute); + assertEquals(1, directive.getAttributes().size()); + directive.getAttributes().remove(attribute); + assertEquals(0, directive.getAttributes().size()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorFeature.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorFeature.java new file mode 100644 index 00000000..47b4e343 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorFeature.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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.decoding.pdpx; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * Class to perform unit test for FlavorFeature 0f {@link FlavorFeature}. + * + */ +public class TestFlavorFeature { + + @Test + public void testFlavorFeature() { + final String id = "dummyid"; + final String type = "dummytype"; + + final FlavorFeature flavorFeature = new FlavorFeature(); + flavorFeature.setId(id); + flavorFeature.setType(type); + + validateReport(id,type,flavorFeature); + } + + private void validateReport(final String id, final String type, final FlavorFeature flavorFeature) { + assertEquals(id, flavorFeature.getId()); + assertEquals(type, flavorFeature.getType()); + + assertEquals(0, flavorFeature.getDirectives().size()); + Directive directive = new Directive(); + flavorFeature.getDirectives().add(directive); + assertEquals(1, flavorFeature.getDirectives().size()); + flavorFeature.getDirectives().remove(directive); + assertEquals(0, flavorFeature.getDirectives().size()); + + assertEquals(0, flavorFeature.getFlavorProperties().size()); + FlavorProperty flavorProperty = new FlavorProperty(); + flavorFeature.getFlavorProperties().add(flavorProperty); + assertEquals(1, flavorFeature.getFlavorProperties().size()); + flavorFeature.getFlavorProperties().remove(flavorProperty); + assertEquals(0, flavorFeature.getFlavorProperties().size()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorProperty.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorProperty.java new file mode 100644 index 00000000..b5a535d7 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestFlavorProperty.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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.decoding.pdpx; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * Class to perform unit test for FlavorProperty 0f {@link FlavorProperty}. + * + */ +public class TestFlavorProperty { + + @Test + public void testFlavorProperty() { + final String hpaFeature = "dummyid"; + final String mandatory = "false"; + final String architecture = "generic"; + final String hpaVersion = "v1"; + + final FlavorProperty flavorProperty = new FlavorProperty(); + flavorProperty.setHpaFeature(hpaFeature); + flavorProperty.setMandatory(mandatory); + flavorProperty.setArchitecture(architecture); + flavorProperty.setHpaVersion(hpaVersion); + + validateReport(hpaFeature,mandatory,architecture,hpaVersion,flavorProperty); + } + + private void validateReport(final String hpaFeature, final String mandatory, final String architecture, + final String hpaVersion, final FlavorProperty flavorProperty) { + assertEquals(hpaFeature, flavorProperty.getHpaFeature()); + assertEquals(mandatory, flavorProperty.getMandatory()); + assertEquals(architecture, flavorProperty.getArchitecture()); + assertEquals(hpaVersion, flavorProperty.getHpaVersion()); + + assertEquals(0, flavorProperty.getDirectives().size()); + Directive directive = new Directive(); + flavorProperty.getDirectives().add(directive); + assertEquals(1, flavorProperty.getDirectives().size()); + flavorProperty.getDirectives().remove(directive); + assertEquals(0, flavorProperty.getDirectives().size()); + + assertEquals(0, flavorProperty.getHpaFeatureAttributes().size()); + HpaFeatureAttribute hpaFeatureAttribute = new HpaFeatureAttribute(); + flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); + assertEquals(1, flavorProperty.getHpaFeatureAttributes().size()); + flavorProperty.getHpaFeatureAttributes().remove(hpaFeatureAttribute); + assertEquals(0, flavorProperty.getHpaFeatureAttributes().size()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestHpaFeatureAttribute.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestHpaFeatureAttribute.java new file mode 100644 index 00000000..40c30eb7 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestHpaFeatureAttribute.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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.decoding.pdpx; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * Class to perform unit test for HpaFeatureAttribute 0f {@link HpaFeatureAttribute}. + * + */ +public class TestHpaFeatureAttribute { + + @Test + public void testHpaFeatureAttribute() { + final String hpaAttributeKey = "dummykey"; + final String hpaAttributeValue = "4096"; + final String operator = ">="; + final String unit = "MB"; + + final HpaFeatureAttribute hpaFeatureAttribute = new HpaFeatureAttribute(); + hpaFeatureAttribute.setHpaAttributeKey(hpaAttributeKey); + hpaFeatureAttribute.setHpaAttributeValue(hpaAttributeValue); + hpaFeatureAttribute.setOperator(operator); + hpaFeatureAttribute.setUnit(unit); + + validateReport(hpaAttributeKey,hpaAttributeValue,operator,unit,hpaFeatureAttribute); + } + + private void validateReport(final String hpaAttributeKey, final String hpaAttributeValue, final String operator, + final String unit, final HpaFeatureAttribute hpaFeatureAttribute) { + assertEquals(hpaAttributeKey, hpaFeatureAttribute.getHpaAttributeKey()); + assertEquals(hpaAttributeValue, hpaFeatureAttribute.getHpaAttributeValue()); + assertEquals(operator, hpaFeatureAttribute.getOperator()); + assertEquals(unit, hpaFeatureAttribute.getUnit()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java new file mode 100644 index 00000000..1ce5786c --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. 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.decoding.pdpx; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import java.io.IOException; +import java.util.Collection; + +import org.junit.Test; +import org.onap.policy.distribution.model.Csar; + +/** + * Class to perform unit test of {@link PolicyDecoderCsarPdpx}. + * + */ +public class TestPolicyDecoderCsarPdpx { + + @Test + public void testHpaPolicy2Vnf() throws IOException { + Csar csar = new Csar("src/test/resources/service-TestNs8-csar.csar"); + + PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); + try { + Collection ret = policyDecoderCsarPdpx.decode(csar); + assertEquals(2, ret.size()); + } catch (Exception e) { + fail("test should not thrown an exception here: " + e.getMessage()); + } + } + + @Test + public void testHpaPolicyFeature() throws IOException { + Csar csar = new Csar("src/test/resources/hpaPolicySRIOV.csar"); + + PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); + try { + Collection ret = policyDecoderCsarPdpx.decode(csar); + assertEquals(2, ret.size()); + } catch (Exception e) { + fail("test should not thrown an exception here: " + e.getMessage()); + } + } +} 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 new file mode 100644 index 00000000..0ea08905 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyParameterGroupTest.java @@ -0,0 +1,65 @@ +/*- + * ============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.decoding.policy.file; + +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}. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public class PolicyDecoderFileInCsarToPolicyParameterGroupTest { + + @Test + public void testConstructorAndGetters() { + final PolicyDecoderFileInCsarToPolicyParameterGroup configurationParameters = + new PolicyDecoderFileInCsarToPolicyParameterGroup("SamplePolicy", "APEX"); + configurationParameters.setName("myConfiguration"); + + assertEquals("myConfiguration", configurationParameters.getName()); + assertEquals("SamplePolicy", configurationParameters.getPolicyFileName()); + assertEquals("APEX", configurationParameters.getPolicyType()); + assertEquals(ValidationStatus.CLEAN, configurationParameters.validate().getStatus()); + } + + @Test + public void testInvalidPolicyFileName() { + final PolicyDecoderFileInCsarToPolicyParameterGroup configurationParameters = + new PolicyDecoderFileInCsarToPolicyParameterGroup("", "APEX"); + configurationParameters.setName("myConfiguration"); + + assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus()); + } + + @Test + public void testInvalidPolicyType() { + final PolicyDecoderFileInCsarToPolicyParameterGroup configurationParameters = + new PolicyDecoderFileInCsarToPolicyParameterGroup("SamplePolicy", ""); + configurationParameters.setName("myConfiguration"); + + assertEquals(ValidationStatus.INVALID, 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 new file mode 100644 index 00000000..e40ab3fe --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicyTest.java @@ -0,0 +1,109 @@ +/*- + * ============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.decoding.policy.file; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.IOException; +import java.util.Collection; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +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.distribution.model.Csar; +import org.onap.policy.distribution.model.PolicyAsString; + +/** + * Class to perform unit test of {@link PolicyDecoderFileInCsarToPolicy}. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +@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 GROUP_NAME = "apexPdpDecoderConfiguration"; + + /** + * Set up. + */ + @BeforeClass + public static void setUp() { + final PolicyDecoderFileInCsarToPolicyParameterGroup configurationParameters = + new PolicyDecoderFileInCsarToPolicyParameterGroup(POLICY_FILE_NAME, POLICY_TYPE); + configurationParameters.setName(GROUP_NAME); + ParameterService.register(configurationParameters); + } + + /** + * Tear down. + */ + @AfterClass + public static void tearDown() { + ParameterService.deregister(GROUP_NAME); + } + + @Test + public void testDecodePolicy() { + + final PolicyDecoderFileInCsarToPolicy decoder = new PolicyDecoderFileInCsarToPolicy(); + decoder.configure(GROUP_NAME); + + final File file = new File("src/test/resources/sampleTestService.csar"); + final Csar csar = new Csar(file.getAbsolutePath()); + + try { + decoder.canHandle(csar); + final Collection policyHolders = decoder.decode(csar); + for (final PolicyAsString policy : policyHolders) { + assertEquals(POLICY_FILE_NAME, policy.getPolicyName()); + assertEquals(POLICY_TYPE, policy.getPolicyType()); + } + } catch (final Exception exp) { + fail("Test must not throw an exception"); + } + } + + @Test + public void testDecodePolicyError() throws IOException { + + final PolicyDecoderFileInCsarToPolicy decoder = new PolicyDecoderFileInCsarToPolicy(); + decoder.configure(GROUP_NAME); + + final File file = new File("unknown.csar"); + final Csar csar = new Csar(file.getAbsolutePath()); + + try { + decoder.canHandle(csar); + decoder.decode(csar); + fail("Test must throw an exception"); + } catch (final Exception exp) { + assertTrue(exp.getMessage().contains("Failed decoding the policy")); + } + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestAttribute.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestAttribute.java deleted file mode 100644 index f11a7ecd..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestAttribute.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. 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.decoding.pdpx; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Class to perform unit test for Attribute 0f {@link Attribute}. - * - */ -public class TestAttribute { - - @Test - public void testAttribute() { - final String attributeName = "dummyName"; - final String attributeValue = "dummyValue"; - - final Attribute attribute = new Attribute(); - attribute.setAttributeName(attributeName); - attribute.setAttributeValue(attributeValue); - - validateReport(attributeName,attributeValue,attribute); - } - - private void validateReport(final String name, final String value, final Attribute attribute) { - assertEquals(name, attribute.getAttributeName()); - assertEquals(value, attribute.getAttributeValue()); - } -} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestContent.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestContent.java deleted file mode 100644 index a329a3ee..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestContent.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. 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.decoding.pdpx; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Class to perform unit test for Content 0f {@link Content}. - * - */ -public class TestContent { - - @Test - public void testContent() { - final String resources = "dummyresource"; - final String identity = "dummyidentity"; - final String policyType = "optimization"; - - final Content content = new Content(); - content.setResources(resources); - content.setIdentity(identity); - content.setPolicyType(policyType); - - validateReport(resources, identity, policyType,content); - } - - private void validateReport(final String resources, final String identity, final String policyType, - final Content content) { - assertEquals(resources, content.getResources()); - assertEquals(identity, content.getIdentity()); - assertEquals(policyType, content.getPolicyType()); - assertEquals(0, content.getPolicyScope().size()); - content.getPolicyScope().add("vFW"); - assertEquals(1, content.getPolicyScope().size()); - content.getPolicyScope().remove("vFW"); - assertEquals(0, content.getPolicyScope().size()); - assertEquals(0, content.getFlavorFeatures().size()); - FlavorFeature flavorFeature = new FlavorFeature(); - content.getFlavorFeatures().add(flavorFeature); - assertEquals(1, content.getFlavorFeatures().size()); - content.getFlavorFeatures().remove(flavorFeature); - assertEquals(0, content.getFlavorFeatures().size()); - } -} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestDirective.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestDirective.java deleted file mode 100644 index 48d11d32..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestDirective.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. 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.decoding.pdpx; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Class to perform unit test for Directive 0f {@link Directive}. - * - */ -public class TestDirective { - - @Test - public void testDirective() { - final String type = "dummytype"; - - final Directive directive = new Directive(); - directive.setType(type); - - validateReport(type,directive); - } - - private void validateReport(final String type, final Directive directive) { - assertEquals(type, directive.getType()); - assertEquals(0, directive.getAttributes().size()); - Attribute attribute = new Attribute(); - directive.getAttributes().add(attribute); - assertEquals(1, directive.getAttributes().size()); - directive.getAttributes().remove(attribute); - assertEquals(0, directive.getAttributes().size()); - } -} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorFeature.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorFeature.java deleted file mode 100644 index 47b4e343..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorFeature.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. 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.decoding.pdpx; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Class to perform unit test for FlavorFeature 0f {@link FlavorFeature}. - * - */ -public class TestFlavorFeature { - - @Test - public void testFlavorFeature() { - final String id = "dummyid"; - final String type = "dummytype"; - - final FlavorFeature flavorFeature = new FlavorFeature(); - flavorFeature.setId(id); - flavorFeature.setType(type); - - validateReport(id,type,flavorFeature); - } - - private void validateReport(final String id, final String type, final FlavorFeature flavorFeature) { - assertEquals(id, flavorFeature.getId()); - assertEquals(type, flavorFeature.getType()); - - assertEquals(0, flavorFeature.getDirectives().size()); - Directive directive = new Directive(); - flavorFeature.getDirectives().add(directive); - assertEquals(1, flavorFeature.getDirectives().size()); - flavorFeature.getDirectives().remove(directive); - assertEquals(0, flavorFeature.getDirectives().size()); - - assertEquals(0, flavorFeature.getFlavorProperties().size()); - FlavorProperty flavorProperty = new FlavorProperty(); - flavorFeature.getFlavorProperties().add(flavorProperty); - assertEquals(1, flavorFeature.getFlavorProperties().size()); - flavorFeature.getFlavorProperties().remove(flavorProperty); - assertEquals(0, flavorFeature.getFlavorProperties().size()); - } -} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorProperty.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorProperty.java deleted file mode 100644 index b5a535d7..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestFlavorProperty.java +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. 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.decoding.pdpx; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Class to perform unit test for FlavorProperty 0f {@link FlavorProperty}. - * - */ -public class TestFlavorProperty { - - @Test - public void testFlavorProperty() { - final String hpaFeature = "dummyid"; - final String mandatory = "false"; - final String architecture = "generic"; - final String hpaVersion = "v1"; - - final FlavorProperty flavorProperty = new FlavorProperty(); - flavorProperty.setHpaFeature(hpaFeature); - flavorProperty.setMandatory(mandatory); - flavorProperty.setArchitecture(architecture); - flavorProperty.setHpaVersion(hpaVersion); - - validateReport(hpaFeature,mandatory,architecture,hpaVersion,flavorProperty); - } - - private void validateReport(final String hpaFeature, final String mandatory, final String architecture, - final String hpaVersion, final FlavorProperty flavorProperty) { - assertEquals(hpaFeature, flavorProperty.getHpaFeature()); - assertEquals(mandatory, flavorProperty.getMandatory()); - assertEquals(architecture, flavorProperty.getArchitecture()); - assertEquals(hpaVersion, flavorProperty.getHpaVersion()); - - assertEquals(0, flavorProperty.getDirectives().size()); - Directive directive = new Directive(); - flavorProperty.getDirectives().add(directive); - assertEquals(1, flavorProperty.getDirectives().size()); - flavorProperty.getDirectives().remove(directive); - assertEquals(0, flavorProperty.getDirectives().size()); - - assertEquals(0, flavorProperty.getHpaFeatureAttributes().size()); - HpaFeatureAttribute hpaFeatureAttribute = new HpaFeatureAttribute(); - flavorProperty.getHpaFeatureAttributes().add(hpaFeatureAttribute); - assertEquals(1, flavorProperty.getHpaFeatureAttributes().size()); - flavorProperty.getHpaFeatureAttributes().remove(hpaFeatureAttribute); - assertEquals(0, flavorProperty.getHpaFeatureAttributes().size()); - } -} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestHpaFeatureAttribute.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestHpaFeatureAttribute.java deleted file mode 100644 index 40c30eb7..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestHpaFeatureAttribute.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. 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.decoding.pdpx; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Class to perform unit test for HpaFeatureAttribute 0f {@link HpaFeatureAttribute}. - * - */ -public class TestHpaFeatureAttribute { - - @Test - public void testHpaFeatureAttribute() { - final String hpaAttributeKey = "dummykey"; - final String hpaAttributeValue = "4096"; - final String operator = ">="; - final String unit = "MB"; - - final HpaFeatureAttribute hpaFeatureAttribute = new HpaFeatureAttribute(); - hpaFeatureAttribute.setHpaAttributeKey(hpaAttributeKey); - hpaFeatureAttribute.setHpaAttributeValue(hpaAttributeValue); - hpaFeatureAttribute.setOperator(operator); - hpaFeatureAttribute.setUnit(unit); - - validateReport(hpaAttributeKey,hpaAttributeValue,operator,unit,hpaFeatureAttribute); - } - - private void validateReport(final String hpaAttributeKey, final String hpaAttributeValue, final String operator, - final String unit, final HpaFeatureAttribute hpaFeatureAttribute) { - assertEquals(hpaAttributeKey, hpaFeatureAttribute.getHpaAttributeKey()); - assertEquals(hpaAttributeValue, hpaFeatureAttribute.getHpaAttributeValue()); - assertEquals(operator, hpaFeatureAttribute.getOperator()); - assertEquals(unit, hpaFeatureAttribute.getUnit()); - } -} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestPolicyDecoderCsarPdpx.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestPolicyDecoderCsarPdpx.java deleted file mode 100644 index 1ce5786c..00000000 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/decoding/pdpx/TestPolicyDecoderCsarPdpx.java +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Intel. 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.decoding.pdpx; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -import java.io.IOException; -import java.util.Collection; - -import org.junit.Test; -import org.onap.policy.distribution.model.Csar; - -/** - * Class to perform unit test of {@link PolicyDecoderCsarPdpx}. - * - */ -public class TestPolicyDecoderCsarPdpx { - - @Test - public void testHpaPolicy2Vnf() throws IOException { - Csar csar = new Csar("src/test/resources/service-TestNs8-csar.csar"); - - PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); - try { - Collection ret = policyDecoderCsarPdpx.decode(csar); - assertEquals(2, ret.size()); - } catch (Exception e) { - fail("test should not thrown an exception here: " + e.getMessage()); - } - } - - @Test - public void testHpaPolicyFeature() throws IOException { - Csar csar = new Csar("src/test/resources/hpaPolicySRIOV.csar"); - - PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); - try { - Collection ret = policyDecoderCsarPdpx.decode(csar); - assertEquals(2, ret.size()); - } catch (Exception e) { - fail("test should not thrown an exception here: " + e.getMessage()); - } - } -} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/DummyDecoder.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/DummyDecoder.java index 6a33e787..fd61c43d 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/DummyDecoder.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/DummyDecoder.java @@ -64,4 +64,7 @@ public class DummyDecoder implements PolicyDecoder { public DummyPolicy getDecodedPolicy() { return decodedPolicy; } + + @Override + public void configure(final String parameterGroupName) {} } diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java index c4020a41..231c50ff 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java @@ -322,7 +322,7 @@ public class TestSdcReceptionHandler { private Map getPolicyDecoders() { final Map policyDecoders = new HashMap(); final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters("DummyDecoder", - "org.onap.policy.distribution.reception.handling.sdc.DummyDecoder"); + "org.onap.policy.distribution.reception.handling.sdc.DummyDecoder", "DummyDecoderConfiguration"); policyDecoders.put("DummyDecoderKey", pDParameters); return policyDecoders; } diff --git a/plugins/reception-plugins/src/test/resources/sampleTestService.csar b/plugins/reception-plugins/src/test/resources/sampleTestService.csar new file mode 100644 index 00000000..387f1bae Binary files /dev/null and b/plugins/reception-plugins/src/test/resources/sampleTestService.csar differ -- cgit 1.2.3-korg