2 * ============LICENSE_START======================================================= ONAP : SO
3 * ================================================================================ Copyright (C) 2018 Nokia.
4 * ============================================================================= Licensed under the Apache License,
5 * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
11 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 * specific language governing permissions and limitations under the License.
13 * ============LICENSE_END=========================================================
15 package org.onap.so.cloudify.beans;
17 import static org.assertj.core.api.Assertions.assertThat;
18 import com.google.common.collect.ImmutableMap;
19 import org.junit.Test;
20 import org.onap.so.cloudify.v3.model.Execution;
22 public class DeploymentInfoBuilderTest {
24 private static final String ERROR_MESSAGE = "something went wrong";
25 private static final String INSTALL_WORKFLOW_ID = "install";
26 private static final String UNINSTALL_WORKFLOW_ID = "uninstall";
29 public void shouldConstructDeploymentInfo_withBasicValues() {
30 DeploymentInfo deploymentInfo = new DeploymentInfoBuilder().withId("id").withStatus(DeploymentStatus.CREATED)
31 .withDeploymentOutputs(ImmutableMap.of()).withDeploymentInputs(ImmutableMap.of())
32 .withActionStatus("started").withLastAction(INSTALL_WORKFLOW_ID).withErrorMessage(ERROR_MESSAGE)
35 assertThat(deploymentInfo.getId()).isEqualTo("id");
36 assertThat(deploymentInfo.getStatus()).isEqualTo(DeploymentStatus.CREATED);
37 assertThat(deploymentInfo.getOutputs()).isEqualTo(ImmutableMap.of());
38 assertThat(deploymentInfo.getInputs()).isEqualTo(ImmutableMap.of());
39 assertThat(deploymentInfo.getActionStatus()).isEqualTo("started");
40 assertThat(deploymentInfo.getLastAction()).isEqualTo(INSTALL_WORKFLOW_ID);
41 assertThat(deploymentInfo.getErrorMessage()).isEqualTo(ERROR_MESSAGE);
45 public void shouldConstructDeploymentInfo_withCreateDeploymentStatus_fromNullExecution() {
46 DeploymentInfo deploymentInfo = new DeploymentInfoBuilder().fromExecution(null).build();
48 assertThat(deploymentInfo.getStatus()).isEqualTo(DeploymentStatus.CREATED);
52 public void shouldConstructDeploymentInfo_withInstalledDeploymentStatus_fromTerminatedExecution() {
53 String workflowIdLastAction = INSTALL_WORKFLOW_ID;
54 String status = "terminated";
55 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.INSTALLED;
56 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
60 public void shouldConstructDeploymentInfo_withFailedDeploymentStatus_fromFailedInstallExecution() {
61 String workflowIdLastAction = INSTALL_WORKFLOW_ID;
62 String status = "failed";
63 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.FAILED;
64 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
68 public void shouldConstructDeploymentInfo_withInstallingDeploymentStatus_fromStartedExecution() {
69 String workflowIdLastAction = INSTALL_WORKFLOW_ID;
70 String status = "started";
71 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.INSTALLING;
72 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
76 public void shouldConstructDeploymentInfo_withInstallingDeploymentStatus_fromPendingExecution() {
77 String workflowIdLastAction = INSTALL_WORKFLOW_ID;
78 String status = "pending";
79 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.INSTALLING;
80 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
84 public void shouldConstructDeploymentInfo_withUnknownDeploymentStatus_fromUnmappableExecution() {
85 String workflowIdLastAction = INSTALL_WORKFLOW_ID;
86 String status = "strangeStatus";
87 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNKNOWN;
88 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
92 public void shouldConstructDeploymentInfo_withCreatedDeploymentStatus_fromTerminatedExecution() {
93 String workflowIdLastAction = UNINSTALL_WORKFLOW_ID;
94 String status = "terminated";
95 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.CREATED;
96 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
100 public void shouldConstructDeploymentInfo_withFailedDeploymentStatus_fromFailedUninstallExecution() {
101 String workflowIdLastAction = UNINSTALL_WORKFLOW_ID;
102 String status = "failed";
103 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.FAILED;
104 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
108 public void shouldConstructDeploymentInfo_withUninstallingDeploymentStatus_fromStartedUninstallExecution() {
109 String workflowIdLastAction = UNINSTALL_WORKFLOW_ID;
110 String status = "started";
111 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNINSTALLING;
112 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
116 public void shouldConstructDeploymentInfo_withUninstallingDeploymentStatus_fromPendingUninstallExecution() {
117 String workflowIdLastAction = UNINSTALL_WORKFLOW_ID;
118 String status = "pending";
119 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNINSTALLING;
120 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
124 public void shouldConstructDeploymentInfo_withUnknownDeploymentStatus_fromUnmappableUninstallExecution() {
125 String workflowIdLastAction = UNINSTALL_WORKFLOW_ID;
126 String status = "strangeStatus";
127 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNKNOWN;
128 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
132 public void shouldConstructDeploymentInfo_withUnknownDeploymentStatus_forUnknownExecutionWorkflowId() {
133 String workflowIdLastAction = "strangeWorkflowIdLastAction";
134 String status = "strangeStatus";
135 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNKNOWN;
136 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
140 public void shouldSetEmptyOutputsMapWhenInputIsNull() {
141 DeploymentInfo deploymentInfo = new DeploymentInfoBuilder().withDeploymentOutputs(null).build();
142 assertThat(deploymentInfo.getOutputs()).isEmpty();
145 private void verifyDeploymentInfoConstruction(String workflowIdLastAction, String actionStatus,
146 DeploymentStatus expectedDeploymentStatus) {
148 Execution execution = new Execution();
149 execution.setWorkflowId(workflowIdLastAction);
150 execution.setStatus(actionStatus);
151 execution.setError(ERROR_MESSAGE);
152 DeploymentInfo deploymentInfo = new DeploymentInfoBuilder().fromExecution(execution).build();
154 assertThat(deploymentInfo.getLastAction()).isEqualTo(workflowIdLastAction);
155 assertThat(deploymentInfo.getActionStatus()).isEqualTo(actionStatus);
156 assertThat(deploymentInfo.getErrorMessage()).isEqualTo(ERROR_MESSAGE);
157 assertThat(deploymentInfo.getStatus()).isEqualTo(expectedDeploymentStatus);