Replaced all tabs with spaces in java and pom.xml
[so.git] / adapters / mso-adapter-utils / src / test / java / org / onap / so / cloudify / beans / DeploymentInfoBuilderTest.java
1 /*
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
6  * of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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=========================================================
14  */
15 package org.onap.so.cloudify.beans;
16
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;
21
22 public class DeploymentInfoBuilderTest {
23
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";
27
28     @Test
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)
33                 .build();
34
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);
42     }
43
44     @Test
45     public void shouldConstructDeploymentInfo_withCreateDeploymentStatus_fromNullExecution() {
46         DeploymentInfo deploymentInfo = new DeploymentInfoBuilder().fromExecution(null).build();
47
48         assertThat(deploymentInfo.getStatus()).isEqualTo(DeploymentStatus.CREATED);
49     }
50
51     @Test
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);
57     }
58
59     @Test
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);
65     }
66
67     @Test
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);
73     }
74
75     @Test
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);
81     }
82
83     @Test
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);
89     }
90
91     @Test
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);
97     }
98
99     @Test
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);
105     }
106
107     @Test
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);
113     }
114
115     @Test
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);
121     }
122
123     @Test
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);
129     }
130
131     @Test
132     public void shouldConstructDeploymentInfo_withUnknownDeploymentStatus_forUnknownExecutionWorkflowId() {
133         String workflowIdLastAction = "strangeWorkflowIdLastAction";
134         String status = "strangeStatus";
135         DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNKNOWN;
136         verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus);
137     }
138
139     @Test
140     public void shouldSetEmptyOutputsMapWhenInputIsNull() {
141         DeploymentInfo deploymentInfo = new DeploymentInfoBuilder().withDeploymentOutputs(null).build();
142         assertThat(deploymentInfo.getOutputs()).isEmpty();
143     }
144
145     private void verifyDeploymentInfoConstruction(String workflowIdLastAction, String actionStatus,
146             DeploymentStatus expectedDeploymentStatus) {
147
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();
153
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);
158     }
159 }