📄 decisiontest.java
字号:
package org.jbpm.service;
import java.util.*;
import junit.framework.*;
import org.apache.commons.logging.*;
import org.jbpm.*;
import org.jbpm.delegation.*;
import org.jbpm.model.definition.*;
import org.jbpm.model.execution.impl.*;
import org.jbpm.model.log.*;
public class DecisionTest extends TestCase {
public static TestHelper helper = new TestHelper();
private ExecutionService executionService = helper.getExecutionService();
static {
helper.deployProcess( "process/decisionprocess.xml" );
}
public static class TestDecisionHandler implements DecisionHandler {
public String decide(ExecutionContext executionContext) {
String transitionName = null;
String routeDescription = (String) executionContext.getVariable( "route description" );
if ( routeDescription == "take a left" ) {
transitionName = "left";
} else if ( routeDescription == "take a right" ) {
transitionName = "right";
} else if ( routeDescription == "ching toing ping" ) {
transitionName = "ask someone else";
}
return transitionName;
}
}
public void testLeftScenario() throws Exception {
// retrieve the definition
Definition definition = executionService.getLatestDefinition( "the decision process" );
// start a process instance
Map variables = new HashMap();
variables.put( "route description", "take a left" );
InvocationLog invocationLog = executionService.startProcessInstance( "testrunner", definition.getId(), variables );
ProcessInstanceImpl pi = (ProcessInstanceImpl) invocationLog.getProcessInstance();
// check if the decision had its effect
assertEquals( "inside the left street", pi.getRoot().getState().getName() );
}
public void testRightScenario() throws Exception {
// retrieve the definition
Definition definition = executionService.getLatestDefinition( "the decision process" );
// start a process instance
Map variables = new HashMap();
variables.put( "route description", "take a right" );
InvocationLog invocationLog = executionService.startProcessInstance( "testrunner", definition.getId(), variables );
ProcessInstanceImpl pi = (ProcessInstanceImpl) invocationLog.getProcessInstance();
// check if the decision had its effect
assertEquals( "inside the right street", pi.getRoot().getState().getName() );
}
public void testNonExistingTransitionName() throws Exception {
// retrieve the definition
Definition definition = executionService.getLatestDefinition( "the decision process" );
// start a process instance
Map variables = new HashMap();
variables.put( "route description", "ching toing ping" );
try {
ProcessInstanceImpl pi = (ProcessInstanceImpl) executionService.startProcessInstance( "testrunner", definition.getId(), variables );
fail( "the given route description should have resulted in transition-name 'ask someone else' which should have resulted in an IllegalTransitionException" );
} catch (IllegalTransitionException e) {
// OK
}
}
public void testNullTransitionName() throws Exception {
// retrieve the definition
Definition definition = executionService.getLatestDefinition( "the decision process" );
// start a process instance
try {
ProcessInstanceImpl pi = (ProcessInstanceImpl) executionService.startProcessInstance( "testrunner", definition.getId() );
fail( "without a route description, a null transition-name should have been returned which should have resulted in an IllegalTransitionException" );
} catch (IllegalTransitionException e) {
// OK
}
}
private static Log log = LogFactory.getLog(DecisionTest.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -