From 492a5ddfdd09ce0a046a61abd6e76a69d9cf477a Mon Sep 17 00:00:00 2001 From: xuegao Date: Fri, 21 Feb 2020 15:28:30 +0100 Subject: Rework the activate pdp group payload Rework the payload which triggers the activate pdp group policy API based on the new requirement. Issue-ID: CLAMP-646 Change-Id: I9bd7e3f2d1907c7e22c5435c792910b8245780b2 Signed-off-by: xuegao --- .../java/org/onap/clamp/loop/LoopToJsonTest.java | 23 ------------ .../org/onap/clamp/loop/PolicyComponentTest.java | 41 ++++++++++++++++++++-- 2 files changed, 39 insertions(+), 25 deletions(-) (limited to 'src/test/java/org') diff --git a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java index 34d524a6..6c6fb0c8 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", "", "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 e822dfb1..52e10d2d 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", ""); + 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); + } } -- cgit 1.2.3-korg