testLoop.setLastComputedState(LoopState.DESIGN);
//when
- Loop actualLoop = loopService.addNewLoop(testLoop);
+ Loop actualLoop = loopService.saveOrUpdateLoop(testLoop);
//then
assertThat(actualLoop).isNotNull();
//when
Loop actualLoop = loopService
- .updateOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(operationalPolicy));
+ .updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(operationalPolicy));
//then
assertThat(actualLoop).isNotNull();
JsonObject confJson = JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class);
String policyName = "policyName";
String policyTosca = "policyTosca";
- MicroServicePolicy microServicePolicy = new MicroServicePolicy(policyName, policyTosca, false, confJson, null);
+ MicroServicePolicy microServicePolicy = new MicroServicePolicy(policyName, "", policyTosca, false, confJson, null, "");
//when
Loop actualLoop = loopService
- .updateMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(microServicePolicy));
+ .updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(microServicePolicy));
//then
assertThat(actualLoop).isNotNull();
JsonObject newJsonRepresentation = JsonUtils.GSON.fromJson("{}", JsonObject.class);
String secondPolicyName = "secondPolicyName";
String secondPolicyTosca = "secondPolicyTosca";
- MicroServicePolicy firstMicroServicePolicy = new MicroServicePolicy(firstPolicyName, "policyTosca",
- false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
- loopService.updateMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstMicroServicePolicy));
+ MicroServicePolicy firstMicroServicePolicy = new MicroServicePolicy(firstPolicyName, "", "policyTosca",
+ false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, "");
+ loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstMicroServicePolicy));
- MicroServicePolicy secondMicroServicePolicy = new MicroServicePolicy(secondPolicyName, secondPolicyTosca, true,
- newJsonRepresentation, null);
+ MicroServicePolicy secondMicroServicePolicy = new MicroServicePolicy(secondPolicyName, "", secondPolicyTosca, true,
+ newJsonRepresentation, null, "");
//when
- firstMicroServicePolicy.setJsonRepresentation(newJsonRepresentation);
- Loop actualLoop = loopService.updateMicroservicePolicies(EXAMPLE_LOOP_NAME,
+ firstMicroServicePolicy.setProperties(JsonUtils.GSON.fromJson("{\"name1\":\"value1\"}", JsonObject.class));
+ Loop actualLoop = loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME,
Lists.newArrayList(firstMicroServicePolicy, secondMicroServicePolicy));
//then
private void saveTestLoopToDb() {
Loop testLoop = createTestLoop(EXAMPLE_LOOP_NAME, "blueprint", "representation");
testLoop.setGlobalPropertiesJson(JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
- loopService.addNewLoop(testLoop);
+ loopService.saveOrUpdateLoop(testLoop);
}
@Test
String firstPolicyName = "firstPolicyName";
String secondPolicyName = "policyName";
String secondPolicyTosca = "secondPolicyTosca";
- MicroServicePolicy firstMicroServicePolicy = new MicroServicePolicy(firstPolicyName, "policyTosca",
- false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
- loopService.updateMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstMicroServicePolicy));
+ MicroServicePolicy firstMicroServicePolicy = new MicroServicePolicy(firstPolicyName, "", "policyTosca",
+ false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, "");
+ loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstMicroServicePolicy));
- MicroServicePolicy secondMicroServicePolicy = new MicroServicePolicy(secondPolicyName, secondPolicyTosca, true,
- jsonRepresentation, null);
+ MicroServicePolicy secondMicroServicePolicy = new MicroServicePolicy(secondPolicyName, "", secondPolicyTosca, true,
+ jsonRepresentation, null, "");
//when
Loop actualLoop = loopService
- .updateMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(secondMicroServicePolicy));
+ .updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(secondMicroServicePolicy));
//then
assertThat(actualLoop).isNotNull();
String secondPolicyName = "secondPolicyName";
OperationalPolicy firstOperationalPolicy = new OperationalPolicy(firstPolicyName, null,
JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
- loopService.updateOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstOperationalPolicy));
+ loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstOperationalPolicy));
OperationalPolicy secondOperationalPolicy = new OperationalPolicy(secondPolicyName, null, newJsonConfiguration);
//when
firstOperationalPolicy.setConfigurationsJson(newJsonConfiguration);
- Loop actualLoop = loopService.updateOperationalPolicies(EXAMPLE_LOOP_NAME,
+ Loop actualLoop = loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME,
Lists.newArrayList(firstOperationalPolicy, secondOperationalPolicy));
//then
String secondPolicyName = "policyName";
OperationalPolicy firstOperationalPolicy = new OperationalPolicy(firstPolicyName, null,
JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
- loopService.updateOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstOperationalPolicy));
+ loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstOperationalPolicy));
OperationalPolicy secondOperationalPolicy = new OperationalPolicy(secondPolicyName, null, jsonRepresentation);
//when
Loop actualLoop = loopService
- .updateOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(secondOperationalPolicy));
+ .updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(secondOperationalPolicy));
//then
assertThat(actualLoop).isNotNull();
}
+ @Test
+ public void shouldCreateModelPropertiesAndUpdateJsonRepresentationOfOldOne() {
+ //given
+ saveTestLoopToDb();
+ String expectedJson = "{\"test\":\"test\"}";
+ JsonObject baseGlobalProperites = JsonUtils.GSON.fromJson("{}", JsonObject.class);
+ JsonObject updatedGlobalProperites = JsonUtils.GSON.fromJson(expectedJson, JsonObject.class);
+ loopService.updateAndSaveGlobalPropertiesJson(EXAMPLE_LOOP_NAME, baseGlobalProperites);
+
+ //when
+ Loop actualLoop = loopService
+ .updateAndSaveGlobalPropertiesJson(EXAMPLE_LOOP_NAME, updatedGlobalProperites);
+
+ //then
+ assertThat(actualLoop).isNotNull();
+ assertThat(actualLoop.getName()).isEqualTo(EXAMPLE_LOOP_NAME);
+ JsonObject returnedGlobalProperties = actualLoop.getGlobalPropertiesJson();
+ assertThat(returnedGlobalProperties.getAsJsonObject()).isEqualTo(updatedGlobalProperites);
+ }
+
private Loop createTestLoop(String loopName, String loopBlueprint, String loopSvg) {
return new Loop(loopName, loopBlueprint, loopSvg);
}