diff options
Diffstat (limited to 'src/test')
3 files changed, 81 insertions, 2 deletions
diff --git a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java index 23723386b..c4254ec8c 100644 --- a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java +++ b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java @@ -38,8 +38,13 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.onap.clamp.clds.Application; import org.onap.clamp.clds.util.JsonUtils; +import org.onap.clamp.loop.log.LogType; +import org.onap.clamp.loop.log.LoopLog; +import org.onap.clamp.loop.log.LoopLogService; import org.onap.clamp.policy.microservice.MicroServicePolicy; +import org.onap.clamp.policy.microservice.MicroservicePolicyService; import org.onap.clamp.policy.operational.OperationalPolicy; +import org.onap.clamp.policy.operational.OperationalPolicyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -57,6 +62,15 @@ public class LoopServiceTestItCase { @Autowired LoopsRepository loopsRepository; + @Autowired + MicroservicePolicyService microServicePolicyService; + + @Autowired + OperationalPolicyService operationalPolicyService; + + @Autowired + LoopLogService loopLogService; + @After public void tearDown() { loopsRepository.deleteAll(); @@ -276,6 +290,35 @@ public class LoopServiceTestItCase { assertThat(returnedGlobalProperties.getAsJsonObject()).isEqualTo(updatedGlobalProperites); } + @Test + @Transactional + public void deleteAttempt() { + saveTestLoopToDb(); + // Add log + Loop loop = loopsRepository.findById(EXAMPLE_LOOP_NAME).orElse(null); + loop.addLog(new LoopLog("test", LogType.INFO, loop)); + loop = loopService.saveOrUpdateLoop(loop); + // Add op policy + OperationalPolicy operationalPolicy = new OperationalPolicy("opPolicy", null, + JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class)); + loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(operationalPolicy)); + + // Add Micro service policy + MicroServicePolicy microServicePolicy = new MicroServicePolicy("microPolicy", "", + "tosca_definitions_version: tosca_simple_yaml_1_0_0", false, + JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null); + loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(microServicePolicy)); + + // Verify it's there + assertThat(loopsRepository.findById(EXAMPLE_LOOP_NAME).orElse(null)).isNotNull(); + loopService.deleteLoop(EXAMPLE_LOOP_NAME); + // Verify it's well deleted and has been cascaded + assertThat(loopsRepository.findById(EXAMPLE_LOOP_NAME).orElse(null)).isNull(); + assertThat(microServicePolicyService.isExisting("microPolicy")).isFalse(); + assertThat(operationalPolicyService.isExisting("opPolicy")).isFalse(); + assertThat(loopLogService.isExisting(((LoopLog) loop.getLoopLogs().toArray()[0]).getId())).isFalse(); + } + private Loop createTestLoop(String loopName, String loopBlueprint, String loopSvg) { return new Loop(loopName, loopBlueprint, loopSvg); } diff --git a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java index 0e03e1b06..dcad1a516 100644 --- a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java +++ b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java @@ -29,15 +29,18 @@ import static org.junit.Assert.assertNotNull; import com.google.gson.Gson; import com.google.gson.JsonObject; +import java.io.IOException; import java.util.HashSet; 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.log.LogType; import org.onap.clamp.loop.log.LoopLog; import org.onap.clamp.policy.microservice.MicroServicePolicy; import org.onap.clamp.policy.operational.OperationalPolicy; +import org.skyscreamer.jsonassert.JSONAssert; public class LoopToJsonTest { @@ -74,10 +77,11 @@ public class LoopToJsonTest { } @Test - public void LoopGsonTest() { + public void LoopGsonTest() throws IOException { Loop loopTest = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}", "123456789", "https://dcaetest.org", "UUID-blueprint"); - OperationalPolicy opPolicy = this.getOperationalPolicy("{\"type\":\"GUARD\"}", "GuardOpPolicyTest"); + 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", @@ -103,4 +107,20 @@ public class LoopToJsonTest { assertThat((LoopLog) loopTestDeserialized.getLoopLogs().toArray()[0]).isEqualToIgnoringGivenFields(loopLog, "loop"); } + + @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"), + loopTest.createPoliciesPayloadPdpGroup(), false); + } } diff --git a/src/test/resources/tosca/pdp-group-policy-payload.json b/src/test/resources/tosca/pdp-group-policy-payload.json new file mode 100644 index 000000000..bf941e516 --- /dev/null +++ b/src/test/resources/tosca/pdp-group-policy-payload.json @@ -0,0 +1,16 @@ +{ + "policies": [ + { + "policy-id": "GuardOpPolicyTest" + }, + { + "policy-id": "guard2" + }, + { + "policy-id": "guard1" + }, + { + "policy-id": "configPolicyTest" + } + ] +}
\ No newline at end of file |