summaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authorSébastien Determe <sebastien.determe@intl.att.com>2020-02-10 09:52:42 +0000
committerGerrit Code Review <gerrit@onap.org>2020-02-10 09:52:42 +0000
commitb398c32d092ca7ca14fa37d22fae6cbc1710e66e (patch)
tree06f46938dfc31e6c891b52b0658d1c091354434a /src/test/java
parent899c22fccf12f50a877988c62e30d5e2c7fb7e3c (diff)
parent81c1344c018e995e4f6f906435d0faab3480e13b (diff)
Merge "Update get Dcae Status flow"
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/clamp/loop/DcaeComponentTest.java4
-rw-r--r--src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java86
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopControllerTestItCase.java4
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java7
4 files changed, 93 insertions, 8 deletions
diff --git a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java
index 03b35f1b..fa9cc063 100644
--- a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java
+++ b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java
@@ -69,8 +69,8 @@ public class DcaeComponentTest {
@Test
public void convertDcaeResponseTest() throws IOException {
- String dcaeFakeResponse = "{'requestId':'testId','operationType':'install','status':'state','error':'errorMessage', "
- + "'links':{'self':'selfUrl','uninstall':'uninstallUrl'}}";
+ String dcaeFakeResponse = "{'requestId':'testId','operationType':'install','status':'state',"
+ + "'error':'errorMessage', 'links':{'self':'selfUrl','uninstall':'uninstallUrl'}}";
DcaeOperationStatusResponse responseObject = DcaeComponent.convertDcaeResponse(dcaeFakeResponse);
assertThat(responseObject.getRequestId()).isEqualTo("testId");
assertThat(responseObject.getOperationType()).isEqualTo("install");
diff --git a/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java b/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java
index e1cee341..c85d5a57 100644
--- a/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java
+++ b/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java
@@ -58,6 +58,9 @@ public class DeployFlowTestItCase {
@Autowired
LoopService loopService;
+ @Autowired
+ LoopsRepository loopsRepository;
+
@Test
@Transactional
public void deployWithSingleBlueprintTest() throws JsonSyntaxException, IOException {
@@ -86,8 +89,8 @@ public class DeployFlowTestItCase {
@Transactional
public void deployWithMultipleBlueprintTest() throws JsonSyntaxException, IOException {
Loop loopTest2 = createLoop("ControlLoopTest2", "<xml></xml>", "yamlcontent", "{\"dcaeDeployParameters\": {"
- + "\"microService1\": {\"location_id\": \"\", \"policy_id\": \"TCA_h2NMX_v1_0_ResourceInstanceName1_tca\"},"
- + "\"microService2\": {\"location_id\": \"\", \"policy_id\": \"TCA_h2NMX_v1_0_ResourceInstanceName2_tca\"}"
+ + "\"microService1\": {\"location_id\": \"\", \"policy_id\": \"TCA_ResourceInstanceName1_tca\"},"
+ + "\"microService2\": {\"location_id\": \"\", \"policy_id\": \"TCA_ResourceInstanceName2_tca\"}"
+ "}}", "UUID-blueprint");
LoopTemplate template = new LoopTemplate();
template.setName("templateName");
@@ -98,7 +101,7 @@ public class DeployFlowTestItCase {
"tosca_definitions_version: tosca_simple_yaml_1_0_0", "{\"param1\":\"value1\"}", true);
loopTest2.addMicroServicePolicy(microServicePolicy1);
loopTest2.addMicroServicePolicy(microServicePolicy2);
- loopService.saveOrUpdateLoop(loopTest2);
+ loopsRepository.saveAndFlush(loopTest2);
Exchange myCamelExchange = ExchangeBuilder.anExchange(camelContext).withProperty("loopObject", loopTest2)
.build();
@@ -143,8 +146,8 @@ public class DeployFlowTestItCase {
@Transactional
public void undeployWithMultipleBlueprintTest() throws JsonSyntaxException, IOException {
Loop loopTest2 = createLoop("ControlLoopTest2", "<xml></xml>", "yamlcontent", "{\"dcaeDeployParameters\": {"
- + "\"microService1\": {\"location_id\": \"\", \"policy_id\": \"TCA_h2NMX_v1_0_ResourceInstanceName1_tca\"},"
- + "\"microService2\": {\"location_id\": \"\", \"policy_id\": \"TCA_h2NMX_v1_0_ResourceInstanceName2_tca\"}"
+ + "\"microService1\": {\"location_id\": \"\", \"policy_id\": \"TCA_ResourceInstanceName1_tca\"},"
+ + "\"microService2\": {\"location_id\": \"\", \"policy_id\": \"TCA_ResourceInstanceName2_tca\"}"
+ "}}", "UUID-blueprint");
LoopTemplate template = new LoopTemplate();
template.setName("templateName");
@@ -157,7 +160,7 @@ public class DeployFlowTestItCase {
"testDeploymentId2", "testDeploymentStatusUrl2");
loopTest2.addMicroServicePolicy(microServicePolicy1);
loopTest2.addMicroServicePolicy(microServicePolicy2);
- loopService.saveOrUpdateLoop(loopTest2);
+ loopsRepository.saveAndFlush(loopTest2);
Exchange myCamelExchange = ExchangeBuilder.anExchange(camelContext).withProperty("loopObject", loopTest2)
.build();
@@ -172,6 +175,77 @@ public class DeployFlowTestItCase {
assertThat(loopAfterTest.getDcaeDeploymentId()).isNull();
}
+
+ @Test
+ @Transactional
+ public void getStatusWithSingleBlueprintTest() throws JsonSyntaxException, IOException {
+ Loop loopTest = createLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}",
+ "UUID-blueprint");
+ LoopTemplate template = new LoopTemplate();
+ template.setName("templateName");
+ template.setBlueprint("yamlcontent");
+ loopTest.setLoopTemplate(template);
+ MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "",
+ "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0",
+ "{\"param1\":\"value1\"}", true);
+ loopTest.addMicroServicePolicy(microServicePolicy);
+ loopService.saveOrUpdateLoop(loopTest);
+ assertThat(loopTest.getComponents().size()).isEqualTo(2);
+ assertThat(loopTest.getComponent("DCAE")).isNotNull();
+ assertThat(loopTest.getComponent("POLICY")).isNotNull();
+ Exchange myCamelExchange = ExchangeBuilder.anExchange(camelContext).withProperty("loopObject", loopTest)
+ .build();
+
+ camelContext.createProducerTemplate().send("direct:update-dcae-status-for-loop", myCamelExchange);
+
+ assertThat(loopTest.getComponent("DCAE").getState().getStateName()).isEqualTo("BLUEPRINT_DEPLOYED");
+
+ Loop loopAfterTest = loopService.getLoop("ControlLoopTest");
+ assertThat(loopAfterTest.getComponents().size()).isEqualTo(2);
+ assertThat(loopAfterTest.getComponent("DCAE")).isNotNull();
+ assertThat(loopAfterTest.getComponent("POLICY")).isNotNull();
+ }
+
+ @Test
+ @Transactional
+ public void getStatusWithMultipleBlueprintTest() throws JsonSyntaxException, IOException {
+ Loop loopTest = createLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}",
+ "UUID-blueprint");
+ LoopTemplate template = new LoopTemplate();
+ template.setName("templateName");
+ loopTest.setLoopTemplate(template);
+ MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "",
+ "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0",
+ "{\"param1\":\"value1\"}", true);
+ MicroServicePolicy microServicePolicy2 = getMicroServicePolicy("configPolicyTest2", "",
+ "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0",
+ "{\"param1\":\"value1\"}", true);
+ loopTest.addMicroServicePolicy(microServicePolicy);
+ loopTest.addMicroServicePolicy(microServicePolicy2);
+ loopService.saveOrUpdateLoop(loopTest);
+ assertThat(loopTest.getComponents().size()).isEqualTo(3);
+ assertThat(loopTest.getComponent("DCAE")).isNull();
+ assertThat(loopTest.getComponent("DCAE_configPolicyTest")).isNotNull();
+ assertThat(loopTest.getComponent("DCAE_configPolicyTest2")).isNotNull();
+ assertThat(loopTest.getComponent("POLICY")).isNotNull();
+ Exchange myCamelExchange = ExchangeBuilder.anExchange(camelContext).withProperty("loopObject", loopTest)
+ .build();
+
+ camelContext.createProducerTemplate().send("direct:update-dcae-status-for-loop", myCamelExchange);
+
+ assertThat(loopTest.getComponent("DCAE_configPolicyTest").getState().getStateName())
+ .isEqualTo("BLUEPRINT_DEPLOYED");
+ assertThat(loopTest.getComponent("DCAE_configPolicyTest2").getState().getStateName())
+ .isEqualTo("BLUEPRINT_DEPLOYED");
+
+ Loop loopAfterTest = loopService.getLoop("ControlLoopTest");
+ assertThat(loopAfterTest.getComponents().size()).isEqualTo(3);
+ assertThat(loopAfterTest.getComponent("DCAE")).isNull();
+ assertThat(loopAfterTest.getComponent("POLICY")).isNotNull();
+ assertThat(loopTest.getComponent("DCAE_configPolicyTest")).isNotNull();
+ assertThat(loopTest.getComponent("DCAE_configPolicyTest2")).isNotNull();
+ }
+
private Loop createLoop(String name, String svgRepresentation, String blueprint, String globalPropertiesJson,
String dcaeBlueprintId) throws JsonSyntaxException, IOException {
Loop loop = new Loop(name, svgRepresentation);
diff --git a/src/test/java/org/onap/clamp/loop/LoopControllerTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopControllerTestItCase.java
index ad37bcc8..f1e5c092 100644
--- a/src/test/java/org/onap/clamp/loop/LoopControllerTestItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopControllerTestItCase.java
@@ -39,6 +39,7 @@ 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.template.LoopTemplate;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
import org.onap.clamp.policy.microservice.MicroServicePolicyService;
import org.onap.clamp.policy.operational.OperationalPolicy;
@@ -68,6 +69,9 @@ public class LoopControllerTestItCase {
private void saveTestLoopToDb() {
Loop testLoop = createTestLoop(EXAMPLE_LOOP_NAME, "blueprint", "representation");
testLoop.setGlobalPropertiesJson(JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
+ LoopTemplate template = new LoopTemplate();
+ template.setName("testTemplate");
+ testLoop.setLoopTemplate(template);
loopService.saveOrUpdateLoop(testLoop);
}
diff --git a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
index 615826ed..8089bf1a 100644
--- a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
@@ -40,6 +40,7 @@ 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.loop.template.LoopTemplate;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
import org.onap.clamp.policy.microservice.MicroServicePolicyService;
import org.onap.clamp.policy.operational.OperationalPolicy;
@@ -175,6 +176,9 @@ public class LoopServiceTestItCase {
private void saveTestLoopToDb() {
Loop testLoop = createTestLoop(EXAMPLE_LOOP_NAME, "blueprint", "representation");
testLoop.setGlobalPropertiesJson(JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
+ LoopTemplate template = new LoopTemplate();
+ template.setName("testTemplate");
+ testLoop.setLoopTemplate(template);
loopService.saveOrUpdateLoop(testLoop);
}
@@ -296,6 +300,9 @@ public class LoopServiceTestItCase {
// Add log
Loop loop = loopsRepository.findById(EXAMPLE_LOOP_NAME).orElse(null);
loop.addLog(new LoopLog("test", LogType.INFO, "CLAMP", loop));
+ LoopTemplate template = new LoopTemplate();
+ template.setName("testTemplate");
+ loop.setLoopTemplate(template);
loop = loopService.saveOrUpdateLoop(loop);
// Add op policy
OperationalPolicy operationalPolicy = new OperationalPolicy("opPolicy", null,