2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
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=========================================================
21 package org.onap.so.bpmn.infrastructure.workflow.tasks;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.ArgumentMatchers.anyString;
25 import static org.mockito.ArgumentMatchers.isA;
26 import static org.mockito.Mockito.doNothing;
27 import static org.mockito.Mockito.doReturn;
28 import static org.mockito.Mockito.when;
29 import org.camunda.bpm.engine.delegate.DelegateExecution;
30 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
31 import org.junit.Before;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.rules.ExpectedException;
35 import org.mockito.InjectMocks;
36 import org.mockito.Mock;
37 import org.mockito.Mockito;
38 import org.mockito.Spy;
39 import org.onap.so.bpmn.BaseTaskTest;
40 import org.onap.so.bpmn.core.WorkflowException;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
42 import org.onap.so.db.request.beans.InfraActiveRequests;
44 public class WorkflowActionBBFailureTest extends BaseTaskTest {
47 protected WorkflowAction workflowAction;
51 protected WorkflowActionBBFailure workflowActionBBFailure;
54 InfraActiveRequests reqMock;
56 private DelegateExecution execution;
59 public ExpectedException thrown = ExpectedException.none();
62 public void before() throws Exception {
63 execution = new DelegateExecutionFake();
64 org.onap.aai.domain.yang.ServiceInstance servInstance = new org.onap.aai.domain.yang.ServiceInstance();
65 servInstance.setServiceInstanceId("TEST");
66 when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), isA(Customer.class))).thenReturn(servInstance);
67 workflowAction.setBbInputSetupUtils(bbSetupUtils);
68 workflowAction.setBbInputSetup(bbInputSetup);
72 public void updateRequestStatusToFailed_Null_Rollback() {
73 String reqId = "reqId123";
74 execution.setVariable("mso-request-id", reqId);
75 execution.setVariable("retryCount", 3);
76 execution.setVariable("handlingCode", "Success");
77 execution.setVariable("gCurrentSequence", 1);
78 WorkflowException we = new WorkflowException("WorkflowAction", 1231, "Error Case");
79 execution.setVariable("WorkflowException", we);
81 doReturn(reqMock).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
82 workflowActionBBFailure.updateRequestStatusToFailed(execution);
83 Mockito.verify(reqMock, Mockito.times(1)).setStatusMessage("Error Case");
84 Mockito.verify(reqMock, Mockito.times(1)).setRequestStatus("FAILED");
85 Mockito.verify(reqMock, Mockito.times(1)).setProgress(Long.valueOf(100));
86 Mockito.verify(reqMock, Mockito.times(1)).setLastModifiedBy("CamundaBPMN");
90 public void updateRequestStatusToFailed() {
91 execution.setVariable("mso-request-id", "123");
92 execution.setVariable("isRollbackComplete", false);
93 execution.setVariable("isRollback", false);
94 InfraActiveRequests req = new InfraActiveRequests();
95 WorkflowException wfe = new WorkflowException("processKey123", 1, "error in test case");
96 execution.setVariable("WorkflowException", wfe);
97 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123");
98 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
99 workflowActionBBFailure.updateRequestStatusToFailed(execution);
100 String errorMsg = (String) execution.getVariable("ErrorMessage");
101 assertEquals("error in test case", errorMsg);
105 public void updateRequestStatusToFailedRollback() {
106 execution.setVariable("mso-request-id", "123");
107 execution.setVariable("isRollbackComplete", false);
108 execution.setVariable("isRollback", true);
109 InfraActiveRequests req = new InfraActiveRequests();
110 WorkflowException wfe = new WorkflowException("processKey123", 1, "error in rollback");
111 execution.setVariable("WorkflowException", wfe);
112 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123");
113 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
114 workflowActionBBFailure.updateRequestStatusToFailed(execution);
115 String errorMsg = (String) execution.getVariable("RollbackErrorMessage");
116 assertEquals("error in rollback", errorMsg);
120 public void updateRequestStatusToFailedRollbackCompleted() {
121 execution.setVariable("mso-request-id", "123");
122 execution.setVariable("isRollbackComplete", true);
123 execution.setVariable("isRollback", true);
124 InfraActiveRequests req = new InfraActiveRequests();
125 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123");
126 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
127 workflowActionBBFailure.updateRequestStatusToFailed(execution);
128 String errorMsg = (String) execution.getVariable("RollbackErrorMessage");
129 assertEquals("Rollback has been completed successfully.", errorMsg);
133 public void updateRequestStatusToFailedNoWorkflowException() {
134 execution.setVariable("mso-request-id", "123");
135 execution.setVariable("isRollbackComplete", false);
136 execution.setVariable("isRollback", false);
137 execution.setVariable("WorkflowExceptionErrorMessage", "error in test case");
138 InfraActiveRequests req = new InfraActiveRequests();
139 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123");
140 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
141 workflowActionBBFailure.updateRequestStatusToFailed(execution);
142 String errorMsg = (String) execution.getVariable("ErrorMessage");
143 assertEquals("error in test case", errorMsg);