From 0f7c0e57f391e1c9e25c174ffb0b7bda370b713e Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 22 Oct 2019 21:56:25 -0700 Subject: changes in decoder as per new infra APIs Change-Id: Ie2ebfa16bc6b08dc54d60ef276f52e9ea2c91b1f Issue-ID: POLICY-1869 Signed-off-by: Liang Ding --- .../pdpx/PolicyDecoderCsarPdpxLifecycleApi.java | 32 +- .../TestPolicyDecoderCsarPdpxLifecycleApi.java | 325 ++++++++++----------- 2 files changed, 192 insertions(+), 165 deletions(-) (limited to 'plugins/reception-plugins/src') diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java index eadca94d..8cfc6857 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/pdpx/PolicyDecoderCsarPdpxLifecycleApi.java @@ -23,7 +23,9 @@ package org.onap.policy.distribution.reception.decoding.pdpx; import java.io.File; import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.common.utils.coder.StandardCoder; @@ -31,7 +33,12 @@ 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.policy.models.tosca.authorative.concepts.ToscaEntityKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; import org.onap.sdc.toscaparser.api.NodeTemplate; @@ -47,6 +54,14 @@ public class PolicyDecoderCsarPdpxLifecycleApi implements PolicyDecoder decode(final Csar csar) throws PolicyDecodingException { final List entities = new ArrayList<>(); @@ -61,7 +76,22 @@ public class PolicyDecoderCsarPdpxLifecycleApi implements PolicyDecoder props = new LinkedHashMap<>(); + props.put(TOSCA_POLICY_SCOPE, content.getScope()); + props.put(TOSCA_POLICY_SERVICES, content.getServices()); + props.put(TOSCA_POLICY_RESOURCES, content.getResources()); + props.put(TOSCA_POLICY_IDENTITY, content.getIdentity()); + props.put(TOSCA_POLICY_FLAVORFEATURES, content.getFlavorFeatures()); + ToscaPolicy policy = new ToscaPolicy(); + policy.setProperties(props); + Map map = new LinkedHashMap<>(); + String type = content.getPolicyType(); + map.put(type, policy); + List> policies = new ArrayList<>(); + policies.add(map); + ToscaTopologyTemplate topologyTemplate = new ToscaTopologyTemplate(); + topologyTemplate.setPolicies(policies); + entity.setToscaTopologyTemplate(topologyTemplate); entities.add(entity); } } diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApi.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApi.java index 02cf5e67..762549fa 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApi.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpxLifecycleApi.java @@ -21,25 +21,38 @@ package org.onap.policy.distribution.reception.decoding.pdpx; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.io.IOException; +import java.lang.String; import java.util.Collection; +import java.util.List; +import java.util.Map; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.common.parameters.ParameterGroup; import org.onap.policy.common.parameters.ParameterService; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.distribution.model.Csar; import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; +import org.onap.policy.distribution.reception.decoding.pdpx.FlavorFeature; +import org.onap.policy.distribution.reception.decoding.pdpx.PolicyDecoderCsarPdpxLifecycleApi; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; - +import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; /** - * Class to perform unit test of {@link PolicyDecoderCsarPdpxLifecycleApi}. + * Class to perform unit test of {@link PolicyDecoderCsarPdpxLifecycleApiLifecycleApi}. * */ public class TestPolicyDecoderCsarPdpxLifecycleApi { + private final StandardCoder encoder = new StandardCoder(); + /** * Set up for test cases. */ @@ -61,7 +74,7 @@ public class TestPolicyDecoderCsarPdpxLifecycleApi { } @Test - public void testHpaPolicy2Vnf() throws IOException, PolicyDecodingException { + public void testHpaPolicy2Vnf() throws IOException, PolicyDecodingException, CoderException { final Csar csar = new Csar("src/test/resources/service-TestNs8-csar.csar"); final PolicyDecoderCsarPdpxLifecycleApi policyDecoderCsarPdpx = new PolicyDecoderCsarPdpxLifecycleApi(); policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName()); @@ -69,208 +82,192 @@ public class TestPolicyDecoderCsarPdpxLifecycleApi { final Collection entities = policyDecoderCsarPdpx.decode(csar); assertEquals(2, entities.size()); - // final ToscaServiceTemplate entity = entities.iterator().next(); - // - // assertEquals("onapName", entity.getOnapName()); - // assertTrue(entity.getName().startsWith("OOF.")); - // assertTrue(entity.getConfigBody().contains("\"priority\":\"5\"")); - // assertTrue(entity.getConfigBody().contains("\"riskLevel\":\"2\"")); - // assertTrue(entity.getConfigBody().contains("\"riskType\":\"Test\"")); - // assertTrue(entity.getConfigBody().contains("\"version\":\"1.0\"")); - // assertTrue(entity.getConfigBody().contains("\"policyType\":\"hpa\"")); - // - // assertTrue(entity.getConfigBody().contains("\"id\":\"VDU_vgw_0\"")); - // assertTrue(entity.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); - // assertTrue(entity.getConfigBody().contains("\"type\":\"flavor_directives\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-feature\":\"basicCapabilities\"")); - // assertTrue(entity.getConfigBody().contains("\"mandatory\":\"True\"")); - // assertTrue(entity.getConfigBody().contains("\"architecture\":\"generic\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-version\":\"v1\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"virtualMemSize\"")); - // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\"")); - // assertTrue(entity.getConfigBody().contains("\"unit\":\"MB\"")); + final ToscaServiceTemplate entity = entities.iterator().next(); + ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); + Map map = topologyTemplate.getPolicies().get(0); + ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF); + Map props = policy.getProperties(); + Object flavorFeatures = + props.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_FLAVORFEATURES); + String features = encoder.encode(flavorFeatures); + assertTrue(features.contains("\"id\":\"VDU_vgw_0\"")); + assertTrue(features.contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); + assertTrue(features.contains("\"type\":\"flavor_directives\"")); + assertTrue(features.contains("\"hpa-feature\":\"basicCapabilities\"")); + assertTrue(features.contains("\"mandatory\":\"True\"")); + assertTrue(features.contains("\"architecture\":\"generic\"")); + assertTrue(features.contains("\"hpa-version\":\"v1\"")); + assertTrue(features.contains("\"hpa-attribute-key\":\"virtualMemSize\"")); + assertTrue(features.contains("\"operator\":\"=\"")); + assertTrue(features.contains("\"unit\":\"MB\"")); } @Test - public void testHpaPolicySriov() throws IOException, PolicyDecodingException { - // final Csar csar = new Csar("src/test/resources/hpaPolicySriov.csar"); + public void testHpaPolicySriov() throws IOException, PolicyDecodingException, CoderException { + final Csar csar = new Csar("src/test/resources/hpaPolicySriov.csar"); final PolicyDecoderCsarPdpxLifecycleApi policyDecoderCsarPdpx = new PolicyDecoderCsarPdpxLifecycleApi(); policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName()); - // final Collection entities = policyDecoderCsarPdpx.decode(csar); - // final ToscaServiceTemplate entity = entities.iterator().next(); - // - // assertEquals("onapName", entity.getOnapName()); - // assertTrue(entity.getName().startsWith("OOF.")); - // assertTrue(entity.getConfigBody().contains("\"priority\":\"5\"")); - // assertTrue(entity.getConfigBody().contains("\"riskLevel\":\"2\"")); - // assertTrue(entity.getConfigBody().contains("\"riskType\":\"Test\"")); - // assertTrue(entity.getConfigBody().contains("\"version\":\"1.0\"")); - // assertTrue(entity.getConfigBody().contains("\"policyType\":\"hpa\"")); - // - // assertTrue(entity.getConfigBody().contains("\"id\":\"VDU_vgw_0\"")); - // assertTrue(entity.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); - // assertTrue(entity.getConfigBody().contains("\"type\":\"flavor_directives\"")); - // assertTrue(entity.getConfigBody().contains("\"attribute_name\":\"flavorName\"")); - // assertTrue(entity.getConfigBody().contains("\"attribute_value\":\"\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-feature\":\"sriovNICNetwork\"")); - // assertTrue(entity.getConfigBody().contains("\"mandatory\":\"True\"")); - // assertTrue(entity.getConfigBody().contains("\"architecture\":\"generic\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-version\":\"v1\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"pciVendorId\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"1234\"")); - // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\"")); - // assertTrue(entity.getConfigBody().contains("\"unit\":\"\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"pciDeviceId\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"5678\"")); - // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\"")); - // assertTrue(entity.getConfigBody().contains("\"unit\":\"\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"pciNumDevices\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"1\"")); - // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\"")); - // assertTrue(entity.getConfigBody().contains("\"unit\":\"\"")); + final Collection entities = policyDecoderCsarPdpx.decode(csar); + final ToscaServiceTemplate entity = entities.iterator().next(); + ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); + Map map = topologyTemplate.getPolicies().get(0); + ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF); + Map props = policy.getProperties(); + Object flavorFeatures = + props.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_FLAVORFEATURES); + String features = encoder.encode(flavorFeatures); + assertTrue(features.contains("\"id\":\"VDU_vgw_0\"")); + assertTrue(features.contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); + assertTrue(features.contains("\"type\":\"flavor_directives\"")); + assertTrue(features.contains("\"attribute_name\":\"flavorName\"")); + assertTrue(features.contains("\"attribute_value\":\"\"")); + assertTrue(features.contains("\"hpa-feature\":\"sriovNICNetwork\"")); + assertTrue(features.contains("\"mandatory\":\"True\"")); + assertTrue(features.contains("\"architecture\":\"generic\"")); + assertTrue(features.contains("\"hpa-version\":\"v1\"")); + assertTrue(features.contains("\"hpa-attribute-key\":\"pciVendorId\"")); + assertTrue(features.contains("\"hpa-attribute-value\":\"1234\"")); + assertTrue(features.contains("\"operator\":\"=\"")); + assertTrue(features.contains("\"unit\":\"\"")); + assertTrue(features.contains("\"hpa-attribute-key\":\"pciDeviceId\"")); + assertTrue(features.contains("\"hpa-attribute-value\":\"5678\"")); + assertTrue(features.contains("\"operator\":\"=\"")); + assertTrue(features.contains("\"unit\":\"\"")); + assertTrue(features.contains("\"hpa-attribute-key\":\"pciNumDevices\"")); + assertTrue(features.contains("\"hpa-attribute-value\":\"1\"")); + assertTrue(features.contains("\"operator\":\"=\"")); + assertTrue(features.contains("\"unit\":\"\"")); } @Test - public void testHpaPolicyPciePassthrough() throws IOException, PolicyDecodingException { + public void testHpaPolicyPciePassthrough() throws IOException, PolicyDecodingException, CoderException { final Csar csar = new Csar("src/test/resources/hpaPolicyPciePassthrough.csar"); final PolicyDecoderCsarPdpxLifecycleApi policyDecoderCsarPdpx = new PolicyDecoderCsarPdpxLifecycleApi(); policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName()); final Collection entities = policyDecoderCsarPdpx.decode(csar); assertEquals(2, entities.size()); - // final ToscaServiceTemplate entity = entities.iterator().next(); - // - // assertEquals("onapName", entity.getOnapName()); - // assertTrue(entity.getName().startsWith("OOF.")); - // assertTrue(entity.getConfigBody().contains("\"priority\":\"5\"")); - // assertTrue(entity.getConfigBody().contains("\"riskLevel\":\"2\"")); - // assertTrue(entity.getConfigBody().contains("\"riskType\":\"Test\"")); - // assertTrue(entity.getConfigBody().contains("\"version\":\"1.0\"")); - // assertTrue(entity.getConfigBody().contains("\"policyType\":\"hpa\"")); - // - // assertTrue(entity.getConfigBody().contains("\"id\":\"VDU_vgw_0\"")); - // assertTrue(entity.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); - // assertTrue(entity.getConfigBody().contains("\"type\":\"flavor_directives\"")); - // assertTrue(entity.getConfigBody().contains("\"attribute_name\":\"flavorName\"")); - // assertTrue(entity.getConfigBody().contains("\"attribute_value\":\"\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-feature\":\"pciePassthrough\"")); - // assertTrue(entity.getConfigBody().contains("\"mandatory\":\"True\"")); - // assertTrue(entity.getConfigBody().contains("\"architecture\":\"generic\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-version\":\"v1\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"pciVendorId\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"1234\"")); - // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\"")); - // assertTrue(entity.getConfigBody().contains("\"unit\":\"\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"pciDeviceId\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"5678\"")); - // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\"")); - // assertTrue(entity.getConfigBody().contains("\"unit\":\"\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"pciNumDevices\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"1\"")); - // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\"")); - // assertTrue(entity.getConfigBody().contains("\"unit\":\"\"")); - - + final ToscaServiceTemplate entity = entities.iterator().next(); + ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); + Map map = topologyTemplate.getPolicies().get(0); + ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF); + Map props = policy.getProperties(); + Object flavorFeatures = + props.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_FLAVORFEATURES); + String features = encoder.encode(flavorFeatures); + assertTrue(features.contains("\"id\":\"VDU_vgw_0\"")); + assertTrue(features.contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); + assertTrue(features.contains("\"type\":\"flavor_directives\"")); + assertTrue(features.contains("\"attribute_name\":\"flavorName\"")); + assertTrue(features.contains("\"attribute_value\":\"\"")); + assertTrue(features.contains("\"hpa-feature\":\"pciePassthrough\"")); + assertTrue(features.contains("\"mandatory\":\"True\"")); + assertTrue(features.contains("\"architecture\":\"generic\"")); + assertTrue(features.contains("\"hpa-version\":\"v1\"")); + assertTrue(features.contains("\"hpa-attribute-key\":\"pciVendorId\"")); + assertTrue(features.contains("\"hpa-attribute-value\":\"1234\"")); + assertTrue(features.contains("\"operator\":\"=\"")); + assertTrue(features.contains("\"unit\":\"\"")); + assertTrue(features.contains("\"hpa-attribute-key\":\"pciDeviceId\"")); + assertTrue(features.contains("\"hpa-attribute-value\":\"5678\"")); + assertTrue(features.contains("\"operator\":\"=\"")); + assertTrue(features.contains("\"unit\":\"\"")); + assertTrue(features.contains("\"hpa-attribute-key\":\"pciNumDevices\"")); + assertTrue(features.contains("\"hpa-attribute-value\":\"1\"")); + assertTrue(features.contains("\"operator\":\"=\"")); + assertTrue(features.contains("\"unit\":\"\"")); } @Test - public void testHpaPolicyHugePage() throws IOException, PolicyDecodingException { + public void testHpaPolicyHugePage() throws IOException, PolicyDecodingException, CoderException { final Csar csar = new Csar("src/test/resources/hpaPolicyHugePage.csar"); final PolicyDecoderCsarPdpxLifecycleApi policyDecoderCsarPdpx = new PolicyDecoderCsarPdpxLifecycleApi(); policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName()); final Collection entities = policyDecoderCsarPdpx.decode(csar); assertEquals(2, entities.size()); - // final ToscaServiceTemplate entity = entities.iterator().next(); - // - // assertEquals("onapName", entity.getOnapName()); - // assertTrue(entity.getName().startsWith("OOF.")); - // assertTrue(entity.getConfigBody().contains("\"priority\":\"5\"")); - // assertTrue(entity.getConfigBody().contains("\"riskLevel\":\"2\"")); - // assertTrue(entity.getConfigBody().contains("\"riskType\":\"Test\"")); - // assertTrue(entity.getConfigBody().contains("\"version\":\"1.0\"")); - // assertTrue(entity.getConfigBody().contains("\"policyType\":\"hpa\"")); - // - // assertTrue(entity.getConfigBody().contains("\"id\":\"VDU_vgw_0\"")); - // assertTrue(entity.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); - // assertTrue(entity.getConfigBody().contains("\"type\":\"flavor_directives\"")); - // assertTrue(entity.getConfigBody().contains("\"attribute_name\":\"flavorName\"")); - // assertTrue(entity.getConfigBody().contains("\"attribute_value\":\"\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-feature\":\"hugePages\"")); - // assertTrue(entity.getConfigBody().contains("\"mandatory\":\"true\"")); - // assertTrue(entity.getConfigBody().contains("\"architecture\":\"generic\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-version\":\"v1\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"memoryPageSize\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"2\"")); - // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\"")); - // assertTrue(entity.getConfigBody().contains("\"unit\":\"MB\"")); + final ToscaServiceTemplate entity = entities.iterator().next(); + ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); + Map map = topologyTemplate.getPolicies().get(0); + ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF); + Map props = policy.getProperties(); + Object flavorFeatures = + props.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_FLAVORFEATURES); + String features = encoder.encode(flavorFeatures); + assertTrue(features.contains("\"id\":\"VDU_vgw_0\"")); + assertTrue(features.contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); + assertTrue(features.contains("\"type\":\"flavor_directives\"")); + assertTrue(features.contains("\"attribute_name\":\"flavorName\"")); + assertTrue(features.contains("\"attribute_value\":\"\"")); + assertTrue(features.contains("\"hpa-feature\":\"hugePages\"")); + assertTrue(features.contains("\"mandatory\":\"true\"")); + assertTrue(features.contains("\"architecture\":\"generic\"")); + assertTrue(features.contains("\"hpa-version\":\"v1\"")); + assertTrue(features.contains("\"hpa-attribute-key\":\"memoryPageSize\"")); + assertTrue(features.contains("\"hpa-attribute-value\":\"2\"")); + assertTrue(features.contains("\"operator\":\"=\"")); + assertTrue(features.contains("\"unit\":\"MB\"")); } @Test - public void testS3p0PciVendorId() throws IOException, PolicyDecodingException { + public void testS3p0PciVendorId() throws IOException, PolicyDecodingException, CoderException { final Csar csar = new Csar("src/test/resources/s3p_0_pciVendorId.csar"); final PolicyDecoderCsarPdpxLifecycleApi policyDecoderCsarPdpx = new PolicyDecoderCsarPdpxLifecycleApi(); policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName()); final Collection entities = policyDecoderCsarPdpx.decode(csar); assertEquals(1, entities.size()); - // final ToscaServiceTemplate entity = entities.iterator().next(); - // - // assertEquals("onapName", entity.getOnapName()); - // assertTrue(entity.getName().startsWith("OOF.")); - // assertTrue(entity.getConfigBody().contains("\"priority\":\"5\"")); - // assertTrue(entity.getConfigBody().contains("\"riskLevel\":\"2\"")); - // assertTrue(entity.getConfigBody().contains("\"riskType\":\"Test\"")); - // assertTrue(entity.getConfigBody().contains("\"version\":\"1.0\"")); - // assertTrue(entity.getConfigBody().contains("\"policyType\":\"hpa\"")); - // - // assertTrue(entity.getConfigBody().contains("\"id\":\"VDU_vgw_0\"")); - // assertTrue(entity.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); - // assertTrue(entity.getConfigBody().contains("\"type\":\"flavor_directives\"")); - // assertTrue(entity.getConfigBody().contains("\"attribute_name\":\"flavorName\"")); - // assertTrue(entity.getConfigBody().contains("\"attribute_value\":\"\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-feature\":\"pciePassthrough\"")); - // assertTrue(entity.getConfigBody().contains("\"mandatory\":\"True\"")); - // assertTrue(entity.getConfigBody().contains("\"architecture\":\"generic\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-version\":\"v1\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"pciVendorId\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"1234\"")); - // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\"")); - // assertTrue(entity.getConfigBody().contains("\"unit\":\"\"")); - + final ToscaServiceTemplate entity = entities.iterator().next(); + ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); + Map map = topologyTemplate.getPolicies().get(0); + ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF); + Map props = policy.getProperties(); + Object flavorFeatures = + props.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_FLAVORFEATURES); + String features = encoder.encode(flavorFeatures); + assertTrue(features.contains("\"id\":\"VDU_vgw_0\"")); + assertTrue(features.contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); + assertTrue(features.contains("\"type\":\"flavor_directives\"")); + assertTrue(features.contains("\"attribute_name\":\"flavorName\"")); + assertTrue(features.contains("\"attribute_value\":\"\"")); + assertTrue(features.contains("\"hpa-feature\":\"pciePassthrough\"")); + assertTrue(features.contains("\"mandatory\":\"True\"")); + assertTrue(features.contains("\"architecture\":\"generic\"")); + assertTrue(features.contains("\"hpa-version\":\"v1\"")); + assertTrue(features.contains("\"hpa-attribute-key\":\"pciVendorId\"")); + assertTrue(features.contains("\"hpa-attribute-value\":\"1234\"")); + assertTrue(features.contains("\"operator\":\"=\"")); + assertTrue(features.contains("\"unit\":\"\"")); } @Test - public void testserviceVcpeWithAll() throws IOException, PolicyDecodingException { + public void testserviceVcpeWithAll() throws IOException, PolicyDecodingException, CoderException { final Csar csar = new Csar("src/test/resources/service-VcpeWithAll-csar.csar"); final PolicyDecoderCsarPdpxLifecycleApi policyDecoderCsarPdpx = new PolicyDecoderCsarPdpxLifecycleApi(); policyDecoderCsarPdpx.configure(PolicyDecoderCsarPdpxLifecycleApiParameters.class.getSimpleName()); final Collection entities = policyDecoderCsarPdpx.decode(csar); assertEquals(5, entities.size()); - // final ToscaServiceTemplate entity = entities.iterator().next(); - // - // assertEquals("onapName", entity.getOnapName()); - // assertTrue(entity.getName().startsWith("OOF.")); - // assertTrue(entity.getConfigBody().contains("\"priority\":\"5\"")); - // assertTrue(entity.getConfigBody().contains("\"riskLevel\":\"2\"")); - // assertTrue(entity.getConfigBody().contains("\"riskType\":\"Test\"")); - // assertTrue(entity.getConfigBody().contains("\"version\":\"1.0\"")); - // assertTrue(entity.getConfigBody().contains("\"policyType\":\"hpa\"")); - // - // assertTrue(entity.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); - // assertTrue(entity.getConfigBody().contains("\"type\":\"flavor_directives\"")); - // assertTrue(entity.getConfigBody().contains("\"attribute_name\":\"flavorName\"")); - // assertTrue(entity.getConfigBody().contains("\"attribute_value\":\"\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-feature\":\"sriovNICNetwork\"")); - // assertTrue(entity.getConfigBody().contains("\"mandatory\":\"True\"")); - // assertTrue(entity.getConfigBody().contains("\"architecture\":\"generic\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-version\":\"v1\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-key\":\"pciVendorId\"")); - // assertTrue(entity.getConfigBody().contains("\"hpa-attribute-value\":\"1234\"")); - // assertTrue(entity.getConfigBody().contains("\"operator\":\"=\"")); - // assertTrue(entity.getConfigBody().contains("\"unit\":\"\"")); - + final ToscaServiceTemplate entity = entities.iterator().next(); + ToscaTopologyTemplate topologyTemplate = entity.getToscaTopologyTemplate(); + Map map = topologyTemplate.getPolicies().get(0); + ToscaPolicy policy = map.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_HPA_OOF); + Map props = policy.getProperties(); + Object flavorFeatures = + props.get(PolicyDecoderCsarPdpxLifecycleApi.TOSCA_POLICY_FLAVORFEATURES); + String features = encoder.encode(flavorFeatures); + assertTrue(features.contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\"")); + assertTrue(features.contains("\"type\":\"flavor_directives\"")); + assertTrue(features.contains("\"attribute_name\":\"flavorName\"")); + assertTrue(features.contains("\"attribute_value\":\"\"")); + assertTrue(features.contains("\"hpa-feature\":\"sriovNICNetwork\"")); + assertTrue(features.contains("\"mandatory\":\"True\"")); + assertTrue(features.contains("\"architecture\":\"generic\"")); + assertTrue(features.contains("\"hpa-version\":\"v1\"")); + assertTrue(features.contains("\"hpa-attribute-key\":\"pciVendorId\"")); + assertTrue(features.contains("\"hpa-attribute-value\":\"1234\"")); + assertTrue(features.contains("\"operator\":\"=\"")); + assertTrue(features.contains("\"unit\":\"\"")); } } -- cgit 1.2.3-korg