aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src/test/java
diff options
context:
space:
mode:
authorJozsef Csongvai <jozsef.csongvai@bell.ca>2021-11-26 17:24:42 -0500
committerJozsef Csongvai <jozsef.csongvai@bell.ca>2021-11-26 17:24:42 -0500
commit1e3c281b0ae601b3c1bed4ba52fc5cb9ae0b0f7a (patch)
tree64af3d2665f4d30ef9234c21f7e419ca568634c9 /bpmn/so-bpmn-tasks/src/test/java
parent18cc4f0fb16e1f03072222268eb2c5661d29bc23 (diff)
Enable CreateChildServiceBB for Service-Macro-Create
Issue-ID: SO-3811 Signed-off-by: Jozsef Csongvai <jozsef.csongvai@bell.ca> Change-Id: I7979082a9f145a84f6f03cf2c44e9ccbca198c5a
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test/java')
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailureTest.java133
1 files changed, 133 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailureTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailureTest.java
index 7f44c97f59..cedaef0bfd 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailureTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailureTest.java
@@ -26,9 +26,20 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.CHILD_SVC_REQ_CORRELATION_ID;
+import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.CHILD_SVC_REQ_ERROR;
+import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.CHILD_SVC_REQ_STATUS;
+import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.IS_CHILD_PROCESS;
+import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.PARENT_CORRELATION_ID;
+
import java.sql.Timestamp;
+import org.camunda.bpm.engine.ProcessEngineServices;
+import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.engine.runtime.MessageCorrelationBuilder;
import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
import org.junit.Before;
import org.junit.Rule;
@@ -271,4 +282,126 @@ public class WorkflowActionBBFailureTest extends BaseTaskTest {
Mockito.verify(reqMock, Mockito.times(1)).setLastModifiedBy("CamundaBPMN");
Mockito.verify(reqMock, Mockito.times(1)).setEndTime(any(Timestamp.class));
}
+
+ @Test
+ public void invokeSendMessageForChildServiceRollBackCompletedSuccessfully() {
+ String parentCorrelationId = "parentCorrelationId";
+ DelegateExecution mockExecution = Mockito.mock(DelegateExecution.class);
+ ProcessEngineServices processEngineServices = mock(ProcessEngineServices.class);
+ RuntimeService runtimeService = mock(RuntimeService.class);
+ MessageCorrelationBuilder messageCorrelationBuilder = mock(MessageCorrelationBuilder.class);
+ when(processEngineServices.getRuntimeService()).thenReturn(runtimeService);
+ when(runtimeService.createMessageCorrelation(anyString())).thenReturn(messageCorrelationBuilder);
+ when(messageCorrelationBuilder.setVariable(CHILD_SVC_REQ_STATUS, "FAILED"))
+ .thenReturn(messageCorrelationBuilder);
+ when(messageCorrelationBuilder.setVariable(CHILD_SVC_REQ_ERROR, "Rollback has been completed successfully."))
+ .thenReturn(messageCorrelationBuilder);
+ when(messageCorrelationBuilder.processInstanceVariableEquals(CHILD_SVC_REQ_CORRELATION_ID, parentCorrelationId))
+ .thenReturn(messageCorrelationBuilder);
+
+ when(mockExecution.getVariable(PARENT_CORRELATION_ID)).thenReturn(parentCorrelationId);
+ when(mockExecution.getVariable("mso-request-id")).thenReturn("123");
+ when(mockExecution.getVariable("isRollbackComplete")).thenReturn(true);
+ when(mockExecution.getVariable("isRollback")).thenReturn(true);
+ when(mockExecution.getVariable(IS_CHILD_PROCESS)).thenReturn(true);
+
+ when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
+
+ InfraActiveRequests req = new InfraActiveRequests();
+ WorkflowException wfe = new WorkflowException("processKey123", 1, "error in rollback");
+ when(mockExecution.getVariable("WorkflowException")).thenReturn(wfe);
+ doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123");
+ doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
+ workflowActionBBFailure.updateRequestStatusToFailed(mockExecution);
+
+ verify(messageCorrelationBuilder).setVariable(CHILD_SVC_REQ_STATUS, "FAILED");
+ verify(messageCorrelationBuilder).setVariable(CHILD_SVC_REQ_ERROR,
+ "Rollback has been completed successfully.");
+ verify(messageCorrelationBuilder).processInstanceVariableEquals(CHILD_SVC_REQ_CORRELATION_ID,
+ parentCorrelationId);
+ }
+
+ @Test
+ public void invokeSendMessageForChildServiceRollBackFailure() {
+ String parentCorrelationId = "parentCorrelationId";
+ DelegateExecution mockExecution = Mockito.mock(DelegateExecution.class);
+ ProcessEngineServices processEngineServices = mock(ProcessEngineServices.class);
+ RuntimeService runtimeService = mock(RuntimeService.class);
+ MessageCorrelationBuilder messageCorrelationBuilder = mock(MessageCorrelationBuilder.class);
+ when(processEngineServices.getRuntimeService()).thenReturn(runtimeService);
+ when(runtimeService.createMessageCorrelation(anyString())).thenReturn(messageCorrelationBuilder);
+ when(messageCorrelationBuilder.setVariable(CHILD_SVC_REQ_STATUS, "FAILED"))
+ .thenReturn(messageCorrelationBuilder);
+ when(messageCorrelationBuilder.setVariable(CHILD_SVC_REQ_ERROR, "error in rollback"))
+ .thenReturn(messageCorrelationBuilder);
+ when(messageCorrelationBuilder.processInstanceVariableEquals(PARENT_CORRELATION_ID, parentCorrelationId))
+ .thenReturn(messageCorrelationBuilder);
+
+ when(mockExecution.getVariable(PARENT_CORRELATION_ID)).thenReturn(parentCorrelationId);
+ when(mockExecution.getVariable("mso-request-id")).thenReturn("123");
+ when(mockExecution.getVariable("isRollbackComplete")).thenReturn(false);
+ when(mockExecution.getVariable("isRollback")).thenReturn(true);
+ when(mockExecution.getVariable(IS_CHILD_PROCESS)).thenReturn(true);
+
+ when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
+
+ InfraActiveRequests req = new InfraActiveRequests();
+ doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123");
+ doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
+ workflowActionBBFailure.updateRequestStatusToFailed(mockExecution);
+
+ verify(messageCorrelationBuilder).setVariable(CHILD_SVC_REQ_STATUS, "FAILED");
+ verify(messageCorrelationBuilder).setVariable(CHILD_SVC_REQ_ERROR,
+ "Failed to determine rollback error message.");
+
+ WorkflowException wfe = new WorkflowException("processKey123", 1, "error in rollback");
+ when(mockExecution.getVariable("WorkflowException")).thenReturn(wfe);
+ workflowActionBBFailure.updateRequestStatusToFailed(mockExecution);
+ verify(messageCorrelationBuilder).setVariable(CHILD_SVC_REQ_ERROR, "error in rollback");
+ verify(messageCorrelationBuilder).processInstanceVariableEquals(CHILD_SVC_REQ_CORRELATION_ID,
+ parentCorrelationId);
+ }
+
+ @Test
+ public void invokeSendMessageForChildServiceNoRollBack() {
+ String parentCorrelationId = "parentCorrelationId";
+ DelegateExecution mockExecution = Mockito.mock(DelegateExecution.class);
+ ProcessEngineServices processEngineServices = mock(ProcessEngineServices.class);
+ RuntimeService runtimeService = mock(RuntimeService.class);
+ MessageCorrelationBuilder messageCorrelationBuilder = mock(MessageCorrelationBuilder.class);
+ when(processEngineServices.getRuntimeService()).thenReturn(runtimeService);
+ when(runtimeService.createMessageCorrelation(anyString())).thenReturn(messageCorrelationBuilder);
+ when(messageCorrelationBuilder.setVariable(CHILD_SVC_REQ_STATUS, "FAILED"))
+ .thenReturn(messageCorrelationBuilder);
+ when(messageCorrelationBuilder.setVariable(CHILD_SVC_REQ_ERROR, "error in rollback"))
+ .thenReturn(messageCorrelationBuilder);
+ when(messageCorrelationBuilder.processInstanceVariableEquals(PARENT_CORRELATION_ID, parentCorrelationId))
+ .thenReturn(messageCorrelationBuilder);
+
+ when(mockExecution.getVariable(PARENT_CORRELATION_ID)).thenReturn(parentCorrelationId);
+ when(mockExecution.getVariable("mso-request-id")).thenReturn("123");
+ when(mockExecution.getVariable("isRollbackComplete")).thenReturn(false);
+ when(mockExecution.getVariable("isRollback")).thenReturn(false);
+ when(mockExecution.getVariable(IS_CHILD_PROCESS)).thenReturn(true);
+
+ when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
+
+ InfraActiveRequests req = new InfraActiveRequests();
+ doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123");
+ doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
+ workflowActionBBFailure.updateRequestStatusToFailed(mockExecution);
+
+ verify(messageCorrelationBuilder).setVariable(CHILD_SVC_REQ_STATUS, "FAILED");
+ verify(messageCorrelationBuilder).setVariable(CHILD_SVC_REQ_ERROR, "Failed to determine error message");
+
+ WorkflowException wfe = new WorkflowException("processKey123", 1, "error in rollback");
+ when(mockExecution.getVariable("WorkflowException")).thenReturn(wfe);
+ workflowActionBBFailure.updateRequestStatusToFailed(mockExecution);
+ verify(messageCorrelationBuilder).setVariable(CHILD_SVC_REQ_ERROR, "error in rollback");
+ verify(messageCorrelationBuilder).processInstanceVariableEquals(CHILD_SVC_REQ_CORRELATION_ID,
+ parentCorrelationId);
+ }
+
+
+
}