📄 testbasicflow.java
字号:
/** * $Source: /home/ws/rz65/CVS-Repository/WorkflowProjects/JBPM-Demo/src/test/testjbpmdemo/testbasic/TestBasicFlow.java,v $ * $Revision: 1.2 $ * $Date: 2005/03/09 18:45:24 $ * $Author: rz65 $ * * Copyright (c) 2005 Universitaet Karlsruhe (TH) / Rechenzentrum (RZ-UNI-UKA) * * RZ-UNI-KA makes no representations or warranties about the suitability * of this software, either express or implied, including but not limited * to the implied warranties of merchantability, fitness for a particular * purpose, or non-infringement. RZ-UNI-KA shall not be liable for any * damages as a result of using, modifying or distributing this software * or its derivatives. */package testjbpmdemo.testbasic;import testjbpmdemo.testbasic.AbstractBasicTestCase;import junit.framework.Test;import junit.framework.TestSuite;import junit.textui.TestRunner;import org.jbpm.context.def.ContextDefinition;import org.jbpm.graph.def.Action;import org.jbpm.graph.def.GraphElement;import org.jbpm.graph.def.Node;import org.jbpm.graph.def.ProcessDefinition;import org.jbpm.graph.def.Transition;import org.jbpm.graph.exe.ProcessInstance;import org.jbpm.graph.exe.Token;import org.jbpm.jpdl.xml.JpdlXmlReader;import org.jbpm.jpdl.xml.JpdlXmlWriter;import org.jbpm.logging.def.LoggingDefinition;import java.util.Collection;import java.util.Date;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;/** * A test case for the process definition. * * <p> * * @version $Revision: 1.2 $ * @author mailto:harald.meyer@rz.uni-karlsruhe.de */public class TestBasicFlow extends AbstractBasicTestCase { /** * Builds a test case instance. * * @param name * The name of the case. */ public TestBasicFlow(String name) { super(name); } /** * The stand-alone run main method. * * @param args * The run-time arguments (ignored) */ public static void main(String[] args) { TestRunner.run(suite()); } /** * Creates a test suite from this class. * * @return The test suite that covers all test... methods */ public static Test suite() { return new TestSuite(TestBasicFlow.class); } protected void setUp() throws Exception { String mn = "setUp"; String resourceName = getDefaultXMLResourcePath(); debug(mn, "resource name: " + resourceName); setUpProcessDefinition = JpdlXmlReader.parseFromResource(resourceName); debug(mn, "process definition: " + setUpProcessDefinition); setUpProcessInstance = new ProcessInstance(setUpProcessDefinition); debug(mn, "process instance: " + setUpProcessInstance); setUpToken = setUpProcessInstance.getRootToken(); debug(mn, "root token: " + setUpToken); } private ProcessDefinition setUpProcessDefinition; private ProcessInstance setUpProcessInstance; private Token setUpToken; /** * Check the set-up */ public void testSetUp() { assertNotNull("process definition must not be null.", setUpProcessDefinition); assertNotNull("process instance must not be null.", setUpProcessInstance); assertNotNull("token must not be null.", setUpToken); } public void testMainScenario() { String mn = "testMainScenario"; // first check if the main path of execution is in the // start state of the process definition assertEquals(setUpProcessDefinition.getStartState(), setUpToken .getNode()); // now, send a signal to the process instance named 'bell rings' dumpToken("before bell rings"); setUpToken.signal("bell rings"); dumpToken("after bell rings"); // the signal triggered the execution of the process instance // and put the token in the 'go open door' state // ...let's check that assertEquals(setUpProcessDefinition.getNode("go open door"), setUpToken .getNode()); // in this test, we just send the signals one by one and // go through a complete scenario. in a real world application // the process instance is persisted inbetween the signals. // suppose we have mounted a sensor on the door so that the next // signal sent to the process instance is 'door opened' setUpToken.signal("door opened"); dumpToken("after door opened"); // now execution has moved to the 'say hello' state, where the // process instance is waiting for the an answer assertEquals(setUpProcessDefinition.getNode("say hello"), setUpToken .getNode()); // now, we can signal to the process that we have received an answer setUpToken.signal("received answer"); dumpToken("after received answer"); Token child1 = setUpToken.getChild("myfork1"); debug(mn,"token child1: " + child1); Token child2 = setUpToken.getChild("myfork2"); child1.signal(); debug(mn,"token child2: " + child2); child2.signal(); // now execution is in 'close door' and it's waiting for the sensor assertEquals(setUpProcessDefinition.getNode("close door"), setUpToken .getNode()); // now, we can signal to the process that we have received an answer setUpToken.signal("door closed"); dumpToken("after door closed"); // now, the process execution is done. assertTrue(setUpProcessInstance.hasEnded()); } private void dumpToken(String msg) { String mn = "dumpToken " + msg; debug(mn, "id: " + setUpToken.getId()); debug(mn, "name: " + setUpToken.getName()); debug(mn, "full name: " + setUpToken.getFullName()); debug(mn, "node: " + setUpToken.getNode()); debug(mn, "node: " + setUpToken.getNode()); debug(mn, "parent: " + setUpToken.getParent()); debug(mn, "children: " + setUpToken.getChildren()); //debug(mn, "has active children: " + setUpToken.hasActiveChildren()); debug(mn, "has ended: " + setUpToken.hasEnded()); debug(mn, "has parent: " + setUpToken.hasParent()); debug(mn, "is parent reactivated: " + setUpToken.isParentReactivated()); debug(mn, "is root: " + setUpToken.isRoot()); debug(mn, "is terminated implicitly: " + setUpToken.isTerminatedImplicitly()); debug(mn, "is termination implicit: " + setUpToken.isTerminationImplicit()); } /** * Test the XML writer result. */ public void testXmlWriterResults() { String mn="testXmlWriterResults"; String s = JpdlXmlWriter.toString(setUpProcessDefinition); assertNotNull("writer result must not be null.",s); debug(mn,"writer result length: " + s.length()); debug(mn,"result: " + s); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -