2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia.
6 * =============================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.so.cloudify.beans;
22 import static org.assertj.core.api.Assertions.assertThat;
24 import com.google.common.collect.ImmutableMap;
25 import org.junit.Test;
26 import org.onap.so.cloudify.v3.model.Execution;
28 public class DeploymentInfoBuilderTest {
30 private static final String ERROR_MESSAGE = "something went wrong";
31 private static final String INSTALL_WORKFLOW_ID = "install";
32 private static final String UNINSTALL_WORKFLOW_ID = "uninstall";
35 public void shouldConstructDeploymentInfo_withBasicValues() {
36 DeploymentInfo deploymentInfo = new DeploymentInfoBuilder()
38 .withStatus(DeploymentStatus.CREATED)
39 .withDeploymentOutputs(ImmutableMap.of())
40 .withDeploymentInputs(ImmutableMap.of())
41 .withActionStatus("started")
42 .withLastAction(INSTALL_WORKFLOW_ID)
43 .withErrorMessage(ERROR_MESSAGE)
46 assertThat(deploymentInfo.getId()).isEqualTo("id");
47 assertThat(deploymentInfo.getStatus()).isEqualTo(DeploymentStatus.CREATED);
48 assertThat(deploymentInfo.getOutputs()).isEqualTo(ImmutableMap.of());
49 assertThat(deploymentInfo.getInputs()).isEqualTo(ImmutableMap.of());
50 assertThat(deploymentInfo.getActionStatus()).isEqualTo("started");
51 assertThat(deploymentInfo.getLastAction()).isEqualTo(INSTALL_WORKFLOW_ID);
52 assertThat(deploymentInfo.getErrorMessage()).isEqualTo(ERROR_MESSAGE);
56 public void shouldConstructDeploymentInfo_withCreateDeploymentStatus_fromNullExecution() {
57 DeploymentInfo deploymentInfo = new DeploymentInfoBuilder()
61 assertThat(deploymentInfo.getStatus()).isEqualTo(DeploymentStatus.CREATED);
65 public void shouldConstructDeploymentInfo_withInstalledDeploymentStatus_fromTerminatedExecution() {
66 String workflowIdLastAction = INSTALL_WORKFLOW_ID;
67 String status = "terminated";
68 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.INSTALLED;
69 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
73 public void shouldConstructDeploymentInfo_withFailedDeploymentStatus_fromFailedInstallExecution() {
74 String workflowIdLastAction = INSTALL_WORKFLOW_ID;
75 String status = "failed";
76 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.FAILED;
77 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
81 public void shouldConstructDeploymentInfo_withInstallingDeploymentStatus_fromStartedExecution() {
82 String workflowIdLastAction = INSTALL_WORKFLOW_ID;
83 String status = "started";
84 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.INSTALLING;
85 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
89 public void shouldConstructDeploymentInfo_withInstallingDeploymentStatus_fromPendingExecution() {
90 String workflowIdLastAction = INSTALL_WORKFLOW_ID;
91 String status = "pending";
92 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.INSTALLING;
93 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
97 public void shouldConstructDeploymentInfo_withUnknownDeploymentStatus_fromUnmappableExecution() {
98 String workflowIdLastAction = INSTALL_WORKFLOW_ID;
99 String status = "strangeStatus";
100 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNKNOWN;
101 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
105 public void shouldConstructDeploymentInfo_withCreatedDeploymentStatus_fromTerminatedExecution() {
106 String workflowIdLastAction = UNINSTALL_WORKFLOW_ID;
107 String status = "terminated";
108 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.CREATED;
109 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
113 public void shouldConstructDeploymentInfo_withFailedDeploymentStatus_fromFailedUninstallExecution() {
114 String workflowIdLastAction = UNINSTALL_WORKFLOW_ID;
115 String status = "failed";
116 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.FAILED;
117 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
121 public void shouldConstructDeploymentInfo_withUninstallingDeploymentStatus_fromStartedUninstallExecution() {
122 String workflowIdLastAction = UNINSTALL_WORKFLOW_ID;
123 String status = "started";
124 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNINSTALLING;
125 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
129 public void shouldConstructDeploymentInfo_withUninstallingDeploymentStatus_fromPendingUninstallExecution() {
130 String workflowIdLastAction = UNINSTALL_WORKFLOW_ID;
131 String status = "pending";
132 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNINSTALLING;
133 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
137 public void shouldConstructDeploymentInfo_withUnknownDeploymentStatus_fromUnmappableUninstallExecution() {
138 String workflowIdLastAction = UNINSTALL_WORKFLOW_ID;
139 String status = "strangeStatus";
140 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNKNOWN;
141 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
145 public void shouldConstructDeploymentInfo_withUnknownDeploymentStatus_forUnknownExecutionWorkflowId() {
146 String workflowIdLastAction = "strangeWorkflowIdLastAction";
147 String status = "strangeStatus";
148 DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNKNOWN;
149 verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
153 public void shouldSetEmptyOutputsMapWhenInputIsNull() {
154 DeploymentInfo deploymentInfo = new DeploymentInfoBuilder().withDeploymentOutputs(null).build();
155 assertThat(deploymentInfo.getOutputs()).isEmpty();
158 private void verifyDeploymentInfoConstruction(String workflowIdLastAction, String actionStatus,
159 DeploymentStatus expectedDeploymentStatus) {
161 Execution execution = new Execution();
162 execution.setWorkflowId(workflowIdLastAction);
163 execution.setStatus(actionStatus);
164 execution.setError(ERROR_MESSAGE);
165 DeploymentInfo deploymentInfo = new DeploymentInfoBuilder()
166 .fromExecution(execution)
169 assertThat(deploymentInfo.getLastAction()).isEqualTo(workflowIdLastAction);
170 assertThat(deploymentInfo.getActionStatus()).isEqualTo(actionStatus);
171 assertThat(deploymentInfo.getErrorMessage()).isEqualTo(ERROR_MESSAGE);
172 assertThat(deploymentInfo.getStatus()).isEqualTo(expectedDeploymentStatus);