jBPM distribution 6.0.0.CR4-Pre1

org.jbpm.test
Class JbpmJUnitBaseTestCase

java.lang.Object
  extended by org.junit.Assert
      extended by org.jbpm.test.JbpmJUnitBaseTestCase

public abstract class JbpmJUnitBaseTestCase
extends org.junit.Assert

Base test case class that shall be used for jBPM related tests. It provides four sections:

JUnit life cycle methods:
* setUp: executed @Before and configures data source and EntityManagerFactory, cleans up Singleton's session id
* tearDown: executed @After and clears out history, closes EntityManagerFactory and data source, disposes RuntimeEngine's and RuntimeManager

KnowledgeBase and KnowledgeSession management methods * createRuntimeManager creates RuntimeManager for gives set of assets and selected strategy
* disposeRuntimeManager disposes RuntimeManager currently active in the scope of test
* getRuntimeEngine creates new RuntimeEngine for given context

Assertions
Set of useful methods to assert process instance at various stages.
Helper methods
* getDs - returns currently configured data source
* getEmf - returns currently configured EntityManagerFactory
* getTestWorkItemHandler - returns test work item handler that might be registered in addition to what is registered by default
* clearHistory - clears history log
* setupPoolingDataSource - sets up data source


Nested Class Summary
static class JbpmJUnitBaseTestCase.Strategy
          Currently supported RuntimeEngine strategies
protected static class JbpmJUnitBaseTestCase.TestWorkItemHandler
           
 
Field Summary
protected  List<RuntimeEngine> activeEngines
           
protected  RuntimeManager manager
           
protected  boolean sessionPersistence
           
protected  boolean setupDataSource
           
 
Constructor Summary
JbpmJUnitBaseTestCase()
          The most simple test case configuration: does NOT initialize data source does NOT configure session persistence This is usually used for in memory process management, without human task interaction.
JbpmJUnitBaseTestCase(boolean setupDataSource, boolean sessionPersistence)
          Allows to explicitly configure persistence and data source.
JbpmJUnitBaseTestCase(boolean setupDataSource, boolean sessionPersistence, String persistenceUnitName)
          Same as JbpmJUnitBaseTestCase(boolean, boolean) but allows to use another persistence unit name.
 
Method Summary
 void assertNodeActive(long processInstanceId, KieSession ksession, String... name)
           
 void assertNodeExists(ProcessInstance process, String... nodeNames)
           
 void assertNodeTriggered(long processInstanceId, String... nodeNames)
           
 void assertNumOfIncommingConnections(ProcessInstance process, String nodeName, int num)
           
 void assertNumOfOutgoingConnections(ProcessInstance process, String nodeName, int num)
           
 void assertPackageNameEquals(ProcessInstance process, String packageName)
           
 void assertProcessInstanceAborted(long processInstanceId, KieSession ksession)
           
 void assertProcessInstanceActive(long processInstanceId, KieSession ksession)
           
 void assertProcessInstanceCompleted(long processInstanceId, KieSession ksession)
           
 void assertProcessNameEquals(ProcessInstance process, String name)
           
 void assertProcessVarExists(ProcessInstance process, String... processVarNames)
           
 void assertVersionEquals(ProcessInstance process, String version)
           
protected static void cleanupSingletonSessionId()
           
protected  void clearHistory()
           
protected  RuntimeManager createRuntimeManager(JbpmJUnitBaseTestCase.Strategy strategy, Map<String,ResourceType> resources)
          Creates default configuration of RuntimeManager with given strategy and all resources being added to knowledge base.
protected  RuntimeManager createRuntimeManager(JbpmJUnitBaseTestCase.Strategy strategy, Map<String,ResourceType> resources, org.kie.internal.runtime.manager.RuntimeEnvironment environment, String identifier)
          The lowest level of creation of RuntimeManager that expects to get RuntimeEnvironment to be given as argument.
protected  RuntimeManager createRuntimeManager(JbpmJUnitBaseTestCase.Strategy strategy, Map<String,ResourceType> resources, String identifier)
          Creates default configuration of RuntimeManager with given strategy and all resources being added to knowledge base.
protected  RuntimeManager createRuntimeManager(JbpmJUnitBaseTestCase.Strategy strategy, String identifier, String... process)
          Creates default configuration of RuntimeManager with given strategy and all processes being added to knowledge base.
protected  RuntimeManager createRuntimeManager(Map<String,ResourceType> resources)
          Creates default configuration of RuntimeManager with SINGLETON strategy and all resources being added to knowledge base.
protected  RuntimeManager createRuntimeManager(Map<String,ResourceType> resources, String identifier)
          Creates default configuration of RuntimeManager with SINGLETON strategy and all resources being added to knowledge base.
protected  RuntimeManager createRuntimeManager(String... process)
          Creates default configuration of RuntimeManager with SINGLETON strategy and all processes being added to knowledge base.
protected  void disposeRuntimeManager()
          Disposes currently active (in scope of a test) RuntimeManager together with all active RuntimeEngine's that were created (in scope of a test).
protected  DataSource getDs()
           
protected  javax.persistence.EntityManagerFactory getEmf()
           
protected  RuntimeEngine getRuntimeEngine()
          Returns new RuntimeEngine built from the manager of this test case.
protected  RuntimeEngine getRuntimeEngine(Context<?> context)
          Returns new RuntimeEngine built from the manager of this test case.
protected  JbpmJUnitBaseTestCase.TestWorkItemHandler getTestWorkItemHandler()
           
 Object getVariableValue(String name, long processInstanceId, KieSession ksession)
          Retrieves value of the variable given by name from process instance given by processInstanceId using given session.
 void setUp()
           
protected  bitronix.tm.resource.jdbc.PoolingDataSource setupPoolingDataSource()
           
 void tearDown()
           
 
Methods inherited from class org.junit.Assert
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

setupDataSource

protected boolean setupDataSource

sessionPersistence

protected boolean sessionPersistence

manager

protected RuntimeManager manager

activeEngines

protected List<RuntimeEngine> activeEngines
Constructor Detail

JbpmJUnitBaseTestCase

public JbpmJUnitBaseTestCase()
The most simple test case configuration: This is usually used for in memory process management, without human task interaction.


JbpmJUnitBaseTestCase

public JbpmJUnitBaseTestCase(boolean setupDataSource,
                             boolean sessionPersistence)
Allows to explicitly configure persistence and data source. This is the most common way of bootstrapping test cases for jBPM.
Use following configuration to execute in memory process management with human tasks persistence
super(true, false);
Use following configuration to execute in persistent process management with human tasks persistence
super(true, true);
This will use default persistence unit name org.jbpm.persistence.jpa

Parameters:
setupDataSource - - true to configure data source under JNDI name: jdbc/jbpm-ds
sessionPersistence - - configures RuntimeEngine to be with JPA persistence enabled

JbpmJUnitBaseTestCase

public JbpmJUnitBaseTestCase(boolean setupDataSource,
                             boolean sessionPersistence,
                             String persistenceUnitName)
Same as JbpmJUnitBaseTestCase(boolean, boolean) but allows to use another persistence unit name.

Parameters:
setupDataSource - - true to configure data source under JNDI name: jdbc/jbpm-ds
sessionPersistence - - configures RuntimeEngine to be with JPA persistence enabled
persistenceUnitName - - custom persistence unit name
Method Detail

setUp

public void setUp()
           throws Exception
Throws:
Exception

tearDown

public void tearDown()
              throws Exception
Throws:
Exception

createRuntimeManager

protected RuntimeManager createRuntimeManager(String... process)
Creates default configuration of RuntimeManager with SINGLETON strategy and all processes being added to knowledge base.
There should be only one RuntimeManager created during single test.

Parameters:
process - - processes that shall be added to knowledge base
Returns:
new instance of RuntimeManager

createRuntimeManager

protected RuntimeManager createRuntimeManager(JbpmJUnitBaseTestCase.Strategy strategy,
                                              String identifier,
                                              String... process)
Creates default configuration of RuntimeManager with given strategy and all processes being added to knowledge base.
There should be only one RuntimeManager created during single test.

Parameters:
strategy - - selected strategy of those that are supported
identifier - - identifies the runtime manager
process - - processes that shall be added to knowledge base
Returns:
new instance of RuntimeManager

createRuntimeManager

protected RuntimeManager createRuntimeManager(Map<String,ResourceType> resources)
Creates default configuration of RuntimeManager with SINGLETON strategy and all resources being added to knowledge base.
There should be only one RuntimeManager created during single test.

Parameters:
resources - - resources (processes, rules, etc) that shall be added to knowledge base
Returns:
new instance of RuntimeManager

createRuntimeManager

protected RuntimeManager createRuntimeManager(Map<String,ResourceType> resources,
                                              String identifier)
Creates default configuration of RuntimeManager with SINGLETON strategy and all resources being added to knowledge base.
There should be only one RuntimeManager created during single test.

Parameters:
resources - - resources (processes, rules, etc) that shall be added to knowledge base
identifier - - identifies the runtime manager
Returns:
new instance of RuntimeManager

createRuntimeManager

protected RuntimeManager createRuntimeManager(JbpmJUnitBaseTestCase.Strategy strategy,
                                              Map<String,ResourceType> resources)
Creates default configuration of RuntimeManager with given strategy and all resources being added to knowledge base.
There should be only one RuntimeManager created during single test.

Parameters:
strategy - - selected strategy of those that are supported
resources - - resources that shall be added to knowledge base
Returns:
new instance of RuntimeManager

createRuntimeManager

protected RuntimeManager createRuntimeManager(JbpmJUnitBaseTestCase.Strategy strategy,
                                              Map<String,ResourceType> resources,
                                              String identifier)
Creates default configuration of RuntimeManager with given strategy and all resources being added to knowledge base.
There should be only one RuntimeManager created during single test.

Parameters:
strategy - - selected strategy of those that are supported
resources - - resources that shall be added to knowledge base
identifier - - identifies the runtime manager
Returns:
new instance of RuntimeManager

createRuntimeManager

protected RuntimeManager createRuntimeManager(JbpmJUnitBaseTestCase.Strategy strategy,
                                              Map<String,ResourceType> resources,
                                              org.kie.internal.runtime.manager.RuntimeEnvironment environment,
                                              String identifier)
The lowest level of creation of RuntimeManager that expects to get RuntimeEnvironment to be given as argument. It does not assume any particular configuration as it's considered manual creation that allows to configure every single piece of RuntimeManager.
Use this only when you know what you do!

Parameters:
strategy - - selected strategy of those that are supported
resources - - resources that shall be added to knowledge base
environment - - runtime environment used for RuntimeManager creation
identifier - - identifies the runtime manager
Returns:
new instance of RuntimeManager

disposeRuntimeManager

protected void disposeRuntimeManager()
Disposes currently active (in scope of a test) RuntimeManager together with all active RuntimeEngine's that were created (in scope of a test). Usual use case is to simulate system shutdown.


getRuntimeEngine

protected RuntimeEngine getRuntimeEngine()
Returns new RuntimeEngine built from the manager of this test case. It uses EmptyContext that is suitable for following strategies:

Returns:
new RuntimeEngine instance
See Also:
getRuntimeEngine(Context)

getRuntimeEngine

protected RuntimeEngine getRuntimeEngine(Context<?> context)
Returns new RuntimeEngine built from the manager of this test case. Common use case is to maintain same session for process instance and thus ProcessInstanceIdContext shall be used.

Parameters:
context - - instance of the context that shall be used to create RuntimeManager
Returns:
new RuntimeEngine instance

getVariableValue

public Object getVariableValue(String name,
                               long processInstanceId,
                               KieSession ksession)
Retrieves value of the variable given by name from process instance given by processInstanceId using given session.

Parameters:
name - - name of the variable
processInstanceId - - id of process instance
ksession - - ksession used to retrieve the value
Returns:
returns variable value or null if there is no such variable

assertProcessInstanceCompleted

public void assertProcessInstanceCompleted(long processInstanceId,
                                           KieSession ksession)

assertProcessInstanceAborted

public void assertProcessInstanceAborted(long processInstanceId,
                                         KieSession ksession)

assertProcessInstanceActive

public void assertProcessInstanceActive(long processInstanceId,
                                        KieSession ksession)

assertNodeActive

public void assertNodeActive(long processInstanceId,
                             KieSession ksession,
                             String... name)

assertNodeTriggered

public void assertNodeTriggered(long processInstanceId,
                                String... nodeNames)

assertProcessVarExists

public void assertProcessVarExists(ProcessInstance process,
                                   String... processVarNames)

assertNodeExists

public void assertNodeExists(ProcessInstance process,
                             String... nodeNames)

assertNumOfIncommingConnections

public void assertNumOfIncommingConnections(ProcessInstance process,
                                            String nodeName,
                                            int num)

assertNumOfOutgoingConnections

public void assertNumOfOutgoingConnections(ProcessInstance process,
                                           String nodeName,
                                           int num)

assertVersionEquals

public void assertVersionEquals(ProcessInstance process,
                                String version)

assertProcessNameEquals

public void assertProcessNameEquals(ProcessInstance process,
                                    String name)

assertPackageNameEquals

public void assertPackageNameEquals(ProcessInstance process,
                                    String packageName)

getEmf

protected javax.persistence.EntityManagerFactory getEmf()

getDs

protected DataSource getDs()

setupPoolingDataSource

protected bitronix.tm.resource.jdbc.PoolingDataSource setupPoolingDataSource()

clearHistory

protected void clearHistory()

getTestWorkItemHandler

protected JbpmJUnitBaseTestCase.TestWorkItemHandler getTestWorkItemHandler()

cleanupSingletonSessionId

protected static void cleanupSingletonSessionId()

jBPM distribution 6.0.0.CR4-Pre1

Copyright © 2001-2013 JBoss by Red Hat. All Rights Reserved.