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

📄 delegationinstantiationtest.java

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

import java.io.*;
import org.jbpm.*;
import org.jbpm.delegation.*;
import org.jbpm.util.io.*;
import junit.framework.*;

public class DelegationInstantiationTest extends TestCase {
  
  private DefinitionImpl definition = null;
  
  public static class InnerDelegationClass implements ActionHandler {
		public void execute(ExecutionContext executionContext) {
		}
  }

	public void setUp() throws Exception {
    // create a definition with a 2 files that represent classes
    definition = new DefinitionImpl();
    definition.setName( "instantiation test process" );
    
    FileImpl file = new FileImpl( definition.getId(), "classes/org/jbpm/model/definition/impl/TestActionHandler.class", getFileInTestClassPath( "org/jbpm/model/definition/impl/TestActionHandler.class" ) );
    file = new FileImpl( definition.getId(), "classes/org/jbpm/model/definition/impl/DelegationInstantiationTest$InnerDelegationClass.class", getFileInTestClassPath( "org/jbpm/model/definition/impl/DelegationInstantiationTest$InnerDelegationClass.class" ) );
  }

  private byte[] getFileInTestClassPath(String resource) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    IoUtil.transfer( DelegationInstantiationTest.class.getClassLoader().getResourceAsStream( resource ), baos );
		return baos.toByteArray();
	}

  public void testInstantiation() {
    DelegationImpl normalDelegation = new DelegationImpl( definition, "org.jbpm.model.definition.impl.TestActionHandler" );
    Object object = normalDelegation.instantiate();
    assertNotNull( object );
    assertEquals( TestActionHandler.class, object.getClass() );
  }

  public void testConfigurationInstantiation() {
    DelegationImpl configurableDelegation = new DelegationImpl( definition, "org.jbpm.model.definition.impl.ConfigurableActionHandler" );
    configurableDelegation.setConfiguration( "test configuration text" );
    ConfigurableActionHandler configurableActionHandler = (ConfigurableActionHandler) configurableDelegation.instantiate();
    assertNotNull( configurableActionHandler );
    assertEquals( "test configuration text", configurableActionHandler.getConfiguration() );
  }

  public void testInnerClassInstantiation() {
    DelegationImpl innerDelegation = new DelegationImpl( definition, "org.jbpm.model.definition.impl.DelegationInstantiationTest$InnerDelegationClass" );
    Object object = innerDelegation.instantiate();
    assertNotNull( object );
    assertEquals( InnerDelegationClass.class, object.getClass() );
  }

  public void testClassNotFoundException() {
    DelegationImpl normalDelegation = new DelegationImpl( definition, "org.jbpm.model.definition.impl.NonExistingClass" );
    try {
			normalDelegation.instantiate();
      fail();
		} catch (DefinitionException e) {
      assertEquals( ClassNotFoundException.class, e.getCause().getClass() );
		}
  }
}

⌨️ 快捷键说明

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