X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Fclamp%2Floop%2FLoopRepositoriesItCase.java;h=e6c477b44a57937fbdbb9b35239667b37ecb7f1c;hb=4e8e11afced0693e24074fd6bb8d5b2cace98ab6;hp=62b25605e2bc335eca79b124e22bb097b17cd51f;hpb=3b7f669088d5867056578b275bf4314af3a439c6;p=clamp.git diff --git a/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java b/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java index 62b25605..e6c477b4 100644 --- a/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java +++ b/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java @@ -30,10 +30,8 @@ import static org.assertj.core.api.Assertions.assertThat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; - import java.time.Instant; import java.util.HashSet; - import org.junit.Test; import org.junit.runner.RunWith; import org.onap.clamp.clds.Application; @@ -92,32 +90,33 @@ public class LoopRepositoriesItCase { return new Service(serviceDetails, resourceDetails); } - private OperationalPolicy getOperationalPolicy(String configJson, String name) { - return new OperationalPolicy(name, null, new Gson().fromJson(configJson, JsonObject.class)); + private OperationalPolicy getOperationalPolicy(String configJson, String name, PolicyModel policyModel) { + return new OperationalPolicy(name, null, new Gson().fromJson(configJson, JsonObject.class), policyModel); } private LoopElementModel getLoopElementModel(String yaml, String name, String policyType, String createdBy, - PolicyModel policyModel) { + PolicyModel policyModel) { LoopElementModel model = new LoopElementModel(name, policyType, yaml); model.addPolicyModel(policyModel); return model; } - private PolicyModel getPolicyModel(String policyType, String policyModelTosca, String version, String policyAcronym, - String policyVariant, String createdBy) { + private PolicyModel getPolicyModel(String policyType, String policyModelTosca, String version, + String policyAcronym) { return new PolicyModel(policyType, policyModelTosca, version, policyAcronym); } private LoopTemplate getLoopTemplate(String name, String blueprint, String svgRepresentation, String createdBy, - Integer maxInstancesAllowed) { + Integer maxInstancesAllowed) { LoopTemplate template = new LoopTemplate(name, blueprint, svgRepresentation, maxInstancesAllowed, null); template.addLoopElementModel(getLoopElementModel("yaml", "microService1", "org.onap.policy.drools", createdBy, - getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools", "type1", createdBy))); + getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools"))); + loopTemplateRepository.save(template); return template; } private Loop getLoop(String name, String svgRepresentation, String blueprint, String globalPropertiesJson, - String dcaeId, String dcaeUrl, String dcaeBlueprintId) { + String dcaeId, String dcaeUrl, String dcaeBlueprintId) { Loop loop = new Loop(); loop.setName(name); loop.setSvgRepresentation(svgRepresentation); @@ -129,9 +128,9 @@ public class LoopRepositoriesItCase { return loop; } - private MicroServicePolicy getMicroServicePolicy(String name, String modelType, String jsonRepresentation, - String policyTosca, String jsonProperties, boolean shared) { - MicroServicePolicy microService = new MicroServicePolicy(name, modelType, policyTosca, shared, + private MicroServicePolicy getMicroServicePolicy(String name, String jsonRepresentation, String jsonProperties, + boolean shared, PolicyModel policyModel) { + MicroServicePolicy microService = new MicroServicePolicy(name, policyModel, shared, gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>()); microService.setConfigurationsJson(new Gson().fromJson(jsonProperties, JsonObject.class)); return microService; @@ -141,17 +140,20 @@ public class LoopRepositoriesItCase { return new LoopLog(message, type, "CLAMP", loop); } + /** + * This method does a crud test and save a loop template and a loop object in db. + */ @Test @Transactional public void crudTest() { // Setup Loop loopTest = getLoop("ControlLoopTest", "", "yamlcontent", "{\"testname\":\"testvalue\"}", "123456789", "https://dcaetest.org", "UUID-blueprint"); - OperationalPolicy opPolicy = this.getOperationalPolicy("{\"type\":\"GUARD\"}", "GuardOpPolicyTest"); + OperationalPolicy opPolicy = this.getOperationalPolicy("{\"type\":\"GUARD\"}", "GuardOpPolicyTest", + getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools")); loopTest.addOperationalPolicy(opPolicy); - MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "", - "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0", - "{\"param1\":\"value1\"}", true); + MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "{\"configtype\":\"json\"}", + "{\"param1\":\"value1\"}", true, getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools")); loopTest.addMicroServicePolicy(microServicePolicy); LoopLog loopLog = getLoopLog(LogType.INFO, "test message", loopTest); loopTest.addLog(loopLog); @@ -182,7 +184,7 @@ public class LoopRepositoriesItCase { assertThat(servicesRepository.existsById(loopInDb.getModelService().getServiceUuid())).isEqualTo(true); assertThat(microServiceModelsRepository.existsById( loopInDb.getLoopTemplate().getLoopElementModelsUsed().first().getLoopElementModel().getName())) - .isEqualTo(true); + .isEqualTo(true); assertThat(policyModelsRepository.existsById(new PolicyModelId( loopInDb.getLoopTemplate().getLoopElementModelsUsed().first().getLoopElementModel().getPolicyModels() .first().getPolicyModelType(), @@ -238,7 +240,7 @@ public class LoopRepositoriesItCase { assertThat(servicesRepository.existsById(loopInDb.getModelService().getServiceUuid())).isEqualTo(true); assertThat(microServiceModelsRepository.existsById( loopInDb.getLoopTemplate().getLoopElementModelsUsed().first().getLoopElementModel().getName())) - .isEqualTo(true); + .isEqualTo(true); assertThat(policyModelsRepository.existsById(new PolicyModelId( loopInDb.getLoopTemplate().getLoopElementModelsUsed().first().getLoopElementModel().getPolicyModels()