diff options
author | Sébastien Determe <sebastien.determe@intl.att.com> | 2020-03-03 09:57:30 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-03-03 09:57:30 +0000 |
commit | ae6a9829f0c572cb4789812ea65871132ec861fd (patch) | |
tree | 08b2a46011795685b1a165684f95d5a59867bc9e /src/test | |
parent | 47caef3827de362e7b6204b01d73238fb6faa714 (diff) | |
parent | 492a5ddfdd09ce0a046a61abd6e76a69d9cf477a (diff) |
Merge "Rework the activate pdp group payload"
Diffstat (limited to 'src/test')
3 files changed, 66 insertions, 34 deletions
diff --git a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java index 34d524a6d..6c6fb0c87 100644 --- a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java +++ b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java @@ -37,7 +37,6 @@ import java.util.Random; import org.junit.Test; import org.onap.clamp.clds.util.JsonUtils; import org.onap.clamp.clds.util.ResourceFileUtil; -import org.onap.clamp.loop.components.external.PolicyComponent; import org.onap.clamp.loop.log.LogType; import org.onap.clamp.loop.log.LoopLog; import org.onap.clamp.loop.service.Service; @@ -46,7 +45,6 @@ import org.onap.clamp.loop.template.LoopTemplate; import org.onap.clamp.loop.template.PolicyModel; import org.onap.clamp.policy.microservice.MicroServicePolicy; import org.onap.clamp.policy.operational.OperationalPolicy; -import org.skyscreamer.jsonassert.JSONAssert; public class LoopToJsonTest { @@ -173,25 +171,4 @@ public class LoopToJsonTest { assertThat(loopTestDeserialized).isEqualToIgnoringGivenFields(loopTest2, "modelService", "svgRepresentation", "blueprint", "components"); } - - /** - * This tests the GSON encode/decode of pdpGroup. - * - * @throws IOException In case of issues - */ - @Test - public void createPoliciesPayloadPdpGroupTest() throws IOException { - Loop loopTest = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}", - "123456789", "https://dcaetest.org", "UUID-blueprint"); - OperationalPolicy opPolicy = this.getOperationalPolicy( - ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), "GuardOpPolicyTest"); - loopTest.addOperationalPolicy(opPolicy); - MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "", - "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0", - "{\"param1\":\"value1\"}", true); - loopTest.addMicroServicePolicy(microServicePolicy); - - JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/pdp-group-policy-payload.json"), - PolicyComponent.createPoliciesPayloadPdpGroup(loopTest), false); - } } diff --git a/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java b/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java index e822dfb1a..52e10d2db 100644 --- a/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java +++ b/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java @@ -24,15 +24,20 @@ package org.onap.clamp.loop; import static org.assertj.core.api.Assertions.assertThat; - +import com.google.gson.Gson; +import com.google.gson.JsonObject; import java.io.IOException; - import org.apache.camel.Exchange; import org.apache.camel.Message; import org.junit.Test; import org.mockito.Mockito; +import org.onap.clamp.clds.util.ResourceFileUtil; import org.onap.clamp.loop.components.external.ExternalComponentState; import org.onap.clamp.loop.components.external.PolicyComponent; +import org.onap.clamp.loop.template.LoopTemplate; +import org.onap.clamp.loop.template.PolicyModel; +import org.onap.clamp.policy.microservice.MicroServicePolicy; +import org.onap.clamp.policy.operational.OperationalPolicy; public class PolicyComponentTest { @@ -243,4 +248,36 @@ public class PolicyComponentTest { assertThat(state4.getStateName()).isEqualTo("IN_ERROR"); } + + /** + * Test the create policies payload PdpGroup test. + */ + @Test + public void createPoliciesPayloadPdpGroupTest() throws IOException { + Loop loopTest = new Loop("ControlLoopTest", "<xml></xml>"); + PolicyModel policyModel1 = new PolicyModel("onap.policies.monitoring.test", null, "1.0.0"); + + MicroServicePolicy microServicePolicy = new MicroServicePolicy("configPolicyTest", policyModel1, true, + new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), null); + microServicePolicy.setPdpGroup("pdpGroup1"); + microServicePolicy.setPdpSubGroup("pdpSubgroup1"); + + loopTest.addMicroServicePolicy(microServicePolicy); + + PolicyModel policyModel2 = new PolicyModel("onap.policies.controlloop.Operational", null, "1.0.0"); + OperationalPolicy opPolicy = new OperationalPolicy("opPolicy", loopTest, + new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), policyModel2, null); + opPolicy.setPdpGroup("pdpGroup2"); + opPolicy.setPdpSubGroup("pdpSubgroup2"); + + loopTest.addOperationalPolicy(opPolicy); + + LoopTemplate loopTemplate = new LoopTemplate("test", "yaml", "svg", 1, null); + loopTemplate.setDcaeBlueprintId("UUID-blueprint"); + loopTest.setLoopTemplate(loopTemplate); + + String payload = PolicyComponent.createPoliciesPayloadPdpGroup(loopTest); + String expectedRes = ResourceFileUtil.getResourceAsString("tosca/pdp-group-policy-payload.json"); + assertThat(payload).isEqualTo(expectedRes); + } } diff --git a/src/test/resources/tosca/pdp-group-policy-payload.json b/src/test/resources/tosca/pdp-group-policy-payload.json index ad3a5b4c3..93a85457a 100644 --- a/src/test/resources/tosca/pdp-group-policy-payload.json +++ b/src/test/resources/tosca/pdp-group-policy-payload.json @@ -1,16 +1,34 @@ { - "policies": [ + "groups": [ { - "policy-id": "GuardOpPolicyTest" + "name": "pdpGroup2", + "deploymentSubgroups": [ + { + "pdpType": "pdpSubgroup2", + "action": "POST", + "policies": [ + { + "name": "onap.policies.controlloop.Operational", + "version": "1.0.0" + } + ] + } + ] }, { - "policy-id": "guard.minmax.new" - }, - { - "policy-id": "guard.frequency.new" - }, - { - "policy-id": "configPolicyTest" + "name": "pdpGroup1", + "deploymentSubgroups": [ + { + "pdpType": "pdpSubgroup1", + "action": "POST", + "policies": [ + { + "name": "onap.policies.monitoring.test", + "version": "1.0.0" + } + ] + } + ] } ] }
\ No newline at end of file |