Skip to content

Commit

Permalink
test(engine): fix tests forexception handling between two activities
Browse files Browse the repository at this point in the history
-change the tests and process defnitions slightly because the second
activity was not a scope, which was necessary for the test
-rename the .bpmn files to include the word "scope"

Related to CAM-4001
  • Loading branch information
Ronny Bräunlich committed Jun 9, 2015
1 parent 449a251 commit a408f5a
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,18 @@ public void testCatchExceptionClassDelegateThrownByFollowUpTask() {
assertNull(taskService.createTaskQuery().singleResult());
}

@Deployment
public void testCatchExceptionExpressionThrownByFollowUpScopeTask() {
try {
Map<String, Object> vars = throwException();
runtimeService.startProcessInstanceByKey("testProcess", vars).getId();
fail("should fail and not catch the error on the first task");
} catch (ProcessEngineException e) {
// happy path
}
assertNull(taskService.createTaskQuery().singleResult());
}


@Deployment( resources = {
"org/camunda/bpm/engine/test/bpmn/event/error/BoundaryErrorEventTest.testCatchErrorThrownByAbstractBpmnActivityBehavior.bpmn20.xml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*/
package org.camunda.bpm.engine.test.bpmn.scripttask;

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

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
Expand All @@ -21,6 +24,7 @@
import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.ScriptCompilationException;
import org.camunda.bpm.engine.ScriptEvaluationException;
import org.camunda.bpm.engine.exception.NullValueException;
import org.camunda.bpm.engine.impl.test.PluggableProcessEngineTestCase;
import org.camunda.bpm.engine.repository.Deployment;
import org.camunda.bpm.engine.runtime.ProcessInstance;
Expand Down Expand Up @@ -604,12 +608,16 @@ public void testAutoStoreScriptVarsOff() {

@org.camunda.bpm.engine.test.Deployment
public void testPreviousTaskShouldNotHandleException(){
runtimeService.startProcessInstanceByKey("process");
Task task = taskService.createTaskQuery().singleResult();
try {
taskService.complete(task.getId());
runtimeService.startProcessInstanceByKey("process");
fail();
}
catch (ScriptEvaluationException see){}
// since the NVE extends the ProcessEngineException we have to handle it
// separately
catch (NullValueException nve) {
fail("Shouldn't have received NullValueException");
} catch (ProcessEngineException e) {
assertThat(e.getMessage(), containsString("Invalid format"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
*/
package org.camunda.bpm.engine.test.bpmn.servicetask;

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

import java.util.Collections;
import java.util.Map;

import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.exception.NullValueException;
import org.camunda.bpm.engine.impl.test.PluggableProcessEngineTestCase;
import org.camunda.bpm.engine.test.Deployment;
import org.junit.Test;
Expand All @@ -26,17 +31,21 @@
public class ServiceTaskClassDelegateActivityBehaviorTest extends PluggableProcessEngineTestCase {

@Deployment
@Test(expected=ThrowExceptionServiceTask.ServiceTaskException.class)
public void testExceptionThrownBySecondServiceTaskIsNotHandled(){
@Test
public void testExceptionThrownBySecondScopeServiceTaskIsNotHandled() {
Map<Object, Object> beans = processEngineConfiguration.getBeans();
beans.put("dummyServiceTask", new DummyServiceTask());
beans.put("throwExceptionServiceTask", new ThrowExceptionServiceTask());
processEngineConfiguration.setBeans(beans);

try{
runtimeService.startProcessInstanceByKey("process", Collections.<String, Object>singletonMap("count", 0));
try {
runtimeService.startProcessInstanceByKey("process", Collections.<String, Object> singletonMap("count", 0));
fail();
} catch(ThrowExceptionServiceTask.ServiceTaskException e){}
} // since the NVE extends the ProcessEngineException we have to handle it
// separately
catch (NullValueException nve) {
fail("Shouldn't have received NullValueException");
} catch (ProcessEngineException e) {
assertThat(e.getMessage(), containsString("Invalid format"));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
*/
package org.camunda.bpm.engine.test.bpmn.servicetask;

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

import java.util.Collections;
import java.util.Map;

import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.exception.NullValueException;
import org.camunda.bpm.engine.impl.test.PluggableProcessEngineTestCase;
import org.camunda.bpm.engine.test.Deployment;
import org.junit.Test;
Expand All @@ -26,17 +31,22 @@
public class ServiceTaskDelegateExpressionActivityBehaviorTest extends PluggableProcessEngineTestCase {

@Deployment
@Test(expected=ThrowExceptionServiceTask.ServiceTaskException.class)
public void testExceptionThrownBySecondServiceTaskIsNotHandled(){
@Test
public void testExceptionThrownBySecondScopeServiceTaskIsNotHandled() {
Map<Object, Object> beans = processEngineConfiguration.getBeans();
beans.put("dummyServiceTask", new DummyServiceTask());
beans.put("throwExceptionServiceTask", new ThrowExceptionServiceTask());
processEngineConfiguration.setBeans(beans);

try{
runtimeService.startProcessInstanceByKey("process", Collections.<String, Object>singletonMap("count", 0));
try {
runtimeService.startProcessInstanceByKey("process", Collections.<String, Object> singletonMap("count", 0));
fail();
} catch(ThrowExceptionServiceTask.ServiceTaskException e){}
} // since the NVE extends the ProcessEngineException we have to handle it
// separately
catch (NullValueException nve) {
fail("Shouldn't have received NullValueException");
} catch (ProcessEngineException e) {
assertThat(e.getMessage(), containsString("Invalid format"));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
*/
package org.camunda.bpm.engine.test.bpmn.servicetask;

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

import java.util.Collections;
import java.util.Map;

import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.exception.NullValueException;
import org.camunda.bpm.engine.impl.test.PluggableProcessEngineTestCase;
import org.camunda.bpm.engine.test.Deployment;

Expand All @@ -26,17 +30,23 @@
public class ServiceTaskExpressionActivityBehaviorTest extends PluggableProcessEngineTestCase {

@Deployment
public void testExceptionThrownBySecondServiceTaskIsNotHandled(){
public void testExceptionThrownBySecondScopeServiceTaskIsNotHandled(){
Map<Object, Object> beans = processEngineConfiguration.getBeans();
beans.put("dummyServiceTask", new DummyServiceTask());
beans.put("throwExceptionServiceTask", new ThrowExceptionServiceTask());
processEngineConfiguration.setBeans(beans);

try{
runtimeService.startProcessInstanceByKey("process", Collections.<String, Object>singletonMap("count", 0));
fail();
// the EL resolver will wrap the actual exception inside a process engine exception
} catch(ProcessEngineException e){}
}
//since the NVE extends the ProcessEngineException we have to handle it separately
catch(NullValueException nve){
fail("Shouldn't have received NullValueException");
}
catch(ProcessEngineException e){
assertThat(e.getMessage(), containsString("Invalid format"));
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:camunda="http://activiti.org/bpmn"
targetNamespace="Examples">

<error id="myError" errorCode="MyError" />
<error id="myException" errorCode="org.camunda.bpm.engine.test.bpmn.event.error.MyBusinessException" />

<process id="testProcess" isExecutable="true">

<startEvent id="start" />

<sequenceFlow id="flow1" sourceRef="start" targetRef="serviceTask" />

<serviceTask id="serviceTask" camunda:expression="${true}" />

<boundaryEvent id="catchException" attachedToRef="serviceTask">
<errorEventDefinition errorRef="myException"/>
</boundaryEvent>

<sequenceFlow id="flow2" sourceRef="serviceTask" targetRef="serviceTask2" />

<serviceTask id="serviceTask2" camunda:class="org.camunda.bpm.engine.test.bpmn.event.error.ThrowErrorDelegate" />

<sequenceFlow id="flow7" sourceRef="serviceTask2" targetRef="end" />
<boundaryEvent id="BoundaryEvent_1" name="" attachedToRef="serviceTask2" cancelActivity="false">
<timerEventDefinition id="_TimerEventDefinition_3">
<timeDuration>P1D</timeDuration>
</timerEventDefinition>
</boundaryEvent>

<endEvent id="end" />

<sequenceFlow id="flow5" sourceRef="catchException" targetRef="userTaskException" />

<userTask id="userTaskException" name="Exception Task" />

<sequenceFlow id="flow6" sourceRef="userTaskException" targetRef="endException" />

<endEvent id="endException" />

</process>

</definitions>
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,32 @@
<bpmn2:startEvent id="StartEvent_1">
<bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:userTask id="UserTask_1" name="User Task">
<bpmn2:scriptTask id="UserTask_1" name="First Script Task" scriptFormat="groovy">
<bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_2</bpmn2:outgoing>
</bpmn2:userTask>
<bpmn2:script></bpmn2:script>
</bpmn2:scriptTask>
<bpmn2:sequenceFlow id="SequenceFlow_1" name="" sourceRef="StartEvent_1" targetRef="UserTask_1"/>
<bpmn2:scriptTask id="ScriptTask_1" name="Script Task" scriptFormat="groovy">
<bpmn2:scriptTask id="ScriptTask_1" name="Second Script Task" scriptFormat="groovy">
<bpmn2:incoming>SequenceFlow_2</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_3</bpmn2:outgoing>
<bpmn2:script><![CDATA[throw new org.camunda.bpm.engine.ProcessEngineException("Test");]]></bpmn2:script>
<bpmn2:script></bpmn2:script>
</bpmn2:scriptTask>
<bpmn2:sequenceFlow id="SequenceFlow_2" name="" sourceRef="UserTask_1" targetRef="ScriptTask_1"/>
<bpmn2:endEvent id="EndEvent_1">
<bpmn2:incoming>SequenceFlow_3</bpmn2:incoming>
</bpmn2:endEvent>
<bpmn2:sequenceFlow id="SequenceFlow_3" name="" sourceRef="ScriptTask_1" targetRef="EndEvent_1"/>
<bpmn2:boundaryEvent id="BoundaryEvent_1" name="" attachedToRef="ScriptTask_1">
<bpmn2:outgoing>SequenceFlow_4</bpmn2:outgoing>
<bpmn2:timerEventDefinition id="_TimerEventDefinition_5">
<bpmn2:timeDuration xsi:type="bpmn2:tFormalExpression">time is just a concept</bpmn2:timeDuration>
</bpmn2:timerEventDefinition>
</bpmn2:boundaryEvent>
<bpmn2:sequenceFlow id="SequenceFlow_4" name="" sourceRef="BoundaryEvent_1" targetRef="EndEvent_2"/>
<bpmn2:endEvent id="EndEvent_2">
<bpmn2:incoming>SequenceFlow_4</bpmn2:incoming>
</bpmn2:endEvent>
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="process">
Expand Down Expand Up @@ -46,6 +57,23 @@
<di:waypoint xsi:type="dc:Point" x="561.0" y="219.0"/>
<di:waypoint xsi:type="dc:Point" x="611.0" y="219.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_BoundaryEvent_6" bpmnElement="BoundaryEvent_1">
<dc:Bounds height="36.0" width="36.0" x="490.0" y="241.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_EndEvent_39" bpmnElement="EndEvent_2">
<dc:Bounds height="36.0" width="36.0" x="577.0" y="292.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="0.0" width="0.0" x="595.0" y="333.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_4" bpmnElement="SequenceFlow_4" sourceElement="_BPMNShape_BoundaryEvent_6" targetElement="_BPMNShape_EndEvent_39">
<di:waypoint xsi:type="dc:Point" x="508.0" y="277.0"/>
<di:waypoint xsi:type="dc:Point" x="508.0" y="310.0"/>
<di:waypoint xsi:type="dc:Point" x="577.0" y="310.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="6.0" width="6.0" x="545.0" y="310.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
<bpmn2:incoming>SequenceFlow_3</bpmn2:incoming>
</bpmn2:endEvent>
<bpmn2:sequenceFlow id="SequenceFlow_3" name="" sourceRef="ServiceTask_2" targetRef="EndEvent_1"/>
<bpmn2:boundaryEvent id="BoundaryEvent_1" name="" attachedToRef="ServiceTask_2" cancelActivity="false">
<bpmn2:outgoing>SequenceFlow_4</bpmn2:outgoing>
<bpmn2:timerEventDefinition id="_TimerEventDefinition_4">
<bpmn2:timeDuration xsi:type="bpmn2:tFormalExpression">time is just a concept</bpmn2:timeDuration>
</bpmn2:timerEventDefinition>
</bpmn2:boundaryEvent>
<bpmn2:sequenceFlow id="SequenceFlow_4" name="" sourceRef="BoundaryEvent_1" targetRef="EndEvent_2"/>
<bpmn2:endEvent id="EndEvent_2">
<bpmn2:incoming>SequenceFlow_4</bpmn2:incoming>
</bpmn2:endEvent>
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
Expand Down Expand Up @@ -45,6 +55,23 @@
<di:waypoint xsi:type="dc:Point" x="503.0" y="258.0"/>
<di:waypoint xsi:type="dc:Point" x="553.0" y="258.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_BoundaryEvent_5" bpmnElement="BoundaryEvent_1">
<dc:Bounds height="36.0" width="36.0" x="447.0" y="280.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_EndEvent_38" bpmnElement="EndEvent_2">
<dc:Bounds height="36.0" width="36.0" x="550.0" y="321.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="0.0" width="0.0" x="568.0" y="362.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_4" bpmnElement="SequenceFlow_4" sourceElement="_BPMNShape_BoundaryEvent_5" targetElement="_BPMNShape_EndEvent_38">
<di:waypoint xsi:type="dc:Point" x="465.0" y="316.0"/>
<di:waypoint xsi:type="dc:Point" x="465.0" y="339.0"/>
<di:waypoint xsi:type="dc:Point" x="550.0" y="339.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="6.0" width="6.0" x="512.0" y="339.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>
Loading

0 comments on commit a408f5a

Please sign in to comment.