aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/reception-plugins/src/test/java/org
diff options
context:
space:
mode:
authorliboNet <libo.zhu@intel.com>2018-11-27 08:10:33 +0800
committerliboNet <libo.zhu@intel.com>2018-12-04 08:49:27 +0800
commit987cb61f269572fec7c0b0fe500f081ca36c2dd9 (patch)
tree20e53b5abe8f08d13d43a30f2b1509379b7f29f9 /plugins/reception-plugins/src/test/java/org
parentcf2a21536bd30ebb8b4544f51ad3024dae310842 (diff)
Fix policy format with vCPE service
. change the capital and lower-case letter . add missing fields in ConfigBody policyName and templateVersion that are requried by OOF . add '=' into default operator once no such info in the input CSAR . based on the vCPE service, which includes several CPs, some may do NOT connect any VDU. so need deal with such case. . add new test case to cover complicated service includes 5 policies . change the resource's type from String to List as requried by OOF which needs such format to deal with all kind of policies beides hpa . improve the code style Change-Id: Id39b1a0511c362c5ae9dce409af18b032832de80 Issue-ID: POLICY-1282 Signed-off-by: liboNet <libo.zhu@intel.com>
Diffstat (limited to 'plugins/reception-plugins/src/test/java/org')
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestContent.java12
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/decoding/pdpx/TestPolicyDecoderCsarPdpx.java83
2 files changed, 65 insertions, 30 deletions
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 56534d8f..d678239f 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
@@ -32,21 +32,18 @@ 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);
+ validateReport(identity, policyType, content);
}
- private void validateReport(final String resources, final String identity, final String policyType,
+ private void validateReport(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());
@@ -60,5 +57,10 @@ public class TestContent {
assertEquals(1, content.getFlavorFeatures().size());
content.getFlavorFeatures().remove(flavorFeature);
assertEquals(0, content.getFlavorFeatures().size());
+ assertEquals(0, content.getResources().size());
+ content.getResources().add("vGW");
+ assertEquals(1, content.getResources().size());
+ content.getResources().remove("vGW");
+ assertEquals(0, content.getResources().size());
}
}
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 3826ec92..2d91f837 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
@@ -80,17 +80,17 @@ public class TestPolicyDecoderCsarPdpx {
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("\"policyType\":\"hpa\""));
assertTrue(policy.getConfigBody().contains("\"id\":\"VDU_vnf_1\""));
- assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.node.nfv.Vdu.Compute\""));
+ assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directives\""));
- assertTrue(policy.getConfigBody().contains("\"hpa-feature\":\"BasicCapabilities\""));
- assertTrue(policy.getConfigBody().contains("\"mandatory\":\"true\""));
+ 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("\"operator\":\"=\""));
assertTrue(policy.getConfigBody().contains("\"unit\":\"MB\""));
}
@@ -109,28 +109,28 @@ public class TestPolicyDecoderCsarPdpx {
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("\"policyType\":\"hpa\""));
assertTrue(policy.getConfigBody().contains("\"id\":\"VDU_vnf_1\""));
- assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.node.nfv.Vdu.Compute\""));
+ assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directives\""));
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("\"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("\"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("\"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("\"operator\":\"=\""));
assertTrue(policy.getConfigBody().contains("\"unit\":\"\""));
}
@@ -150,28 +150,28 @@ public class TestPolicyDecoderCsarPdpx {
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("\"policyType\":\"hpa\""));
assertTrue(policy.getConfigBody().contains("\"id\":\"VDU_vnf_1\""));
- assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.node.nfv.Vdu.Compute\""));
+ assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directives\""));
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("\"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("\"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("\"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("\"operator\":\"=\""));
assertTrue(policy.getConfigBody().contains("\"unit\":\"\""));
@@ -193,10 +193,10 @@ public class TestPolicyDecoderCsarPdpx {
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("\"policyType\":\"hpa\""));
assertTrue(policy.getConfigBody().contains("\"id\":\"VDU_vnf_1\""));
- assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.node.nfv.Vdu.Compute\""));
+ assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directives\""));
assertTrue(policy.getConfigBody().contains("\"attribute_name\":\"flavorName\""));
assertTrue(policy.getConfigBody().contains("\"attribute_value\":\"\""));
@@ -206,7 +206,7 @@ public class TestPolicyDecoderCsarPdpx {
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("\"operator\":\"=\""));
assertTrue(policy.getConfigBody().contains("\"unit\":\"MB\""));
}
@@ -226,20 +226,53 @@ public class TestPolicyDecoderCsarPdpx {
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("\"policyType\":\"hpa\""));
assertTrue(policy.getConfigBody().contains("\"id\":\"VDU_vgw_0\""));
- assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.node.nfv.Vdu.Compute\""));
+ assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directives\""));
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("\"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("\"operator\":\"=\""));
+ assertTrue(policy.getConfigBody().contains("\"unit\":\"\""));
+
+ }
+
+ @Test
+ public void testserviceVcpeWithAll() throws IOException, PolicyDecodingException {
+ final Csar csar = new Csar("src/test/resources/service-VcpeWithAll-csar.csar");
+ final PolicyDecoderCsarPdpx policyDecoderCsarPdpx = new PolicyDecoderCsarPdpx();
+ policyDecoderCsarPdpx.configure(CSAR_TO_OPTIMIZATION_POLICY_CONFIGURATION);
+
+ final Collection<OptimizationPolicy> policies = policyDecoderCsarPdpx.decode(csar);
+ assertEquals(5, policies.size());
+ final 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\":\"hpa\""));
+
+ assertTrue(policy.getConfigBody().contains("\"type\":\"tosca.nodes.nfv.Vdu.Compute\""));
+ assertTrue(policy.getConfigBody().contains("\"type\":\"flavor_directives\""));
+ 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\":\"\""));
}