⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statetest.java

📁 一个java工作流引擎
💻 JAVA
字号:
package org.jbpm.service;

import java.util.*;
import junit.framework.*;
import org.jbpm.*;
import org.jbpm.model.definition.*;
import org.jbpm.model.execution.Token;
import org.jbpm.model.execution.impl.*;
import org.jbpm.model.log.*;

public class StateTest extends TestCase {
  
  public static TestHelper helper = new TestHelper();
  private ExecutionService executionService = helper.getExecutionService();
  
  static {
    helper.deployProcess( "process/stateprocess.xml" );
  }
  
  public void testStateProcess() throws Exception {
    // retrieve the definition
    Definition definition = executionService.getLatestDefinition( "the state process" );
    
    // start a process instance
    InvocationLog invocationLog = executionService.startProcessInstance( "testrunner", definition.getId() );
    ProcessInstanceImpl pi = (ProcessInstanceImpl) invocationLog.getProcessInstance();
    Long tokenId = pi.getRoot().getId();
    Long piId = pi.getId();
    Map variables = executionService.getVariables( tokenId );
    
    // check the state of the process instance
    assertEquals( "testrunner", pi.getRoot().getActorId() );
    assertEquals( "testrunner", variables.get( "initiator" ) );
    assertEquals( "only state", pi.getRoot().getState().getName() );
    assertTrue( ( pi.getRoot().getChildren() == null ) || ( pi.getRoot().getChildren().size()==0 ) );
    assertNotNull( pi.getRoot().getStart() );
    assertEquals( pi.getStart(), pi.getRoot().getStart() );
    assertNull( pi.getRoot().getEnd() );
    assertNull( pi.getRoot().getParent() );
    assertEquals( "the state process", pi.getDefinition().getName() );
    
    // check the tasklist
    Collection tasks = executionService.getTaskList("testrunner", null );
    assertEquals( 1, tasks.size() );
    Token token = (Token) tasks.iterator().next();
    assertEquals( pi.getRoot().getId(), token.getId() );

    // signal the end of the only state
    executionService.endOfState( "testrunner", tokenId );
    Assembler assembler = new PropertyAssembler( "root.children[ITERATE][RECURSIVE]" );
    pi = (ProcessInstanceImpl) executionService.getProcessInstance( piId, assembler );
    variables = executionService.getVariables( tokenId );
    
    // check the results
    String actorId = pi.getRoot().getActorId();
    assertNull( pi.getRoot().getActorId() );
    assertEquals( "testrunner", variables.get( "initiator" ) );
    assertNull( pi.getRoot().getState() );
    assertTrue( ( pi.getRoot().getChildren() == null ) || ( pi.getRoot().getChildren().size()==0 ) );
    assertNotNull( pi.getRoot().getStart() );
    assertEquals( pi.getStart(), pi.getRoot().getStart() );
    assertNotNull( pi.getRoot().getEnd() );
    assertEquals( pi.getEnd(), pi.getRoot().getEnd() );
    assertNull( pi.getRoot().getParent() );
    assertEquals( "the state process", pi.getDefinition().getName() );
    
    // check that the tasklist is empty now
    assertEquals( 0, executionService.getTaskList("testrunner", null ).size() );
    
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -