Merge "Added quriedVolumeGroupId to createvfModule"
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / workflow / tasks / WorkflowActionBBFailureTest.java
1 package org.onap.so.bpmn.infrastructure.workflow.tasks;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.mockito.ArgumentMatchers.anyString;
5 import static org.mockito.ArgumentMatchers.isA;
6 import static org.mockito.Mockito.doNothing;
7 import static org.mockito.Mockito.doReturn;
8 import static org.mockito.Mockito.when;
9
10 import org.camunda.bpm.engine.delegate.DelegateExecution;
11 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
12 import org.junit.Before;
13 import org.junit.Rule;
14 import org.junit.Test;
15 import org.junit.rules.ExpectedException;
16 import org.mockito.InjectMocks;
17 import org.mockito.Mock;
18 import org.mockito.Mockito;
19 import org.mockito.Spy;
20 import org.onap.so.bpmn.BaseTaskTest;
21 import org.onap.so.bpmn.core.WorkflowException;
22 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
23 import org.onap.so.db.request.beans.InfraActiveRequests;
24
25 public class WorkflowActionBBFailureTest  extends BaseTaskTest {
26
27         @Mock
28         protected WorkflowAction workflowAction;
29         
30         @InjectMocks
31         @Spy
32         protected WorkflowActionBBFailure workflowActionBBFailure;
33         
34         @Mock
35         InfraActiveRequests reqMock;
36         
37         private DelegateExecution execution;
38         
39         @Rule
40         public ExpectedException thrown = ExpectedException.none();
41         
42         @Before
43         public void before() throws Exception {
44                 execution = new DelegateExecutionFake();
45                 org.onap.aai.domain.yang.ServiceInstance servInstance = new org.onap.aai.domain.yang.ServiceInstance();
46                 servInstance.setServiceInstanceId("TEST");
47                 when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), isA(Customer.class))).thenReturn(servInstance);
48                 workflowAction.setBbInputSetupUtils(bbSetupUtils);
49                 workflowAction.setBbInputSetup(bbInputSetup);
50         }
51         
52         @Test
53         public void updateRequestStatusToFailed_Null_Rollback(){
54                 String reqId = "reqId123";
55                 execution.setVariable("mso-request-id", reqId);
56                 execution.setVariable("retryCount", 3);
57                 execution.setVariable("handlingCode","Success");
58                 execution.setVariable("gCurrentSequence",1);
59                 WorkflowException we = new WorkflowException("WorkflowAction",1231,"Error Case");
60                 execution.setVariable("WorkflowException",we);
61                 
62                 doReturn(reqMock).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
63                 workflowActionBBFailure.updateRequestStatusToFailed(execution);
64                 Mockito.verify( reqMock, Mockito.times(1)).setStatusMessage("Error Case");
65                 Mockito.verify( reqMock, Mockito.times(1)).setRequestStatus("FAILED");
66                 Mockito.verify( reqMock, Mockito.times(1)).setProgress(Long.valueOf(100));
67                 Mockito.verify( reqMock, Mockito.times(1)).setLastModifiedBy("CamundaBPMN");
68         }
69         
70         @Test
71         public void updateRequestStatusToFailed(){
72                 execution.setVariable("mso-request-id", "123");
73                 execution.setVariable("isRollbackComplete", false);
74                 execution.setVariable("isRollback", false);
75                 InfraActiveRequests req = new InfraActiveRequests();
76                 WorkflowException wfe = new WorkflowException("processKey123", 1, "error in test case");
77                 execution.setVariable("WorkflowException", wfe);
78                 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123");
79                 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
80                 workflowActionBBFailure.updateRequestStatusToFailed(execution);
81                 String errorMsg = (String) execution.getVariable("ErrorMessage");
82                 assertEquals("error in test case", errorMsg);
83         }
84         
85         @Test
86         public void updateRequestStatusToFailedRollback(){
87                 execution.setVariable("mso-request-id", "123");
88                 execution.setVariable("isRollbackComplete", false);
89                 execution.setVariable("isRollback", true);
90                 InfraActiveRequests req = new InfraActiveRequests();
91                 WorkflowException wfe = new WorkflowException("processKey123", 1, "error in rollback");
92                 execution.setVariable("WorkflowException", wfe);
93                 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123");
94                 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
95                 workflowActionBBFailure.updateRequestStatusToFailed(execution);
96                 String errorMsg = (String) execution.getVariable("RollbackErrorMessage");
97                 assertEquals("error in rollback", errorMsg);
98         }
99         
100         @Test
101         public void updateRequestStatusToFailedRollbackCompleted(){
102                 execution.setVariable("mso-request-id", "123");
103                 execution.setVariable("isRollbackComplete", true);
104                 execution.setVariable("isRollback", true);
105                 InfraActiveRequests req = new InfraActiveRequests();
106                 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123");
107                 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
108                 workflowActionBBFailure.updateRequestStatusToFailed(execution);
109                 String errorMsg = (String) execution.getVariable("RollbackErrorMessage");
110                 assertEquals("Rollback has been completed successfully.", errorMsg);
111         }
112         
113         @Test
114         public void updateRequestStatusToFailedNoWorkflowException(){
115                 execution.setVariable("mso-request-id", "123");
116                 execution.setVariable("isRollbackComplete", false);
117                 execution.setVariable("isRollback", false);
118                 execution.setVariable("WorkflowExceptionErrorMessage", "error in test case");
119                 InfraActiveRequests req = new InfraActiveRequests();
120                 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123");
121                 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
122                 workflowActionBBFailure.updateRequestStatusToFailed(execution);
123                 String errorMsg = (String) execution.getVariable("ErrorMessage");
124                 assertEquals("error in test case", errorMsg);
125         }
126 }