subprocesstest.java

来自「一个java工作流引擎」· Java 代码 · 共 60 行

JAVA
60
字号
package org.jbpm.service;

import java.util.*;
import junit.framework.*;
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 SubProcessTest extends TestCase {
  
  public static TestHelper helper = new TestHelper();
  private ExecutionService executionService = helper.getExecutionService();
  
  static {
    helper.deployProcess( "process/superprocess.xml" );
    helper.deployProcess( "process/subprocess.xml" );
  }

  public void testSubProcessing() throws Exception {
    // retrieve the definition
    Definition definition = executionService.getLatestDefinition( "the super process" );
    
    // start a process instance
    Map variables = new HashMap();
    variables.put( "a", new Long(2) );
    variables.put( "b", new Long(3) );
    
    InvocationLog invocationLog = executionService.startProcessInstance( "testrunner", definition.getId(), variables );
    ProcessInstanceImpl pi = (ProcessInstanceImpl) invocationLog.getProcessInstance();
    
    Assembler assembler = new PropertyAssembler( "root.subProcessInstance.root" );
    executionService.getProcessInstance( pi.getId(), assembler );

    TokenImpl superRoot = (TokenImpl) pi.getRoot();
    assertNull( superRoot.getActorId() );
    assertEquals( "sub process state", superRoot.getState().getName() );
    assertEquals( new Long(2), superRoot.getVariable( "a" ) );
    assertEquals( new Long(3), superRoot.getVariable( "b" ) );
    assertNull( superRoot.getVariable( "s" ) );
    
    Token subProcessToken = pi.getRoot().getSubProcessInstance().getRoot();
    assertNotNull(subProcessToken);
    assertEquals( "testrunner", subProcessToken.getActorId() );
    assertEquals( "enter third term", subProcessToken.getState().getName() );
    
    variables = new HashMap();
    variables.put( "cc", new Long(33) );
    executionService.endOfState( "testrunner", subProcessToken.getId(), variables );

    assembler = new PropertyAssembler( "root.variables" );
    pi = (ProcessInstanceImpl) executionService.getProcessInstance( pi.getId(), assembler );
    superRoot = (TokenImpl) pi.getRoot();
    assertEquals( new Long(2), superRoot.getVariable( "a" ) );
    assertEquals( new Long(3), superRoot.getVariable( "b" ) );
    assertEquals( new Long(38), superRoot.getVariable( "s" ) );
  }
}

⌨️ 快捷键说明

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