From cef5b582ed8f2f9a64203e737234e29434314b36 Mon Sep 17 00:00:00 2001 From: sebdet Date: Tue, 21 Jan 2020 12:40:59 +0100 Subject: Modify the template model Add loopElement to loopTemplate so that operational policy can be added into the template as well Issue-ID: CLAMP-555 Change-Id: I298c05f7f92536e4dab840983c41b0f7ee22daac Signed-off-by: sebdet --- .../tosca/DictionaryRepositoriesTestItCase.java | 3 +- .../org/onap/clamp/loop/DcaeComponentTest.java | 2 +- .../onap/clamp/loop/LoopRepositoriesItCase.java | 57 +++++++++++----------- .../org/onap/clamp/loop/LoopServiceTestItCase.java | 14 ++++-- .../java/org/onap/clamp/loop/LoopToJsonTest.java | 15 +++--- .../onap/clamp/loop/PolicyModelServiceItCase.java | 2 - .../microservice/MicroServicePayloadTest.java | 2 +- 7 files changed, 51 insertions(+), 44 deletions(-) (limited to 'src/test/java/org/onap') diff --git a/src/test/java/org/onap/clamp/clds/tosca/DictionaryRepositoriesTestItCase.java b/src/test/java/org/onap/clamp/clds/tosca/DictionaryRepositoriesTestItCase.java index 7f5b6901..2274fcf6 100644 --- a/src/test/java/org/onap/clamp/clds/tosca/DictionaryRepositoriesTestItCase.java +++ b/src/test/java/org/onap/clamp/clds/tosca/DictionaryRepositoriesTestItCase.java @@ -20,6 +20,7 @@ * =================================================================== * */ + package org.onap.clamp.clds.tosca; import static org.assertj.core.api.Assertions.assertThat; @@ -60,7 +61,7 @@ public class DictionaryRepositoriesTestItCase { element1.setSubDictionary("subDictionary1"); element1.setType("type1"); element1.setDescription("description1"); - + LinkedList elementList1 = new LinkedList(); elementList1.add(element1); dictionaryTest1.setDictionaryElements(elementList1); diff --git a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java index 557fdcec..96921514 100644 --- a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java +++ b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java @@ -57,7 +57,7 @@ public class DcaeComponentTest { MicroServicePolicy microServicePolicy = new MicroServicePolicy("configPolicyTest", "", "tosca_definitions_version: tosca_simple_yaml_1_0_0", true, new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), new HashSet<>()); - microServicePolicy.setProperties(new Gson().fromJson("{\"param1\":\"value1\"}", JsonObject.class)); + microServicePolicy.setConfigurationsJson(new Gson().fromJson("{\"param1\":\"value1\"}", JsonObject.class)); loopTest.addMicroServicePolicy(microServicePolicy); return loopTest; diff --git a/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java b/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java index 44feaebd..e0c112cb 100644 --- a/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java +++ b/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java @@ -42,10 +42,10 @@ import org.onap.clamp.loop.log.LoopLog; import org.onap.clamp.loop.log.LoopLogRepository; import org.onap.clamp.loop.service.Service; import org.onap.clamp.loop.service.ServicesRepository; +import org.onap.clamp.loop.template.LoopElementModel; +import org.onap.clamp.loop.template.LoopElementModelsRepository; import org.onap.clamp.loop.template.LoopTemplate; import org.onap.clamp.loop.template.LoopTemplatesRepository; -import org.onap.clamp.loop.template.MicroServiceModel; -import org.onap.clamp.loop.template.MicroServiceModelsRepository; import org.onap.clamp.loop.template.PolicyModel; import org.onap.clamp.loop.template.PolicyModelId; import org.onap.clamp.loop.template.PolicyModelsRepository; @@ -80,7 +80,7 @@ public class LoopRepositoriesItCase { private LoopTemplatesRepository loopTemplateRepository; @Autowired - private MicroServiceModelsRepository microServiceModelsRepository; + private LoopElementModelsRepository microServiceModelsRepository; @Autowired private PolicyModelsRepository policyModelsRepository; @@ -96,21 +96,22 @@ public class LoopRepositoriesItCase { return new OperationalPolicy(name, null, new Gson().fromJson(configJson, JsonObject.class)); } - private MicroServiceModel getMicroServiceModel(String yaml, String name, String policyType, String createdBy, + private LoopElementModel getLoopElementModel(String yaml, String name, String policyType, String createdBy, PolicyModel policyModel) { - MicroServiceModel model = new MicroServiceModel(name, policyType, yaml, 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) { - return new PolicyModel(policyType, policyModelTosca, version, policyAcronym, policyVariant); + return new PolicyModel(policyType, policyModelTosca, version, policyAcronym); } private LoopTemplate getLoopTemplate(String name, String blueprint, String svgRepresentation, String createdBy, Integer maxInstancesAllowed) { LoopTemplate template = new LoopTemplate(name, blueprint, svgRepresentation, maxInstancesAllowed, null); - template.addMicroServiceModel(getMicroServiceModel("yaml", "microService1", "org.onap.policy.drools", createdBy, + template.addLoopElementModel(getLoopElementModel("yaml", "microService1", "org.onap.policy.drools", createdBy, getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools", "type1", createdBy))); return template; } @@ -134,7 +135,7 @@ public class LoopRepositoriesItCase { String policyTosca, String jsonProperties, boolean shared) { MicroServicePolicy microService = new MicroServicePolicy(name, modelType, policyTosca, shared, gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>()); - microService.setProperties(new Gson().fromJson(jsonProperties, JsonObject.class)); + microService.setConfigurationsJson(new Gson().fromJson(jsonProperties, JsonObject.class)); return microService; } @@ -182,13 +183,13 @@ public class LoopRepositoriesItCase { assertThat(loopTemplateRepository.existsById(loopInDb.getLoopTemplate().getName())).isEqualTo(true); assertThat(servicesRepository.existsById(loopInDb.getModelService().getServiceUuid())).isEqualTo(true); assertThat(microServiceModelsRepository.existsById( - loopInDb.getLoopTemplate().getMicroServiceModelUsed().first().getMicroServiceModel().getName())) + loopInDb.getLoopTemplate().getLoopElementModelsUsed().first().getLoopElementModel().getName())) .isEqualTo(true); assertThat(policyModelsRepository.existsById(new PolicyModelId( - loopInDb.getLoopTemplate().getMicroServiceModelUsed().first().getMicroServiceModel().getPolicyModel() - .getPolicyModelType(), - loopInDb.getLoopTemplate().getMicroServiceModelUsed().first().getMicroServiceModel().getPolicyModel() - .getVersion()))).isEqualTo(true); + loopInDb.getLoopTemplate().getLoopElementModelsUsed().first().getLoopElementModel().getPolicyModels() + .first().getPolicyModelType(), + loopInDb.getLoopTemplate().getLoopElementModelsUsed().first().getLoopElementModel().getPolicyModels() + .first().getVersion()))).isEqualTo(true); // Now attempt to read from database Loop loopInDbRetrieved = loopRepository.findById(loopTest.getName()).get(); @@ -198,7 +199,16 @@ public class LoopRepositoriesItCase { "createdBy", "updatedBy"); assertThat((LoopLog) loopInDbRetrieved.getLoopLogs().toArray()[0]).isEqualToComparingFieldByField(loopLog); assertThat((OperationalPolicy) loopInDbRetrieved.getOperationalPolicies().toArray()[0]) - .isEqualToComparingFieldByField(opPolicy); + .isEqualToIgnoringGivenFields(opPolicy, "createdDate", "updatedDate", "createdBy", "updatedBy"); + assertThat(((OperationalPolicy) loopInDbRetrieved.getOperationalPolicies().toArray()[0]).getCreatedDate()) + .isNotNull(); + assertThat(((OperationalPolicy) loopInDbRetrieved.getOperationalPolicies().toArray()[0]).getUpdatedDate()) + .isNotNull(); + assertThat(((OperationalPolicy) loopInDbRetrieved.getOperationalPolicies().toArray()[0]).getCreatedBy()) + .isNotNull(); + assertThat(((OperationalPolicy) loopInDbRetrieved.getOperationalPolicies().toArray()[0]).getUpdatedBy()) + .isNotNull(); + assertThat((MicroServicePolicy) loopInDbRetrieved.getMicroServicePolicies().toArray()[0]) .isEqualToIgnoringGivenFields(microServicePolicy, "createdDate", "updatedDate", "createdBy", "updatedBy"); @@ -230,23 +240,14 @@ public class LoopRepositoriesItCase { assertThat(loopTemplateRepository.existsById(loopInDb.getLoopTemplate().getName())).isEqualTo(true); assertThat(servicesRepository.existsById(loopInDb.getModelService().getServiceUuid())).isEqualTo(true); assertThat(microServiceModelsRepository.existsById( - loopInDb.getLoopTemplate().getMicroServiceModelUsed().first().getMicroServiceModel().getName())) + loopInDb.getLoopTemplate().getLoopElementModelsUsed().first().getLoopElementModel().getName())) .isEqualTo(true); assertThat(policyModelsRepository.existsById(new PolicyModelId( - loopInDb.getLoopTemplate().getMicroServiceModelUsed().first().getMicroServiceModel().getPolicyModel() - .getPolicyModelType(), - loopInDb.getLoopTemplate().getMicroServiceModelUsed().first().getMicroServiceModel().getPolicyModel() - .getVersion()))).isEqualTo(true); - - // Cleanup - // microServiceModelsRepository - // .delete(loopInDb.getLoopTemplate().getMicroServiceModelUsed().first().getMicroServiceModel()); - // - // policyModelsRepository.delete( - // loopInDb.getLoopTemplate().getMicroServiceModelUsed().first().getMicroServiceModel().getPolicyModel()); - // loopTemplateRepository.delete(loopInDb.getLoopTemplate()); - // servicesRepository.delete(service); + loopInDb.getLoopTemplate().getLoopElementModelsUsed().first().getLoopElementModel().getPolicyModels() + .first().getPolicyModelType(), + loopInDb.getLoopTemplate().getLoopElementModelsUsed().first().getLoopElementModel().getPolicyModels() + .first().getVersion()))).isEqualTo(true); } } diff --git a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java index d19c8a80..338aaa3e 100644 --- a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java +++ b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java @@ -110,7 +110,9 @@ public class LoopServiceTestItCase { assertThat(actualLoop.getName()).isEqualTo(EXAMPLE_LOOP_NAME); Set savedPolicies = actualLoop.getOperationalPolicies(); assertThat(savedPolicies).hasSize(1); - assertThat(savedPolicies).usingElementComparatorIgnoringFields("loop").contains(operationalPolicy); + assertThat(savedPolicies) + .usingElementComparatorIgnoringFields("loop", "createdBy", "createdDate", "updatedBy", "updatedDate") + .contains(operationalPolicy); OperationalPolicy savedPolicy = savedPolicies.iterator().next(); assertThat(savedPolicy.getLoop().getName()).isEqualTo(EXAMPLE_LOOP_NAME); @@ -154,7 +156,8 @@ public class LoopServiceTestItCase { JsonUtils.GSON.fromJson("{}", JsonObject.class), null); // when - firstMicroServicePolicy.setProperties(JsonUtils.GSON.fromJson("{\"name1\":\"value1\"}", JsonObject.class)); + firstMicroServicePolicy + .setConfigurationsJson(JsonUtils.GSON.fromJson("{\"name1\":\"value1\"}", JsonObject.class)); Loop actualLoop = loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstMicroServicePolicy, secondMicroServicePolicy)); @@ -229,7 +232,8 @@ public class LoopServiceTestItCase { assertThat(actualLoop.getName()).isEqualTo(EXAMPLE_LOOP_NAME); Set savedPolicies = actualLoop.getOperationalPolicies(); assertThat(savedPolicies).hasSize(2); - assertThat(savedPolicies).usingElementComparatorIgnoringFields("loop") + assertThat(savedPolicies) + .usingElementComparatorIgnoringFields("loop", "createdDate", "updatedDate", "createdBy", "updatedBy") .containsExactlyInAnyOrder(firstOperationalPolicy, secondOperationalPolicy); Set policiesLoops = Lists.newArrayList(savedPolicies).stream().map(OperationalPolicy::getLoop) .map(Loop::getName).collect(Collectors.toSet()); @@ -258,7 +262,9 @@ public class LoopServiceTestItCase { assertThat(actualLoop.getName()).isEqualTo(EXAMPLE_LOOP_NAME); Set savedPolicies = actualLoop.getOperationalPolicies(); assertThat(savedPolicies).hasSize(1); - assertThat(savedPolicies).usingElementComparatorIgnoringFields("loop").containsExactly(secondOperationalPolicy); + assertThat(savedPolicies) + .usingElementComparatorIgnoringFields("loop", "createdDate", "updatedDate", "createdBy", "updatedBy") + .containsExactly(secondOperationalPolicy); OperationalPolicy savedPolicy = savedPolicies.iterator().next(); assertThat(savedPolicy.getLoop().getName()).isEqualTo(EXAMPLE_LOOP_NAME); diff --git a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java index 914c64ea..af8f2271 100644 --- a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java +++ b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java @@ -44,8 +44,8 @@ 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; +import org.onap.clamp.loop.template.LoopElementModel; import org.onap.clamp.loop.template.LoopTemplate; -import org.onap.clamp.loop.template.MicroServiceModel; import org.onap.clamp.loop.template.PolicyModel; import org.onap.clamp.policy.microservice.MicroServicePolicy; import org.onap.clamp.policy.operational.OperationalPolicy; @@ -74,27 +74,28 @@ public class LoopToJsonTest { String policyTosca, String jsonProperties, boolean shared) { MicroServicePolicy microService = new MicroServicePolicy(name, modelType, policyTosca, shared, gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>()); - microService.setProperties(new Gson().fromJson(jsonProperties, JsonObject.class)); + microService.setConfigurationsJson(new Gson().fromJson(jsonProperties, JsonObject.class)); return microService; } - private MicroServiceModel getMicroServiceModel(String yaml, String name, PolicyModel policyModel) { - MicroServiceModel model = new MicroServiceModel(); + private LoopElementModel getLoopElementModel(String yaml, String name, PolicyModel policyModel) { + LoopElementModel model = new LoopElementModel(); model.setBlueprint(yaml); model.setName(name); - model.setPolicyModel(policyModel); + model.addPolicyModel(policyModel); + model.setLoopElementType("OPERATIONAL_POLICY"); return model; } private PolicyModel getPolicyModel(String policyType, String policyModelTosca, String version, String policyAcronym, String policyVariant) { - return new PolicyModel(policyType, policyModelTosca, version, policyAcronym, policyVariant); + return new PolicyModel(policyType, policyModelTosca, version, policyAcronym); } private LoopTemplate getLoopTemplate(String name, String blueprint, String svgRepresentation, Integer maxInstancesAllowed) { LoopTemplate template = new LoopTemplate(name, blueprint, svgRepresentation, maxInstancesAllowed, null); - template.addMicroServiceModel(getMicroServiceModel("yaml", "microService1", + template.addLoopElementModel(getLoopElementModel("yaml", "microService1", getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools", "type1"))); return template; } diff --git a/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java b/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java index b284dd79..39468a1c 100644 --- a/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java +++ b/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java @@ -66,7 +66,6 @@ public class PolicyModelServiceItCase { policyModel.setPolicyAcronym(policyAcronym); policyModel.setPolicyModelTosca(policyModelTosca); policyModel.setPolicyModelType(policyType); - policyModel.setPolicyVariant(policyVariant); policyModel.setUpdatedBy(createdBy); policyModel.setVersion(version); return policyModel; @@ -92,7 +91,6 @@ public class PolicyModelServiceItCase { assertThat(actualPolicyModel.getCreatedDate()).isNotNull(); assertThat(actualPolicyModel.getPolicyAcronym()).isEqualTo(policyModel.getPolicyAcronym()); assertThat(actualPolicyModel.getPolicyModelTosca()).isEqualTo(policyModel.getPolicyModelTosca()); - assertThat(actualPolicyModel.getPolicyVariant()).isEqualTo(policyModel.getPolicyVariant()); assertThat(actualPolicyModel.getUpdatedBy()).isEqualTo(""); assertThat(actualPolicyModel.getUpdatedDate()).isNotNull(); assertThat(actualPolicyModel.getVersion()).isEqualTo(policyModel.getVersion()); diff --git a/src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java b/src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java index 68925a91..1556ac6d 100644 --- a/src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java +++ b/src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java @@ -39,7 +39,7 @@ public class MicroServicePayloadTest { public void testPayloadConstruction() throws IOException { MicroServicePolicy policy = new MicroServicePolicy("testPolicy", "onap.policies.monitoring.cdap.tca.hi.lo.app", ResourceFileUtil.getResourceAsString("tosca/tosca_example.yaml"), false, new HashSet<>()); - policy.setProperties(JsonUtils.GSON.fromJson( + policy.setConfigurationsJson(JsonUtils.GSON.fromJson( ResourceFileUtil.getResourceAsString("tosca/micro-service-policy-properties.json"), JsonObject.class)); JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/micro-service-policy-payload.json"), policy.createPolicyPayload(), false); -- cgit 1.2.3-korg