diff options
author | mmis <michael.morris@ericsson.com> | 2018-09-14 09:00:25 +0100 |
---|---|---|
committer | mmis <michael.morris@ericsson.com> | 2018-09-14 18:31:41 +0100 |
commit | 00b77b9ed6de5779212fecd30b71ebb615f89c3c (patch) | |
tree | 0f87db6033059fefdc7e6b278ab63d4225d1e068 /plugins/reception-plugins/src/test/java/org | |
parent | 6d43eadb867277856697778ae53cc21541d21d64 (diff) |
Aligned decoder with forwarder for opt. policies
Changed decoder for optimization policies to generate instance of
OptimizationPolicy (instead of PdpxPolicy) as expected by the forwarder.
Without this change there is a mismatch between the decoder and the
forwarder.
Added parameters for configuring the static elements of the optimization
policies and setting of these elements.
Issue-ID: POLICY-927
Change-Id: Ib91a905dc89eed13622fb88e4dd19b3cb9f62c75
Signed-off-by: mmis <michael.morris@ericsson.com>
Diffstat (limited to 'plugins/reception-plugins/src/test/java/org')
7 files changed, 157 insertions, 170 deletions
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 index f11a7ecd..565f17d3 100644 --- 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 @@ -39,7 +39,7 @@ public class TestAttribute { attribute.setAttributeName(attributeName); attribute.setAttributeValue(attributeValue); - validateReport(attributeName,attributeValue,attribute); + validateReport(attributeName, attributeValue, attribute); } private void validateReport(final String name, final String value, final Attribute attribute) { 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 index a329a3ee..56534d8f 100644 --- 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 @@ -41,11 +41,11 @@ public class TestContent { content.setIdentity(identity); content.setPolicyType(policyType); - validateReport(resources, identity, policyType,content); + validateReport(resources, identity, policyType, content); } - private void validateReport(final String resources, final String identity, final String policyType, - final Content 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()); 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 index 48d11d32..cc8d946f 100644 --- 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 @@ -37,7 +37,7 @@ public class TestDirective { final Directive directive = new Directive(); directive.setType(type); - validateReport(type,directive); + validateReport(type, directive); } private void validateReport(final String type, final Directive directive) { 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 index 47b4e343..e4de2759 100644 --- 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 @@ -39,7 +39,7 @@ public class TestFlavorFeature { flavorFeature.setId(id); flavorFeature.setType(type); - validateReport(id,type,flavorFeature); + validateReport(id, type, flavorFeature); } private void validateReport(final String id, final String type, final FlavorFeature flavorFeature) { 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 index b5a535d7..da6c26fc 100644 --- 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 @@ -43,11 +43,11 @@ public class TestFlavorProperty { flavorProperty.setArchitecture(architecture); flavorProperty.setHpaVersion(hpaVersion); - validateReport(hpaFeature,mandatory,architecture,hpaVersion,flavorProperty); + validateReport(hpaFeature, mandatory, architecture, hpaVersion, flavorProperty); } private void validateReport(final String hpaFeature, final String mandatory, final String architecture, - final String hpaVersion, final FlavorProperty flavorProperty) { + final String hpaVersion, final FlavorProperty flavorProperty) { assertEquals(hpaFeature, flavorProperty.getHpaFeature()); assertEquals(mandatory, flavorProperty.getMandatory()); assertEquals(architecture, flavorProperty.getArchitecture()); 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 index 40c30eb7..f2f514d0 100644 --- 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 @@ -43,11 +43,11 @@ public class TestHpaFeatureAttribute { hpaFeatureAttribute.setOperator(operator); hpaFeatureAttribute.setUnit(unit); - validateReport(hpaAttributeKey,hpaAttributeValue,operator,unit,hpaFeatureAttribute); + validateReport(hpaAttributeKey, hpaAttributeValue, operator, unit, hpaFeatureAttribute); } private void validateReport(final String hpaAttributeKey, final String hpaAttributeValue, final String operator, - final String unit, final HpaFeatureAttribute hpaFeatureAttribute) { + final String unit, final HpaFeatureAttribute hpaFeatureAttribute) { assertEquals(hpaAttributeKey, hpaFeatureAttribute.getHpaAttributeKey()); assertEquals(hpaAttributeValue, hpaFeatureAttribute.getHpaAttributeValue()); assertEquals(operator, hpaFeatureAttribute.getOperator()); 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 index 11bce326..0585b23a 100644 --- 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 @@ -21,16 +21,17 @@ 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 static org.junit.Assert.assertTrue; import java.io.IOException; import java.util.Collection; - +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.distribution.model.Csar; +import org.onap.policy.distribution.model.OptimizationPolicy; +import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; /** * Class to perform unit test of {@link PolicyDecoderCsarPdpx}. @@ -38,178 +39,164 @@ import org.onap.policy.distribution.model.Csar; */ public class TestPolicyDecoderCsarPdpx { + private static final String CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION = "csarToOptimizationPolicyConfiguration"; + + /** + * Set up for test cases. + */ + @BeforeClass + public static void setUp() { + ParameterGroup parameterGroup = new PolicyDecoderCsarPdpxConfigurationParameterBuilder().setOnapName("onapName") + .setPolicyNamePrefix("OOF").setPriority("5").setRiskLevel("2").setRiskType("Test").setVersion("1.0") + .build(); + parameterGroup.setName(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION); + ParameterService.register(parameterGroup); + } + @Test - public void testHpaPolicy2Vnf() throws IOException { + public void testHpaPolicy2Vnf() throws IOException, PolicyDecodingException { Csar csar = new Csar("src/test/resources/service-TestNs8-csar.csar"); PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); - try { - Collection<PdpxPolicy> ret = policyDecoderCsarPdpx.decode(csar); - assertEquals(2, ret.size()); - PdpxPolicy pdpxPolicy = (PdpxPolicy) ret.toArray()[0]; - assertEquals("Optimization", pdpxPolicy.getContent().getPolicyType()); - assertEquals(1, pdpxPolicy.getContent().getFlavorFeatures().size()); - - FlavorFeature flavorFeature = pdpxPolicy.getContent().getFlavorFeatures().get(0); - assertEquals("vdu_vnf_1", flavorFeature.getId()); - assertEquals("tosca.node.nfv.Vdu.Compute", flavorFeature.getType()); - assertEquals(1, flavorFeature.getDirectives().size()); - Directive directive = flavorFeature.getDirectives().get(0); - assertEquals("flavor_directive", directive.getType()); - assertEquals(1, directive.getAttributes().size()); - assertEquals("flavorName", directive.getAttributes().get(0).getAttributeName()); - assertEquals("", directive.getAttributes().get(0).getAttributeValue()); - assertEquals(2, flavorFeature.getFlavorProperties().size()); - FlavorProperty flavorProperty = flavorFeature.getFlavorProperties().get(0); - assertEquals("BasicCapabilities", flavorProperty.getHpaFeature()); - assertEquals("true", flavorProperty.getMandatory()); - assertEquals("generic", flavorProperty.getArchitecture()); - assertEquals("v1", flavorProperty.getHpaVersion()); - assertEquals(0, flavorProperty.getDirectives().size()); - assertEquals(1, flavorProperty.getHpaFeatureAttributes().size()); - HpaFeatureAttribute hpaFeatreAttribute = flavorProperty.getHpaFeatureAttributes().get(0); - assertEquals("virtualMemSize",hpaFeatreAttribute.getHpaAttributeKey()); - assertEquals("4096",hpaFeatreAttribute.getHpaAttributeValue()); - assertEquals("",hpaFeatreAttribute.getOperator()); - assertEquals("MB",hpaFeatreAttribute.getUnit()); - - } catch (Exception e) { - fail("test should not thrown an exception here: " + e.getMessage()); - } + policyDecoderCsarPdpx.configure(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION); + + Collection<OptimizationPolicy> ret = policyDecoderCsarPdpx.decode(csar); + + assertEquals(2, ret.size()); + OptimizationPolicy policy = (OptimizationPolicy) ret.toArray()[0]; + + assertEquals("onapName", policy.getOnapName()); + assertTrue(policy.getPolicyName().startsWith("OOF.")); + assertTrue(policy.getConfigBody().contains("\"priority\":\"5\"")); + assertTrue(policy.getConfigBody().contains("\"riskLevel\":\"2\"")); + assertTrue(policy.getConfigBody().contains("\"riskType\":\"Test\"")); + assertTrue(policy.getConfigBody().contains("\"version\":\"1.0\"")); + assertTrue(policy.getConfigBody().contains("\"policyType\":\"Optimization\"")); + + assertTrue(policy.getConfigBody().contains("\"id\":\"vdu_vnf_1\"")); + assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.node.nfv.Vdu.Compute\"")); + assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directive\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-feature\":\"BasicCapabilities\"")); + assertTrue(policy.getConfigBody().contains("\"mandatory\":\"true\"")); + assertTrue(policy.getConfigBody().contains("\"architecture\":\"generic\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-version\":\"v1\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-attribute-key\":\"virtualMemSize\"")); + assertTrue(policy.getConfigBody().contains("\"operator\":\"\"")); + assertTrue(policy.getConfigBody().contains("\"unit\":\"MB\"")); } @Test - public void testHpaPolicySriov() throws IOException { + public void testHpaPolicySriov() throws IOException, PolicyDecodingException { Csar csar = new Csar("src/test/resources/hpaPolicySriov.csar"); PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); - try { - Collection<PdpxPolicy> ret = policyDecoderCsarPdpx.decode(csar); - assertEquals(2, ret.size()); - PdpxPolicy pdpxPolicy = (PdpxPolicy) ret.toArray()[0]; - assertEquals("Optimization", pdpxPolicy.getContent().getPolicyType()); - assertEquals(1, pdpxPolicy.getContent().getFlavorFeatures().size()); - - FlavorFeature flavorFeature = pdpxPolicy.getContent().getFlavorFeatures().get(0); - assertEquals("vdu_vnf_1", flavorFeature.getId()); - assertEquals("tosca.node.nfv.Vdu.Compute", flavorFeature.getType()); - assertEquals(1, flavorFeature.getDirectives().size()); - Directive directive = flavorFeature.getDirectives().get(0); - assertEquals("flavor_directive", directive.getType()); - assertEquals(1, directive.getAttributes().size()); - assertEquals("flavorName", directive.getAttributes().get(0).getAttributeName()); - assertEquals("", directive.getAttributes().get(0).getAttributeValue()); - assertEquals(4, flavorFeature.getFlavorProperties().size()); - FlavorProperty flavorProperty = flavorFeature.getFlavorProperties().get(3); - assertEquals("SriovNICNetwork", flavorProperty.getHpaFeature()); - assertEquals("true", flavorProperty.getMandatory()); - assertEquals("generic", flavorProperty.getArchitecture()); - assertEquals("v1", flavorProperty.getHpaVersion()); - assertEquals(0, flavorProperty.getDirectives().size()); - assertEquals(3, flavorProperty.getHpaFeatureAttributes().size()); - - HpaFeatureAttribute pciVendorId = flavorProperty.getHpaFeatureAttributes().get(0); - assertEquals("pciVendorId",pciVendorId.getHpaAttributeKey()); - assertEquals("1234",pciVendorId.getHpaAttributeValue()); - assertEquals("",pciVendorId.getOperator()); - assertEquals("",pciVendorId.getUnit()); - HpaFeatureAttribute pciDeviceId = flavorProperty.getHpaFeatureAttributes().get(1); - assertEquals("pciDeviceId",pciDeviceId.getHpaAttributeKey()); - assertEquals("5678",pciDeviceId.getHpaAttributeValue()); - assertEquals("",pciDeviceId.getOperator()); - assertEquals("",pciDeviceId.getUnit()); - HpaFeatureAttribute pciNumDevices = flavorProperty.getHpaFeatureAttributes().get(2); - assertEquals("pciNumDevices",pciNumDevices.getHpaAttributeKey()); - assertEquals("1",pciNumDevices.getHpaAttributeValue()); - assertEquals("",pciNumDevices.getOperator()); - assertEquals("",pciNumDevices.getUnit()); - } catch (Exception e) { - fail("test should not thrown an exception here: " + e.getMessage()); - } + policyDecoderCsarPdpx.configure(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION); + + Collection<OptimizationPolicy> policies = policyDecoderCsarPdpx.decode(csar); + OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0]; + + assertEquals("onapName", policy.getOnapName()); + assertTrue(policy.getPolicyName().startsWith("OOF.")); + assertTrue(policy.getConfigBody().contains("\"priority\":\"5\"")); + assertTrue(policy.getConfigBody().contains("\"riskLevel\":\"2\"")); + assertTrue(policy.getConfigBody().contains("\"riskType\":\"Test\"")); + assertTrue(policy.getConfigBody().contains("\"version\":\"1.0\"")); + assertTrue(policy.getConfigBody().contains("\"policyType\":\"Optimization\"")); + + assertTrue(policy.getConfigBody().contains("\"id\":\"vdu_vnf_1\"")); + assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.node.nfv.Vdu.Compute\"")); + assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directive\"")); + assertTrue(policy.getConfigBody().contains("\"attribute_name\":\"flavorName\"")); + assertTrue(policy.getConfigBody().contains("\"attribute_value\":\"\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-feature\":\"SriovNICNetwork\"")); + assertTrue(policy.getConfigBody().contains("\"mandatory\":\"true\"")); + assertTrue(policy.getConfigBody().contains("\"architecture\":\"generic\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-version\":\"v1\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-attribute-key\":\"pciVendorId\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-attribute-value\":\"1234\"")); + assertTrue(policy.getConfigBody().contains("\"operator\":\"\"")); + assertTrue(policy.getConfigBody().contains("\"unit\":\"\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-attribute-key\":\"pciDeviceId\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-attribute-value\":\"5678\"")); + assertTrue(policy.getConfigBody().contains("\"operator\":\"\"")); + assertTrue(policy.getConfigBody().contains("\"unit\":\"\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-attribute-key\":\"pciNumDevices\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-attribute-value\":\"1\"")); + assertTrue(policy.getConfigBody().contains("\"operator\":\"\"")); + assertTrue(policy.getConfigBody().contains("\"unit\":\"\"")); } @Test - public void testHpaPolicyPciePassthrough() throws IOException { + public void testHpaPolicyPciePassthrough() throws IOException, PolicyDecodingException { Csar csar = new Csar("src/test/resources/hpaPolicyPciePassthrough.csar"); PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); - try { - Collection<PdpxPolicy> ret = policyDecoderCsarPdpx.decode(csar); - assertEquals(2, ret.size()); - PdpxPolicy pdpxPolicy = (PdpxPolicy) ret.toArray()[0]; - assertEquals("Optimization", pdpxPolicy.getContent().getPolicyType()); - assertEquals(1, pdpxPolicy.getContent().getFlavorFeatures().size()); - - FlavorFeature flavorFeature = pdpxPolicy.getContent().getFlavorFeatures().get(0); - assertEquals("vdu_vnf_1", flavorFeature.getId()); - assertEquals("tosca.node.nfv.Vdu.Compute", flavorFeature.getType()); - assertEquals(1, flavorFeature.getDirectives().size()); - Directive directive = flavorFeature.getDirectives().get(0); - assertEquals("flavor_directive", directive.getType()); - assertEquals(1, directive.getAttributes().size()); - assertEquals("flavorName", directive.getAttributes().get(0).getAttributeName()); - assertEquals("", directive.getAttributes().get(0).getAttributeValue()); - assertEquals(4, flavorFeature.getFlavorProperties().size()); - FlavorProperty flavorProperty = flavorFeature.getFlavorProperties().get(3); - assertEquals("pciePassthrough", flavorProperty.getHpaFeature()); - assertEquals("true", flavorProperty.getMandatory()); - assertEquals("generic", flavorProperty.getArchitecture()); - assertEquals("v1", flavorProperty.getHpaVersion()); - assertEquals(0, flavorProperty.getDirectives().size()); - assertEquals(3, flavorProperty.getHpaFeatureAttributes().size()); - - HpaFeatureAttribute pciVendorId = flavorProperty.getHpaFeatureAttributes().get(0); - assertEquals("pciVendorId",pciVendorId.getHpaAttributeKey()); - assertEquals("1234",pciVendorId.getHpaAttributeValue()); - assertEquals("",pciVendorId.getOperator()); - assertEquals("",pciVendorId.getUnit()); - HpaFeatureAttribute pciDeviceId = flavorProperty.getHpaFeatureAttributes().get(1); - assertEquals("pciDeviceId",pciDeviceId.getHpaAttributeKey()); - assertEquals("5678",pciDeviceId.getHpaAttributeValue()); - assertEquals("",pciDeviceId.getOperator()); - assertEquals("",pciDeviceId.getUnit()); - HpaFeatureAttribute pciNumDevices = flavorProperty.getHpaFeatureAttributes().get(2); - assertEquals("pciNumDevices",pciNumDevices.getHpaAttributeKey()); - assertEquals("1",pciNumDevices.getHpaAttributeValue()); - assertEquals("",pciNumDevices.getOperator()); - assertEquals("",pciNumDevices.getUnit()); - } catch (Exception e) { - fail("test should not thrown an exception here: " + e.getMessage()); - } + policyDecoderCsarPdpx.configure(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION); + + Collection<OptimizationPolicy> policies = policyDecoderCsarPdpx.decode(csar); + assertEquals(2, policies.size()); + OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0]; + + assertEquals("onapName", policy.getOnapName()); + assertTrue(policy.getPolicyName().startsWith("OOF.")); + assertTrue(policy.getConfigBody().contains("\"priority\":\"5\"")); + assertTrue(policy.getConfigBody().contains("\"riskLevel\":\"2\"")); + assertTrue(policy.getConfigBody().contains("\"riskType\":\"Test\"")); + assertTrue(policy.getConfigBody().contains("\"version\":\"1.0\"")); + assertTrue(policy.getConfigBody().contains("\"policyType\":\"Optimization\"")); + + assertTrue(policy.getConfigBody().contains("\"id\":\"vdu_vnf_1\"")); + assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.node.nfv.Vdu.Compute\"")); + assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directive\"")); + assertTrue(policy.getConfigBody().contains("\"attribute_name\":\"flavorName\"")); + assertTrue(policy.getConfigBody().contains("\"attribute_value\":\"\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-feature\":\"pciePassthrough\"")); + assertTrue(policy.getConfigBody().contains("\"mandatory\":\"true\"")); + assertTrue(policy.getConfigBody().contains("\"architecture\":\"generic\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-version\":\"v1\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-attribute-key\":\"pciVendorId\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-attribute-value\":\"1234\"")); + assertTrue(policy.getConfigBody().contains("\"operator\":\"\"")); + assertTrue(policy.getConfigBody().contains("\"unit\":\"\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-attribute-key\":\"pciDeviceId\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-attribute-value\":\"5678\"")); + assertTrue(policy.getConfigBody().contains("\"operator\":\"\"")); + assertTrue(policy.getConfigBody().contains("\"unit\":\"\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-attribute-key\":\"pciNumDevices\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-attribute-value\":\"1\"")); + assertTrue(policy.getConfigBody().contains("\"operator\":\"\"")); + assertTrue(policy.getConfigBody().contains("\"unit\":\"\"")); + + } @Test - public void testHpaPolicyHugePage() throws IOException { + public void testHpaPolicyHugePage() throws IOException, PolicyDecodingException { Csar csar = new Csar("src/test/resources/hpaPolicyHugePage.csar"); PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx(); - try { - Collection<PdpxPolicy> ret = policyDecoderCsarPdpx.decode(csar); - assertEquals(2, ret.size()); - PdpxPolicy pdpxPolicy = (PdpxPolicy) ret.toArray()[0]; - assertEquals("Optimization", pdpxPolicy.getContent().getPolicyType()); - assertEquals(1, pdpxPolicy.getContent().getFlavorFeatures().size()); - - FlavorFeature flavorFeature = pdpxPolicy.getContent().getFlavorFeatures().get(0); - assertEquals("vdu_vnf_1", flavorFeature.getId()); - assertEquals("tosca.node.nfv.Vdu.Compute", flavorFeature.getType()); - assertEquals(1, flavorFeature.getDirectives().size()); - Directive directive = flavorFeature.getDirectives().get(0); - assertEquals("flavor_directive", directive.getType()); - assertEquals(1, directive.getAttributes().size()); - assertEquals("flavorName", directive.getAttributes().get(0).getAttributeName()); - assertEquals("", directive.getAttributes().get(0).getAttributeValue()); - assertEquals(3, flavorFeature.getFlavorProperties().size()); - FlavorProperty flavorProperty = flavorFeature.getFlavorProperties().get(2); - assertEquals("hugePages", flavorProperty.getHpaFeature()); - assertEquals("false", flavorProperty.getMandatory()); - assertEquals("generic", flavorProperty.getArchitecture()); - assertEquals("v1", flavorProperty.getHpaVersion()); - assertEquals(0, flavorProperty.getDirectives().size()); - assertEquals(1, flavorProperty.getHpaFeatureAttributes().size()); - HpaFeatureAttribute hpaFeatreAttribute = flavorProperty.getHpaFeatureAttributes().get(0); - assertEquals("memoryPageSize",hpaFeatreAttribute.getHpaAttributeKey()); - assertEquals("2",hpaFeatreAttribute.getHpaAttributeValue()); - assertEquals("",hpaFeatreAttribute.getOperator()); - assertEquals("MB",hpaFeatreAttribute.getUnit()); - } catch (Exception e) { - fail("test should not thrown an exception here: " + e.getMessage()); - } + policyDecoderCsarPdpx.configure(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION); + + Collection<OptimizationPolicy> policies = policyDecoderCsarPdpx.decode(csar); + assertEquals(2, policies.size()); + OptimizationPolicy policy = (OptimizationPolicy) policies.toArray()[0]; + + assertEquals("onapName", policy.getOnapName()); + assertTrue(policy.getPolicyName().startsWith("OOF.")); + assertTrue(policy.getConfigBody().contains("\"priority\":\"5\"")); + assertTrue(policy.getConfigBody().contains("\"riskLevel\":\"2\"")); + assertTrue(policy.getConfigBody().contains("\"riskType\":\"Test\"")); + assertTrue(policy.getConfigBody().contains("\"version\":\"1.0\"")); + assertTrue(policy.getConfigBody().contains("\"policyType\":\"Optimization\"")); + + assertTrue(policy.getConfigBody().contains("\"id\":\"vdu_vnf_1\"")); + assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.node.nfv.Vdu.Compute\"")); + assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directive\"")); + assertTrue(policy.getConfigBody().contains("\"attribute_name\":\"flavorName\"")); + assertTrue(policy.getConfigBody().contains("\"attribute_value\":\"\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-feature\":\"hugePages\"")); + assertTrue(policy.getConfigBody().contains("\"mandatory\":\"false\"")); + assertTrue(policy.getConfigBody().contains("\"architecture\":\"generic\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-version\":\"v1\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-attribute-key\":\"memoryPageSize\"")); + assertTrue(policy.getConfigBody().contains("\"hpa-attribute-value\":\"2\"")); + assertTrue(policy.getConfigBody().contains("\"operator\":\"\"")); + assertTrue(policy.getConfigBody().contains("\"unit\":\"MB\"")); } } |