Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
244 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...src/test/java/org/activiti/engine/test/bpmn/servicetask/CallServiceInServiceTaskTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.activiti.engine.test.bpmn.servicetask; | ||
|
||
import java.util.List; | ||
|
||
import org.activiti.engine.impl.test.PluggableActivitiTestCase; | ||
import org.activiti.engine.repository.ProcessDefinition; | ||
import org.activiti.engine.runtime.ProcessInstance; | ||
import org.activiti.engine.test.Deployment; | ||
|
||
/** | ||
* @author Joram Barrez | ||
*/ | ||
public class CallServiceInServiceTaskTest extends PluggableActivitiTestCase { | ||
|
||
@Deployment | ||
public void testStartProcessFromDelegate() { | ||
runtimeService.startProcessInstanceByKey("startProcessFromDelegate"); | ||
|
||
// Starting the process should lead to two processes being started, | ||
// The other one started from the java delegate in the service task | ||
List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list(); | ||
assertEquals(2, processInstances.size()); | ||
|
||
boolean startProcessFromDelegateFound = false; | ||
boolean oneTaskProcessFound = false; | ||
for (ProcessInstance processInstance : processInstances) { | ||
ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId()); | ||
if (processDefinition.getKey().equals("startProcessFromDelegate")) { | ||
startProcessFromDelegateFound = true; | ||
} else if (processDefinition.getKey().equals("oneTaskProcess")) { | ||
oneTaskProcessFound = true; | ||
} | ||
} | ||
|
||
assertTrue(startProcessFromDelegateFound); | ||
assertTrue(oneTaskProcessFound); | ||
} | ||
|
||
@Deployment | ||
public void testRollBackOnException() { | ||
Exception expectedException = null; | ||
try { | ||
runtimeService.startProcessInstanceByKey("startProcessFromDelegate"); | ||
} catch (Exception e) { | ||
expectedException = e; | ||
} | ||
assertNotNull(expectedException); | ||
|
||
// Starting the process should cause a rollback of both processes | ||
assertEquals(0, runtimeService.createProcessInstanceQuery().count()); | ||
} | ||
|
||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...test/java/org/activiti/engine/test/bpmn/servicetask/StartProcessInstanceTestDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.activiti.engine.test.bpmn.servicetask; | ||
|
||
import org.activiti.engine.RuntimeService; | ||
import org.activiti.engine.delegate.DelegateExecution; | ||
import org.activiti.engine.delegate.JavaDelegate; | ||
import org.activiti.engine.impl.context.Context; | ||
|
||
/** | ||
* @author Joram Barrez | ||
*/ | ||
public class StartProcessInstanceTestDelegate implements JavaDelegate { | ||
|
||
public void execute(DelegateExecution execution) throws Exception { | ||
RuntimeService runtimeService = Context.getProcessEngineConfiguration().getRuntimeService(); | ||
runtimeService.startProcessInstanceByKey("oneTaskProcess"); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...ine/test/bpmn/servicetask/CallServiceInServiceTaskTest.testRollBackOnException.bpmn20.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<definitions | ||
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" | ||
xmlns:activiti="http://activiti.org/bpmn" | ||
targetNamespace="Examples"> | ||
|
||
<process id="startProcessFromDelegate" isExecutable="true"> | ||
|
||
<startEvent id="theStart" /> | ||
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="service" /> | ||
|
||
<serviceTask id="service" activiti:class="org.activiti.engine.test.bpmn.servicetask.StartProcessInstanceTestDelegate" /> | ||
<sequenceFlow id="flow2" sourceRef="service" targetRef="failingScriptTask" /> | ||
|
||
<scriptTask id="failingScriptTask" name="Execute script" scriptFormat="groovy"> | ||
<script> | ||
// Throw an exception in script task | ||
throw new RuntimeException("This is an exception thrown from scriptTask") | ||
</script> | ||
</scriptTask> | ||
<sequenceFlow id="flow3" sourceRef="failingScriptTask" targetRef="theEnd" /> | ||
|
||
<endEvent id="theEnd" /> | ||
|
||
</process> | ||
|
||
<process id="oneTaskProcess" isExecutable="true"> | ||
|
||
<startEvent id="oneTaskProcessStart" /> | ||
<sequenceFlow id="oneTaskProcessFlow1" sourceRef="oneTaskProcessStart" targetRef="oneTaskProcessUserTask" /> | ||
|
||
<userTask id="oneTaskProcessUserTask" /> | ||
<sequenceFlow id="oneTaskProcessFlow2" sourceRef="oneTaskProcessUserTask" targetRef="oneTaskProcessEnd" /> | ||
|
||
<endEvent id="oneTaskProcessEnd" /> | ||
|
||
</process> | ||
|
||
</definitions> |
34 changes: 34 additions & 0 deletions
34
...est/bpmn/servicetask/CallServiceInServiceTaskTest.testStartProcessFromDelegate.bpmn20.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<definitions | ||
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" | ||
xmlns:activiti="http://activiti.org/bpmn" | ||
targetNamespace="Examples"> | ||
|
||
<process id="startProcessFromDelegate" isExecutable="true"> | ||
|
||
<startEvent id="theStart" /> | ||
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="service" /> | ||
|
||
<serviceTask id="service" activiti:class="org.activiti.engine.test.bpmn.servicetask.StartProcessInstanceTestDelegate" /> | ||
<sequenceFlow id="flow2" sourceRef="service" targetRef="task" /> | ||
|
||
<userTask id="task" /> | ||
<sequenceFlow id="flow3" sourceRef="task" targetRef="theEnd" /> | ||
|
||
<endEvent id="theEnd" /> | ||
|
||
</process> | ||
|
||
<process id="oneTaskProcess" isExecutable="true"> | ||
|
||
<startEvent id="oneTaskProcessStart" /> | ||
<sequenceFlow id="oneTaskProcessFlow1" sourceRef="oneTaskProcessStart" targetRef="oneTaskProcessTask" /> | ||
|
||
<userTask id="oneTaskProcessTask" /> | ||
<sequenceFlow id="oneTaskProcessFlow2" sourceRef="oneTaskProcessTask" targetRef="oneTaskProcessEnd" /> | ||
|
||
<endEvent id="oneTaskProcessEnd" /> | ||
|
||
</process> | ||
|
||
</definitions> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters