aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java')
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java84
1 files changed, 39 insertions, 45 deletions
diff --git a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
index 28a92e37..d19c8a80 100644
--- a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
@@ -33,7 +33,6 @@ import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.assertj.core.util.Lists;
-import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.clamp.clds.Application;
@@ -42,7 +41,7 @@ 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.microservice.MicroServicePolicyService;
import org.onap.clamp.policy.operational.OperationalPolicy;
import org.onap.clamp.policy.operational.OperationalPolicyService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -63,7 +62,7 @@ public class LoopServiceTestItCase {
LoopsRepository loopsRepository;
@Autowired
- MicroservicePolicyService microServicePolicyService;
+ MicroServicePolicyService microServicePolicyService;
@Autowired
OperationalPolicyService operationalPolicyService;
@@ -71,11 +70,6 @@ public class LoopServiceTestItCase {
@Autowired
LoopLogService loopLogService;
- @After
- public void tearDown() {
- loopsRepository.deleteAll();
- }
-
@Test
@Transactional
public void shouldCreateEmptyLoop() {
@@ -96,7 +90,7 @@ public class LoopServiceTestItCase {
assertThat(actualLoop.getBlueprint()).isEqualTo(loopBlueprint);
assertThat(actualLoop.getSvgRepresentation()).isEqualTo(loopSvg);
assertThat(actualLoop.getGlobalPropertiesJson().getAsJsonPrimitive("testName").getAsString())
- .isEqualTo("testValue");
+ .isEqualTo("testValue");
}
@Test
@@ -105,11 +99,11 @@ public class LoopServiceTestItCase {
// given
saveTestLoopToDb();
OperationalPolicy operationalPolicy = new OperationalPolicy("policyName", null,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
// when
Loop actualLoop = loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME,
- Lists.newArrayList(operationalPolicy));
+ Lists.newArrayList(operationalPolicy));
// then
assertThat(actualLoop).isNotNull();
@@ -128,20 +122,20 @@ public class LoopServiceTestItCase {
// given
saveTestLoopToDb();
MicroServicePolicy microServicePolicy = new MicroServicePolicy("policyName", "",
- "tosca_definitions_version: tosca_simple_yaml_1_0_0", false,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ "tosca_definitions_version: tosca_simple_yaml_1_0_0", false,
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
// when
Loop actualLoop = loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME,
- Lists.newArrayList(microServicePolicy));
+ Lists.newArrayList(microServicePolicy));
// then
assertThat(actualLoop).isNotNull();
assertThat(actualLoop.getName()).isEqualTo(EXAMPLE_LOOP_NAME);
Set<MicroServicePolicy> savedPolicies = actualLoop.getMicroServicePolicies();
assertThat(savedPolicies).hasSize(1);
- assertThat(savedPolicies).usingElementComparatorIgnoringFields("usedByLoops")
- .containsExactly(microServicePolicy);
+ assertThat(savedPolicies).usingElementComparatorIgnoringFields("usedByLoops", "createdDate", "updatedDate",
+ "createdBy", "updatedBy").containsExactly(microServicePolicy);
assertThat(savedPolicies).extracting("usedByLoops").hasSize(1);
}
@@ -153,16 +147,16 @@ public class LoopServiceTestItCase {
saveTestLoopToDb();
MicroServicePolicy firstMicroServicePolicy = new MicroServicePolicy("firstPolicyName", "", "", false,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstMicroServicePolicy));
MicroServicePolicy secondMicroServicePolicy = new MicroServicePolicy("secondPolicyName", "",
- "tosca_definitions_version: tosca_simple_yaml_1_0_0", true, JsonUtils.GSON.fromJson("{}", JsonObject.class),
- null);
+ "tosca_definitions_version: tosca_simple_yaml_1_0_0", true,
+ JsonUtils.GSON.fromJson("{}", JsonObject.class), null);
// when
firstMicroServicePolicy.setProperties(JsonUtils.GSON.fromJson("{\"name1\":\"value1\"}", JsonObject.class));
Loop actualLoop = loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME,
- Lists.newArrayList(firstMicroServicePolicy, secondMicroServicePolicy));
+ Lists.newArrayList(firstMicroServicePolicy, secondMicroServicePolicy));
// then
assertThat(actualLoop).isNotNull();
@@ -171,8 +165,8 @@ public class LoopServiceTestItCase {
assertThat(savedPolicies).hasSize(2);
assertThat(savedPolicies).contains(firstMicroServicePolicy);
assertThat(savedPolicies).contains(secondMicroServicePolicy);
- assertThat(savedPolicies).usingElementComparatorIgnoringFields("usedByLoops")
- .containsExactlyInAnyOrder(firstMicroServicePolicy, secondMicroServicePolicy);
+ assertThat(savedPolicies).usingElementComparatorIgnoringFields("usedByLoops", "createdDate", "updatedDate",
+ "createdBy", "updatedBy").containsExactlyInAnyOrder(firstMicroServicePolicy, secondMicroServicePolicy);
}
@@ -189,24 +183,24 @@ public class LoopServiceTestItCase {
saveTestLoopToDb();
MicroServicePolicy firstMicroServicePolicy = new MicroServicePolicy("firstPolicyName", "",
- "\"tosca_definitions_version: tosca_simple_yaml_1_0_0\"", false,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ "\"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(firstMicroServicePolicy));
MicroServicePolicy secondMicroServicePolicy = new MicroServicePolicy("policyName", "", "secondPolicyTosca",
- true, JsonUtils.GSON.fromJson("{}", JsonObject.class), null);
+ true, JsonUtils.GSON.fromJson("{}", JsonObject.class), null);
// when
Loop actualLoop = loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME,
- Lists.newArrayList(secondMicroServicePolicy));
+ Lists.newArrayList(secondMicroServicePolicy));
// then
assertThat(actualLoop).isNotNull();
assertThat(actualLoop.getName()).isEqualTo(EXAMPLE_LOOP_NAME);
Set<MicroServicePolicy> savedPolicies = actualLoop.getMicroServicePolicies();
assertThat(savedPolicies).hasSize(1);
- assertThat(savedPolicies).usingElementComparatorIgnoringFields("usedByLoops")
- .containsExactly(secondMicroServicePolicy);
+ assertThat(savedPolicies).usingElementComparatorIgnoringFields("usedByLoops", "createdDate", "updatedDate",
+ "createdBy", "updatedBy").containsExactly(secondMicroServicePolicy);
}
@@ -219,16 +213,16 @@ public class LoopServiceTestItCase {
JsonObject newJsonConfiguration = JsonUtils.GSON.fromJson("{}", JsonObject.class);
OperationalPolicy firstOperationalPolicy = new OperationalPolicy("firstPolicyName", null,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstOperationalPolicy));
OperationalPolicy secondOperationalPolicy = new OperationalPolicy("secondPolicyName", null,
- newJsonConfiguration);
+ newJsonConfiguration);
// when
firstOperationalPolicy.setConfigurationsJson(newJsonConfiguration);
Loop actualLoop = loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME,
- Lists.newArrayList(firstOperationalPolicy, secondOperationalPolicy));
+ Lists.newArrayList(firstOperationalPolicy, secondOperationalPolicy));
// then
assertThat(actualLoop).isNotNull();
@@ -236,9 +230,9 @@ public class LoopServiceTestItCase {
Set<OperationalPolicy> savedPolicies = actualLoop.getOperationalPolicies();
assertThat(savedPolicies).hasSize(2);
assertThat(savedPolicies).usingElementComparatorIgnoringFields("loop")
- .containsExactlyInAnyOrder(firstOperationalPolicy, secondOperationalPolicy);
+ .containsExactlyInAnyOrder(firstOperationalPolicy, secondOperationalPolicy);
Set<String> policiesLoops = Lists.newArrayList(savedPolicies).stream().map(OperationalPolicy::getLoop)
- .map(Loop::getName).collect(Collectors.toSet());
+ .map(Loop::getName).collect(Collectors.toSet());
assertThat(policiesLoops).containsExactly(EXAMPLE_LOOP_NAME);
}
@@ -249,15 +243,15 @@ public class LoopServiceTestItCase {
saveTestLoopToDb();
OperationalPolicy firstOperationalPolicy = new OperationalPolicy("firstPolicyName", null,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstOperationalPolicy));
OperationalPolicy secondOperationalPolicy = new OperationalPolicy("policyName", null,
- JsonUtils.GSON.fromJson("{}", JsonObject.class));
+ JsonUtils.GSON.fromJson("{}", JsonObject.class));
// when
Loop actualLoop = loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME,
- Lists.newArrayList(secondOperationalPolicy));
+ Lists.newArrayList(secondOperationalPolicy));
// then
assertThat(actualLoop).isNotNull();
@@ -300,21 +294,21 @@ public class LoopServiceTestItCase {
loop = loopService.saveOrUpdateLoop(loop);
// Add op policy
OperationalPolicy operationalPolicy = new OperationalPolicy("opPolicy", null,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
+ 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);
+ "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
+ // Verify it's well deleted and has been cascaded, except for Microservice
assertThat(loopsRepository.findById(EXAMPLE_LOOP_NAME).orElse(null)).isNull();
- assertThat(microServicePolicyService.isExisting("microPolicy")).isFalse();
+ assertThat(microServicePolicyService.isExisting("microPolicy")).isTrue();
assertThat(operationalPolicyService.isExisting("opPolicy")).isFalse();
assertThat(loopLogService.isExisting(((LoopLog) loop.getLoopLogs().toArray()[0]).getId())).isFalse();
}
@@ -334,8 +328,8 @@ public class LoopServiceTestItCase {
public void testUpdateDcaeDeploymentFields() {
saveTestLoopToDb();
Loop loop = loopService.getLoop(EXAMPLE_LOOP_NAME);
- loopService.updateDcaeDeploymentFields(loop,"CLAMP_c5ce429a-f570-48c5-a7ea-53bed8f86f85",
- "https4://deployment-handler.onap:8443");
+ loopService.updateDcaeDeploymentFields(loop, "CLAMP_c5ce429a-f570-48c5-a7ea-53bed8f86f85",
+ "https4://deployment-handler.onap:8443");
loop = loopService.getLoop(EXAMPLE_LOOP_NAME);
assertThat(loop.getDcaeDeploymentId()).isEqualTo("CLAMP_c5ce429a-f570-48c5-a7ea-53bed8f86f85");
assertThat(loop.getDcaeDeploymentStatusUrl()).isEqualTo("https4://deployment-handler.onap:8443");
@@ -347,8 +341,8 @@ public class LoopServiceTestItCase {
saveTestLoopToDb();
assertThat(microServicePolicyService.isExisting("policyName")).isFalse();
MicroServicePolicy microServicePolicy = new MicroServicePolicy("policyName", "",
- "tosca_definitions_version: tosca_simple_yaml_1_0_0", false,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ "tosca_definitions_version: tosca_simple_yaml_1_0_0", false,
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
loopService.updateMicroservicePolicy(EXAMPLE_LOOP_NAME, microServicePolicy);
assertThat(microServicePolicyService.isExisting("policyName")).isTrue();
}