📄 canceltest.java
字号:
package org.jbpm.service;
import java.util.*;
import junit.framework.*;
import org.apache.commons.logging.*;
import org.jbpm.*;
import org.jbpm.model.definition.*;
import org.jbpm.model.execution.*;
import org.jbpm.model.execution.impl.*;
import org.jbpm.model.log.*;
public class CancelTest extends TestCase {
public static TestHelper helper = new TestHelper();
private ExecutionService executionService = helper.getExecutionService();
static {
helper.deployProcess( "process/stateprocess.xml" );
helper.deployProcess( "process/concurrencyprocess.xml" );
helper.deployProcess( "process/superprocess.xml" );
helper.deployProcess( "process/subprocess.xml" );
}
public void testSimpleStateCancellation() throws Exception {
// retrieve the definition
Definition definition = executionService.getLatestDefinition( "the state process" );
// start a process instance
InvocationLog invocationLog = executionService.startProcessInstance( "testrunner", definition.getId() );
ProcessInstance processInstance = invocationLog.getProcessInstance();
InvocationLog log = executionService.cancelToken( "testrunner", processInstance.getRoot().getId() );
// check the result
assertTrue( executionService.getToken( processInstance.getRoot().getId(), null ).hasEnded() );
assertTrue( executionService.getProcessInstance( processInstance.getId(), null ).hasEnded() );
}
public void testFirstSubTokenCancellation() throws Exception {
// retrieve the definition
Definition definition = executionService.getLatestDefinition( "the concurrency process" );
// start a process instance
InvocationLog invocationLog = executionService.startProcessInstance( "testrunner", definition.getId() );
// take one of the sub tokens
TokenImpl aSubToken = (TokenImpl) invocationLog.getToken().getChildren().values().iterator().next();
Long subTokenStateId = aSubToken.getState().getId();
// cancel that token
executionService.cancelToken( "testrunner", aSubToken.getId() );
aSubToken = (TokenImpl) executionService.getToken( aSubToken.getId(), null );
// check if the selected token has been cancelled (read : 'ended') properly
assertTrue( aSubToken.hasEnded() );
// check if the other tokens have not been cancelled
Assembler assembler = new PropertyAssembler( "root.children" );
ProcessInstanceImpl processInstance = (ProcessInstanceImpl) executionService.getProcessInstance( aSubToken.getProcessInstance().getId(), assembler );
Iterator iter = processInstance.getRoot().getChildren().values().iterator();
while (iter.hasNext()) {
TokenImpl otherSubToken = (TokenImpl) iter.next();
if ( ! otherSubToken.getId().equals( aSubToken.getId() ) ) {
assertFalse( executionService.getToken( otherSubToken.getId(), null ).hasEnded() );
}
}
// and check if the process instance is not cancelled
assertFalse( executionService.getProcessInstance( invocationLog.getProcessInstance().getId(), null ).hasEnded() );
}
public void testLastSubTokenCancellation() throws Exception {
// retrieve the definition
Definition definition = executionService.getLatestDefinition( "the concurrency process" );
// start a process instance
InvocationLog invocationLog = executionService.startProcessInstance( "testrunner", definition.getId() );
// cancel all the sub tokens
Iterator iter = invocationLog.getToken().getChildren().values().iterator();
while ( iter.hasNext() ) {
TokenImpl aSubToken = (TokenImpl) iter.next();
executionService.cancelToken( "testrunner", aSubToken.getId() );
}
// get the process instance
Assembler assembler = new PropertyAssembler( "root.children" );
ProcessInstanceImpl processInstance = (ProcessInstanceImpl) executionService.getProcessInstance( invocationLog.getProcessInstance().getId(), assembler );
// check that the process instance was ended
assertTrue( processInstance.hasEnded() );
// check that all the sub tokens were ended
iter = processInstance.getRoot().getChildren().values().iterator();
while (iter.hasNext()) {
TokenImpl aSubToken = (TokenImpl) iter.next();
assertTrue( aSubToken.hasEnded() );
}
}
public void testSuperProcessCancellation() throws Exception {
// retrieve the definition
Definition definition = executionService.getLatestDefinition( "the super process" );
// start a process instance
InvocationLog invocationLog = executionService.startProcessInstance( "testrunner", definition.getId() );
executionService.cancelProcessInstance( "testrunner", invocationLog.getProcessInstance().getId() );
// get the process instance
Assembler assembler = new PropertyAssembler( "root.children" );
ProcessInstanceImpl processInstance = (ProcessInstanceImpl) executionService.getProcessInstance( invocationLog.getProcessInstance().getId(), assembler );
// check that the process instance was ended
assertTrue( processInstance.hasEnded() );
// check that all the sub tokens were ended
ProcessInstance subProcessInstance = processInstance.getRoot().getSubProcessInstance();
assertTrue( subProcessInstance.getRoot().hasEnded() );
assertTrue( subProcessInstance.hasEnded() );
}
public void testSubProcessCancellation() throws Exception {
// retrieve the definition
Definition definition = executionService.getLatestDefinition( "the super process" );
// start a process instance
InvocationLog invocationLog = executionService.startProcessInstance( "testrunner", definition.getId() );
// get the id of the sub-process-instance
Long subProcessInstanceId = invocationLog.getProcessInstance().getRoot().getSubProcessInstance().getId();
Long processInstanceId = invocationLog.getProcessInstance().getId();
// cancel the sub-process-instance
executionService.cancelProcessInstance( "testrunner", subProcessInstanceId );
// get the process instance
ProcessInstanceImpl processInstance = (ProcessInstanceImpl) executionService.getProcessInstance( processInstanceId, null );
ProcessInstanceImpl subProcessInstance = (ProcessInstanceImpl) executionService.getProcessInstance( subProcessInstanceId, null );
// check that the super process instance was ended
assertTrue( processInstance.hasEnded() );
assertTrue( processInstance.getRoot().hasEnded() );
// check that the sub process instance was ended
assertTrue( subProcessInstance.hasEnded() );
assertTrue( subProcessInstance.getRoot().hasEnded() );
}
private static Log log = LogFactory.getLog(DecisionTest.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -