Package org.jbpm.test
Class JbpmJUnitBaseTestCase
- java.lang.Object
-
- org.jbpm.test.AbstractBaseTest
-
- org.jbpm.test.JbpmJUnitBaseTestCase
-
public abstract class JbpmJUnitBaseTestCase extends AbstractBaseTest
Base test case class that shall be used for jBPM related tests. It provides four sections:- JUnit life cycle methods
- Knowledge Base and KnowledgeSession management methods
- Assertions
- Helper methods
* setUp: executed @Before and configures data source andEntityManagerFactory
, cleans up Singleton's session id
* tearDown: executed @After and clears out history, closesEntityManagerFactory
and data source, disposesRuntimeEngine
's andRuntimeManager
KnowledgeBase and KnowledgeSession management methods * createRuntimeManager createsRuntimeManager
for gives set of assets and selected strategy
* disposeRuntimeManager disposesRuntimeManager
currently active in the scope of test
* getRuntimeEngine creates newRuntimeEngine
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 configuredEntityManagerFactory
* 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
Nested Classes Modifier and Type Class Description static class
JbpmJUnitBaseTestCase.Strategy
Currently supported RuntimeEngine strategiesprotected static class
JbpmJUnitBaseTestCase.TestWorkItemHandler
-
Field Summary
Fields Modifier and Type Field Description protected Set<org.kie.api.runtime.manager.RuntimeEngine>
activeEngines
protected List<org.kie.api.event.rule.AgendaEventListener>
customAgendaListeners
protected Map<String,Object>
customEnvironmentEntries
protected Map<String,org.kie.api.runtime.process.WorkItemHandler>
customHandlers
protected List<org.kie.api.event.process.ProcessEventListener>
customProcessListeners
protected List<org.kie.api.task.TaskLifeCycleEventListener>
customTaskListeners
protected org.kie.api.runtime.manager.RuntimeManager
manager
static String[]
processStateName
protected boolean
sessionPersistence
protected boolean
setupDataSource
static String[]
txStateName
protected org.kie.api.task.UserGroupCallback
userGroupCallback
-
Fields inherited from class org.jbpm.test.AbstractBaseTest
DATASOURCE_NAME
-
-
Constructor Summary
Constructors Constructor Description 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 asJbpmJUnitBaseTestCase(boolean, boolean)
but allows to use another persistence unit name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addAgendaEventListener(org.kie.api.event.rule.AgendaEventListener listener)
void
addEnvironmentEntry(String name, Object value)
void
addProcessEventListener(org.kie.api.event.process.ProcessEventListener listener)
void
addTaskEventListener(org.kie.api.task.TaskLifeCycleEventListener listener)
void
addWorkItemHandler(String name, org.kie.api.runtime.process.WorkItemHandler handler)
void
assertNodeActive(long processInstanceId, org.kie.api.runtime.KieSession ksession, String... name)
void
assertNodeExists(org.kie.api.runtime.process.ProcessInstance process, String... nodeNames)
void
assertNodeTriggered(long processInstanceId, String... nodeNames)
void
assertNumOfIncommingConnections(org.kie.api.runtime.process.ProcessInstance process, String nodeName, int num)
void
assertNumOfOutgoingConnections(org.kie.api.runtime.process.ProcessInstance process, String nodeName, int num)
void
assertPackageNameEquals(org.kie.api.runtime.process.ProcessInstance process, String packageName)
void
assertProcessInstanceAborted(long processInstanceId)
Asserts that process instance is aborted.void
assertProcessInstanceAborted(long processInstanceId, org.kie.api.runtime.KieSession ksession)
Deprecated.This method does not check the actual state of process instance.void
assertProcessInstanceActive(long processInstanceId)
Asserts that process instance is active.void
assertProcessInstanceActive(long processInstanceId, org.kie.api.runtime.KieSession ksession)
Asserts that process instance is active.void
assertProcessInstanceCompleted(long processInstanceId)
Asserts that process instance is completed.void
assertProcessInstanceCompleted(long processInstanceId, org.kie.api.runtime.KieSession ksession)
Deprecated.This method does not check the actual state of process instance.void
assertProcessInstanceNotActive(long processInstanceId, org.kie.api.runtime.KieSession ksession)
Asserts that process instance is not active.void
assertProcessNameEquals(org.kie.api.runtime.process.ProcessInstance process, String name)
void
assertProcessVarExists(org.kie.api.runtime.process.ProcessInstance process, String... processVarNames)
void
assertVersionEquals(org.kie.api.runtime.process.ProcessInstance process, String version)
protected static void
cleanupSingletonSessionId()
protected void
clearCustomRegistry()
protected void
clearHistory()
protected org.kie.api.runtime.manager.RuntimeManager
createRuntimeManager(String... process)
Creates default configuration ofRuntimeManager
with SINGLETON strategy and allprocesses
being added to knowledge base.protected org.kie.api.runtime.manager.RuntimeManager
createRuntimeManager(Map<String,org.kie.api.io.ResourceType> resources)
Creates default configuration ofRuntimeManager
with SINGLETON strategy and allresources
being added to knowledge base.protected org.kie.api.runtime.manager.RuntimeManager
createRuntimeManager(Map<String,org.kie.api.io.ResourceType> resources, String identifier)
Creates default configuration ofRuntimeManager
with SINGLETON strategy and allresources
being added to knowledge base.protected org.kie.api.runtime.manager.RuntimeManager
createRuntimeManager(JbpmJUnitBaseTestCase.Strategy strategy, String identifier, String... process)
Creates default configuration ofRuntimeManager
with givenstrategy
and allprocesses
being added to knowledge base.protected org.kie.api.runtime.manager.RuntimeManager
createRuntimeManager(JbpmJUnitBaseTestCase.Strategy strategy, Map<String,org.kie.api.io.ResourceType> resources)
Creates default configuration ofRuntimeManager
with givenstrategy
and allresources
being added to knowledge base.protected org.kie.api.runtime.manager.RuntimeManager
createRuntimeManager(JbpmJUnitBaseTestCase.Strategy strategy, Map<String,org.kie.api.io.ResourceType> resources, String identifier)
Creates default configuration ofRuntimeManager
with givenstrategy
and allresources
being added to knowledge base.protected org.kie.api.runtime.manager.RuntimeManager
createRuntimeManager(JbpmJUnitBaseTestCase.Strategy strategy, Map<String,org.kie.api.io.ResourceType> resources, org.kie.api.runtime.manager.RuntimeEnvironment environment, String identifier)
The lowest level of creation ofRuntimeManager
that expects to getRuntimeEnvironment
to be given as argument.protected void
disposeRuntimeManager()
Disposes currently active (in scope of a test)RuntimeManager
together with all activeRuntimeEngine
's that were created (in scope of a test).List<String>
getActiveNodesInProcessInstance(org.kie.api.runtime.KieSession ksession, long processInstanceId)
Collection<org.kie.api.runtime.process.ProcessInstance>
getActiveProcesses(org.kie.api.runtime.KieSession ksession)
protected DataSource
getDs()
protected javax.persistence.EntityManagerFactory
getEmf()
protected org.drools.core.audit.WorkingMemoryInMemoryLogger
getInMemoryLogger()
protected org.kie.api.runtime.manager.audit.AuditService
getLogService()
protected org.kie.api.runtime.manager.RuntimeEngine
getRuntimeEngine()
Returns newRuntimeEngine
built from the manager of this test case.protected org.kie.api.runtime.manager.RuntimeEngine
getRuntimeEngine(org.kie.api.runtime.manager.Context<?> context)
Returns newRuntimeEngine
built from the manager of this test case.protected JbpmJUnitBaseTestCase.TestWorkItemHandler
getTestWorkItemHandler()
Object
getVariableValue(String name, long processInstanceId, org.kie.api.runtime.KieSession ksession)
Retrieves value of the variable given byname
from process instance given byprocessInstanceId
using given session.void
setPersistenceProperty(String name, Object value)
void
setUp()
void
tearDown()
-
Methods inherited from class org.jbpm.test.AbstractBaseTest
configure, getDataSourceProperties, getJndiDatasourceName, reset, setupPoolingDataSource, setupPoolingDataSource
-
-
-
-
Field Detail
-
setupDataSource
protected boolean setupDataSource
-
sessionPersistence
protected boolean sessionPersistence
-
manager
protected org.kie.api.runtime.manager.RuntimeManager manager
-
userGroupCallback
protected org.kie.api.task.UserGroupCallback userGroupCallback
-
activeEngines
protected Set<org.kie.api.runtime.manager.RuntimeEngine> activeEngines
-
customProcessListeners
protected List<org.kie.api.event.process.ProcessEventListener> customProcessListeners
-
customAgendaListeners
protected List<org.kie.api.event.rule.AgendaEventListener> customAgendaListeners
-
customTaskListeners
protected List<org.kie.api.task.TaskLifeCycleEventListener> customTaskListeners
-
txStateName
public static String[] txStateName
-
processStateName
public static String[] processStateName
-
-
Constructor Detail
-
JbpmJUnitBaseTestCase
public JbpmJUnitBaseTestCase()
The most simple test case configuration:- does NOT initialize data source
- does NOT configure session persistence
-
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 nameorg.jbpm.persistence.jpa
- Parameters:
setupDataSource
- - true to configure data source under JNDI name: jdbc/jbpm-dssessionPersistence
- - configures RuntimeEngine to be with JPA persistence enabled
-
JbpmJUnitBaseTestCase
public JbpmJUnitBaseTestCase(boolean setupDataSource, boolean sessionPersistence, String persistenceUnitName)
Same asJbpmJUnitBaseTestCase(boolean, boolean)
but allows to use another persistence unit name.- Parameters:
setupDataSource
- - true to configure data source under JNDI name: jdbc/jbpm-dssessionPersistence
- - configures RuntimeEngine to be with JPA persistence enabledpersistenceUnitName
- - custom persistence unit name
-
-
Method Detail
-
createRuntimeManager
protected org.kie.api.runtime.manager.RuntimeManager createRuntimeManager(String... process)
Creates default configuration ofRuntimeManager
with SINGLETON strategy and allprocesses
being added to knowledge base.
There should be only oneRuntimeManager
created during single test.- Parameters:
process
- - processes that shall be added to knowledge base- Returns:
- new instance of RuntimeManager
-
createRuntimeManager
protected org.kie.api.runtime.manager.RuntimeManager createRuntimeManager(JbpmJUnitBaseTestCase.Strategy strategy, String identifier, String... process)
Creates default configuration ofRuntimeManager
with givenstrategy
and allprocesses
being added to knowledge base.
There should be only oneRuntimeManager
created during single test.- Parameters:
strategy
- - selected strategy of those that are supportedidentifier
- - identifies the runtime managerprocess
- - processes that shall be added to knowledge base- Returns:
- new instance of RuntimeManager
-
createRuntimeManager
protected org.kie.api.runtime.manager.RuntimeManager createRuntimeManager(Map<String,org.kie.api.io.ResourceType> resources)
Creates default configuration ofRuntimeManager
with SINGLETON strategy and allresources
being added to knowledge base.
There should be only oneRuntimeManager
created during single test.- Parameters:
resources
- - resources (processes, rules, etc) that shall be added to knowledge base- Returns:
- new instance of RuntimeManager
-
createRuntimeManager
protected org.kie.api.runtime.manager.RuntimeManager createRuntimeManager(Map<String,org.kie.api.io.ResourceType> resources, String identifier)
Creates default configuration ofRuntimeManager
with SINGLETON strategy and allresources
being added to knowledge base.
There should be only oneRuntimeManager
created during single test.- Parameters:
resources
- - resources (processes, rules, etc) that shall be added to knowledge baseidentifier
- - identifies the runtime manager- Returns:
- new instance of RuntimeManager
-
createRuntimeManager
protected org.kie.api.runtime.manager.RuntimeManager createRuntimeManager(JbpmJUnitBaseTestCase.Strategy strategy, Map<String,org.kie.api.io.ResourceType> resources)
Creates default configuration ofRuntimeManager
with givenstrategy
and allresources
being added to knowledge base.
There should be only oneRuntimeManager
created during single test.- Parameters:
strategy
- - selected strategy of those that are supportedresources
- - resources that shall be added to knowledge base- Returns:
- new instance of RuntimeManager
-
createRuntimeManager
protected org.kie.api.runtime.manager.RuntimeManager createRuntimeManager(JbpmJUnitBaseTestCase.Strategy strategy, Map<String,org.kie.api.io.ResourceType> resources, String identifier)
Creates default configuration ofRuntimeManager
with givenstrategy
and allresources
being added to knowledge base.
There should be only oneRuntimeManager
created during single test.- Parameters:
strategy
- - selected strategy of those that are supportedresources
- - resources that shall be added to knowledge baseidentifier
- - identifies the runtime manager- Returns:
- new instance of RuntimeManager
-
createRuntimeManager
protected org.kie.api.runtime.manager.RuntimeManager createRuntimeManager(JbpmJUnitBaseTestCase.Strategy strategy, Map<String,org.kie.api.io.ResourceType> resources, org.kie.api.runtime.manager.RuntimeEnvironment environment, String identifier)
The lowest level of creation ofRuntimeManager
that expects to getRuntimeEnvironment
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 ofRuntimeManager
.
Use this only when you know what you do!- Parameters:
strategy
- - selected strategy of those that are supportedresources
- - resources that shall be added to knowledge baseenvironment
- - runtime environment used forRuntimeManager
creationidentifier
- - 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 activeRuntimeEngine
's that were created (in scope of a test). Usual use case is to simulate system shutdown.
-
getRuntimeEngine
protected org.kie.api.runtime.manager.RuntimeEngine getRuntimeEngine()
Returns newRuntimeEngine
built from the manager of this test case. It usesEmptyContext
that is suitable for following strategies:- Singleton
- Request
- Returns:
- new RuntimeEngine instance
- See Also:
getRuntimeEngine(Context)
-
getRuntimeEngine
protected org.kie.api.runtime.manager.RuntimeEngine getRuntimeEngine(org.kie.api.runtime.manager.Context<?> context)
Returns newRuntimeEngine
built from the manager of this test case. Common use case is to maintain same session for process instance and thusProcessInstanceIdContext
shall be used.- Parameters:
context
- - instance of the context that shall be used to createRuntimeManager
- Returns:
- new RuntimeEngine instance
-
getVariableValue
public Object getVariableValue(String name, long processInstanceId, org.kie.api.runtime.KieSession ksession)
Retrieves value of the variable given byname
from process instance given byprocessInstanceId
using given session.- Parameters:
name
- - name of the variableprocessInstanceId
- - id of process instanceksession
- - ksession used to retrieve the value- Returns:
- returns variable value or null if there is no such variable
-
assertProcessInstanceCompleted
@Deprecated public void assertProcessInstanceCompleted(long processInstanceId, org.kie.api.runtime.KieSession ksession)
Deprecated.This method does not check the actual state of process instance. Use eitherassertProcessInstanceCompleted(long)
if session persistence is enabled orassertProcessInstanceNotActive(long, KieSession)
otherwise.
-
assertProcessInstanceAborted
@Deprecated public void assertProcessInstanceAborted(long processInstanceId, org.kie.api.runtime.KieSession ksession)
Deprecated.This method does not check the actual state of process instance. Use eitherassertProcessInstanceAborted(long)
if session persistence is enabled orassertProcessInstanceNotActive(long, KieSession)
otherwise.
-
assertProcessInstanceActive
public void assertProcessInstanceActive(long processInstanceId, org.kie.api.runtime.KieSession ksession)
Asserts that process instance is active. Does not require session persistence to be enabled.- Parameters:
processInstanceId
- id of process instanceksession
-
-
assertProcessInstanceNotActive
public void assertProcessInstanceNotActive(long processInstanceId, org.kie.api.runtime.KieSession ksession)
Asserts that process instance is not active. Does not require session persistence to be enabled.- Parameters:
processInstanceId
- id of process instanceksession
-
-
assertProcessInstanceActive
public void assertProcessInstanceActive(long processInstanceId)
Asserts that process instance is active. Makes use of AuditService which requires persistence to be enabled.- Parameters:
processInstanceId
- id of process instance
-
assertProcessInstanceCompleted
public void assertProcessInstanceCompleted(long processInstanceId)
Asserts that process instance is completed. Makes use of AuditService which requires persistence to be enabled.- Parameters:
processInstanceId
- id of process instance
-
assertProcessInstanceAborted
public void assertProcessInstanceAborted(long processInstanceId)
Asserts that process instance is aborted. Makes use of AuditService which requires persistence to be enabled.- Parameters:
processInstanceId
- id of process instance
-
assertNodeActive
public void assertNodeActive(long processInstanceId, org.kie.api.runtime.KieSession ksession, String... name)
-
assertNodeTriggered
public void assertNodeTriggered(long processInstanceId, String... nodeNames)
-
assertProcessVarExists
public void assertProcessVarExists(org.kie.api.runtime.process.ProcessInstance process, String... processVarNames)
-
assertNodeExists
public void assertNodeExists(org.kie.api.runtime.process.ProcessInstance process, String... nodeNames)
-
assertNumOfIncommingConnections
public void assertNumOfIncommingConnections(org.kie.api.runtime.process.ProcessInstance process, String nodeName, int num)
-
assertNumOfOutgoingConnections
public void assertNumOfOutgoingConnections(org.kie.api.runtime.process.ProcessInstance process, String nodeName, int num)
-
assertVersionEquals
public void assertVersionEquals(org.kie.api.runtime.process.ProcessInstance process, String version)
-
assertProcessNameEquals
public void assertProcessNameEquals(org.kie.api.runtime.process.ProcessInstance process, String name)
-
assertPackageNameEquals
public void assertPackageNameEquals(org.kie.api.runtime.process.ProcessInstance process, String packageName)
-
getEmf
protected javax.persistence.EntityManagerFactory getEmf()
-
getDs
protected DataSource getDs()
-
clearHistory
protected void clearHistory()
-
clearCustomRegistry
protected void clearCustomRegistry()
-
getTestWorkItemHandler
protected JbpmJUnitBaseTestCase.TestWorkItemHandler getTestWorkItemHandler()
-
getLogService
protected org.kie.api.runtime.manager.audit.AuditService getLogService()
-
getInMemoryLogger
protected org.drools.core.audit.WorkingMemoryInMemoryLogger getInMemoryLogger()
-
addProcessEventListener
public void addProcessEventListener(org.kie.api.event.process.ProcessEventListener listener)
-
addAgendaEventListener
public void addAgendaEventListener(org.kie.api.event.rule.AgendaEventListener listener)
-
addTaskEventListener
public void addTaskEventListener(org.kie.api.task.TaskLifeCycleEventListener listener)
-
addWorkItemHandler
public void addWorkItemHandler(String name, org.kie.api.runtime.process.WorkItemHandler handler)
-
cleanupSingletonSessionId
protected static void cleanupSingletonSessionId()
-
getActiveProcesses
public Collection<org.kie.api.runtime.process.ProcessInstance> getActiveProcesses(org.kie.api.runtime.KieSession ksession)
-
-