Package org.jbpm.test

Class 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
    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
    • 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
      • customHandlers

        protected Map<String,​org.kie.api.runtime.process.WorkItemHandler> customHandlers
      • 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
      • customEnvironmentEntries

        protected Map<String,​Object> customEnvironmentEntries
      • 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
        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

      • createRuntimeManager

        protected org.kie.api.runtime.manager.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 org.kie.api.runtime.manager.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 org.kie.api.runtime.manager.RuntimeManager createRuntimeManager​(Map<String,​org.kie.api.io.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 org.kie.api.runtime.manager.RuntimeManager createRuntimeManager​(Map<String,​org.kie.api.io.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 org.kie.api.runtime.manager.RuntimeManager createRuntimeManager​(JbpmJUnitBaseTestCase.Strategy strategy,
                                                                                  Map<String,​org.kie.api.io.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 org.kie.api.runtime.manager.RuntimeManager createRuntimeManager​(JbpmJUnitBaseTestCase.Strategy strategy,
                                                                                  Map<String,​org.kie.api.io.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 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 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 org.kie.api.runtime.manager.RuntimeEngine getRuntimeEngine()
        Returns new RuntimeEngine built from the manager of this test case. It uses EmptyContext 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 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,
                                       org.kie.api.runtime.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
      • 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 instance
        ksession -
      • 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 instance
        ksession -
      • 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()
      • clearHistory

        protected void clearHistory()
      • clearCustomRegistry

        protected void clearCustomRegistry()
      • 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)
      • addEnvironmentEntry

        public void addEnvironmentEntry​(String name,
                                        Object value)
      • setPersistenceProperty

        public void setPersistenceProperty​(String name,
                                           Object value)
      • cleanupSingletonSessionId

        protected static void cleanupSingletonSessionId()
      • getActiveProcesses

        public Collection<org.kie.api.runtime.process.ProcessInstance> getActiveProcesses​(org.kie.api.runtime.KieSession ksession)
      • getActiveNodesInProcessInstance

        public List<String> getActiveNodesInProcessInstance​(org.kie.api.runtime.KieSession ksession,
                                                            long processInstanceId)