executionpersistencetest.java

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

JAVA
72
字号
package org.jbpm.model.execution.impl;

import java.util.*;
import org.jbpm.*;
import org.jbpm.model.definition.impl.*;
import org.jbpm.persistence.hibernate.*;
import junit.framework.*;

public class ExecutionPersistenceTest extends TestCase {

  static { TestHelper.initLogging(); }
  
  private static boolean isDefinitionLoaded = false;
  private static Long processInstanceId = null;
  
  private HibernateTestHelper hibernate = null;
  private ProcessInstanceImpl processInstance = null;
  
  public void setUp() throws Exception {
    hibernate = new HibernateTestHelper();
    
    if ( ! isDefinitionLoaded ) {
      loadProcessInstance(); 
    }
    
    hibernate.startTransaction();
    processInstance = (ProcessInstanceImpl) hibernate.getSession().load( ProcessInstanceImpl.class, processInstanceId );
  }
  
  public void tearDown() throws Exception {
    hibernate.commitTransaction();
  }
  
  private void loadProcessInstance() throws Exception {
    DefinitionImpl definition = new DefinitionImpl("holiday");
    ProcessInstanceImpl processInstance = new ProcessInstanceImpl( definition );
    
    TokenImpl root = (TokenImpl) processInstance.getRoot();
    new TokenImpl( root, "child one" );
    new TokenImpl( root, "child two" );
    root.setActorId( "root swimlane id" );
    new VariableInstanceImpl( "variable one", root, DefaultType.STRING );
    new VariableInstanceImpl( "variable two", root, DefaultType.LONG );
    new VariableInstanceImpl( "variable three", root, DefaultType.DOUBLE );
    
    // save the definition using the persistence manager
    hibernate.startTransaction();
    hibernate.getSession().save( definition );
    hibernate.getSession().save( processInstance );
    hibernate.commitTransaction();
    
    processInstanceId = processInstance.getId();
  }
  
  public void testProcessInstance() {
    TokenImpl root = (TokenImpl)processInstance.getRoot();

    assertEquals( "holiday", processInstance.getDefinition().getName() );
    assertEquals( "root", root.getName() );
    assertEquals( "root swimlane id", root.getActorId() );

    Collection retrievedChildNames = root.getChildren().keySet();
    Collection expectedChildNames = new HashSet( Arrays.asList( new String[]{ "child one", "child two" } ) );
    assertEquals( expectedChildNames, retrievedChildNames );

    Collection retrievedVariableNames = root.getVariableInstances().keySet();
    Collection expectedVariableNames = new HashSet( Arrays.asList( new String[]{ "variable one", "variable two", "variable three" } ) );
    assertEquals( expectedVariableNames, retrievedVariableNames );
  }
  
}

⌨️ 快捷键说明

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