Skip to content

Commit

Permalink
Adding possibility to throw an error on execution (#327)
Browse files Browse the repository at this point in the history
Adding test for for throwing an error on execution

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jan Galinski <[email protected]>
  • Loading branch information
3 people authored Oct 4, 2023
1 parent b4bb0d1 commit 3005381
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public interface MockedModelConfigurer {

private BpmnModelInstance modelInstance = null;
private String escalation;
private String error;

public CallActivityMock(final String processId, final MockedModelConfigurer modelConfigurer) {
this.processId = processId;
Expand Down Expand Up @@ -235,6 +236,19 @@ public CallActivityMock onExecutionThrowEscalation(final String escalationCode)
this.escalation = escalationCode;
return this;
}

/**
* On execution, the MockProcess will throw error for the given code when no escalation is set
*
* If called multiple times, this method adds only the last error to the end event.
*
* @param escalationCode the escalation code
* @return self
*/
public CallActivityMock onExecutionThrowError(final String errorCode) {
this.error = errorCode;
return this;
}

/**
* This will deploy the mock process.
Expand All @@ -260,6 +274,8 @@ public BpmnModelInstance getModelInstance() {

if (this.escalation != null) {
endEvent = endEvent.escalation(this.escalation);
} else if (this.error != null) {
endEvent = endEvent.error(this.error);
}

modelInstance = endEvent.done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,36 @@ public void register_subprocess_mock_throwEscalation() {
isEnded(processInstance);
assertEquals(escalationEndId, ((ProcessInstanceWithVariablesImpl) processInstance).getExecutionEntity().getActivityId());
}

@Test
public void register_subprocess_mock_throwError() {
String errorCode = "SOME_ERROR";
String subprocessId = "call_subprocess";
String errorEndId = "ErrorEnd";

BpmnModelInstance processWithSubProcess = Bpmn.createExecutableProcess(PROCESS_ID)
.startEvent("start")
.callActivity(subprocessId)
.calledElement(SUB_PROCESS_ID)
.boundaryEvent()
.error(errorCode)
.endEvent(errorEndId)
.moveToActivity(subprocessId)
.userTask(TASK_USERTASK)
.endEvent("end")
.done();

camunda.manageDeployment(new DeployProcess(camunda).apply(PROCESS_ID, processWithSubProcess));

camunda.manageDeployment(registerCallActivityMock(SUB_PROCESS_ID)
.onExecutionThrowError(errorCode)
.deploy(camunda));

ProcessInstance processInstance = startProcess(PROCESS_ID);

isEnded(processInstance);
assertEquals(errorEndId, ((ProcessInstanceWithVariablesImpl) processInstance).getExecutionEntity().getActivityId());
}

private void prepareProcessWithOneSubprocess() {
final BpmnModelInstance processWithSubProcess = Bpmn.createExecutableProcess(PROCESS_ID)
Expand Down

0 comments on commit 3005381

Please sign in to comment.