Skip to content

Commit

Permalink
test(engine): add failing test case for BpmnError in IOMapping
Browse files Browse the repository at this point in the history
related to #CAM-3864
  • Loading branch information
menski committed May 11, 2015
1 parent 2f0265d commit aed920a
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
Expand Up @@ -12,6 +12,10 @@
*/
package org.camunda.bpm.engine.test.bpmn.iomapping;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand All @@ -20,6 +24,7 @@
import java.util.concurrent.atomic.AtomicInteger;

import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.delegate.BpmnError;
import org.camunda.bpm.engine.impl.test.PluggableProcessEngineTestCase;
import org.camunda.bpm.engine.runtime.Execution;
import org.camunda.bpm.engine.runtime.Job;
Expand Down Expand Up @@ -815,6 +820,54 @@ public void testMIOutputMappingDisallowed() {

}

@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/iomapping/InputOutputTest.testThrowErrorInScriptInputOutputMapping.bpmn")
public void testBpmnErrorInScriptInputMapping() {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("throwInMapping", "in");
variables.put("exception", new BpmnError("error"));
runtimeService.startProcessInstanceByKey("testProcess", variables);
//we will only reach the user task if the BPMNError from the script was handled by the boundary event
Task task = taskService.createTaskQuery().singleResult();
assertThat(task.getName(), is("User Task"));
}

@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/iomapping/InputOutputTest.testThrowErrorInScriptInputOutputMapping.bpmn")
public void testExceptionInScriptInputMapping() {
String exceptionMessage = "myException";
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("throwInMapping", "in");
variables.put("exception", new RuntimeException(exceptionMessage));
try {
runtimeService.startProcessInstanceByKey("testProcess", variables);
} catch(RuntimeException re){
assertThat(re.getMessage(), containsString(exceptionMessage));
}
}

@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/iomapping/InputOutputTest.testThrowErrorInScriptInputOutputMapping.bpmn")
public void testBpmnErrorInScriptOutputMapping() {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("throwInMapping", "out");
variables.put("exception", new BpmnError("error"));
runtimeService.startProcessInstanceByKey("testProcess", variables);
//we will only reach the user task if the BPMNError from the script was handled by the boundary event
Task task = taskService.createTaskQuery().singleResult();
assertThat(task.getName(), is("User Task"));
}

@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/iomapping/InputOutputTest.testThrowErrorInScriptInputOutputMapping.bpmn")
public void testExceptionInScriptOutputMapping() {
String exceptionMessage = "myException";
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("throwInMapping", "out");
variables.put("exception", new RuntimeException(exceptionMessage));
try {
runtimeService.startProcessInstanceByKey("testProcess", variables);
} catch(RuntimeException re){
assertThat(re.getMessage(), containsString(exceptionMessage));
}
}

@Deployment
public void FAILING_testOutputMappingOnErrorBoundaryEvent() {

Expand Down
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:camunda="http://activiti.org/bpmn" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" id="_KvS8sPBXEeOtYvXzz5ksgw" targetNamespace="http://activiti.org/bpmn">
<process id="testProcess" isExecutable="true">
<startEvent id="start" />
<sequenceFlow sourceRef="start" targetRef="task" />
<serviceTask id="task" camunda:expression="${true}">
<extensionElements>
<camunda:inputOutput>
<camunda:inputParameter name="in">
<camunda:script scriptFormat="groovy">
if (throwInMapping == 'in') {
throw exception
}
</camunda:script>
</camunda:inputParameter>
<camunda:outputParameter name="out">
<camunda:script scriptFormat="groovy">
if (throwInMapping == 'out') {
throw exception
}
</camunda:script>
</camunda:outputParameter>
</camunda:inputOutput>
</extensionElements>
</serviceTask>
<boundaryEvent id="BoundaryEvent_1" name="" attachedToRef="task">
<outgoing>SequenceFlow_3</outgoing>
<errorEventDefinition id="_ErrorEventDefinition_4"/>
</boundaryEvent>
<sequenceFlow id="SequenceFlow_3" name="" sourceRef="BoundaryEvent_1" targetRef="UserTask_1"/>
<userTask id="UserTask_1" name="User Task">
<incoming>SequenceFlow_3</incoming>
<outgoing>SequenceFlow_4</outgoing>
</userTask>
<endEvent id="EndEvent_2">
<incoming>SequenceFlow_4</incoming>
</endEvent>
<sequenceFlow id="SequenceFlow_4" name="" sourceRef="UserTask_1" targetRef="EndEvent_2"/>
<sequenceFlow sourceRef="task" targetRef="wait" />
<receiveTask id="wait" />
<sequenceFlow sourceRef="wait" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>

0 comments on commit aed920a

Please sign in to comment.