org.camunda.bpm.engine.test
Class ProcessEngineRule

java.lang.Object
  extended by org.junit.rules.TestWatcher
      extended by org.camunda.bpm.engine.test.ProcessEngineRule
All Implemented Interfaces:
ProcessEngineServices, org.junit.rules.TestRule

public class ProcessEngineRule
extends org.junit.rules.TestWatcher
implements ProcessEngineServices

Convenience for ProcessEngine and services initialization in the form of a JUnit rule.

Usage:

 public class YourTest {

   @Rule
   public ProcessEngineRule processEngineRule = new ProcessEngineRule();

   ...
 }
 

The ProcessEngine and the services will be made available to the test class through the getters of the processEngineRule. The processEngine will be initialized by default with the camunda.cfg.xml resource on the classpath. To specify a different configuration file, pass the resource location in the appropriate constructor. Process engines will be cached statically. Right before the first time the setUp is called for a given configuration resource, the process engine will be constructed.

You can declare a deployment with the Deployment annotation. This base class will make sure that this deployment gets deployed before the setUp and cascade deleted after the tearDown.

The processEngineRule also lets you set the current time used by the process engine. This can be handy to control the exact time that is used by the engine in order to verify e.g. e.g. due dates of timers. Or start, end and duration times in the history service. In the tearDown, the internal clock will automatically be reset to use the current system time rather then the time that was set during a test method. In other words, you don't have to clean up your own time messing mess ;-)

If you need the history service for your tests then you can specify the required history level of the test method or class, using the RequiredHistoryLevel annotation. If the current history level of the process engine is lower than the specified one then the test is skipped.

Author:
Tom Baeyens

Field Summary
protected  List<String> additionalDeployments
           
protected  AuthorizationService authorizationService
           
protected  CaseService caseService
           
protected  String configurationResource
           
protected  String configurationResourceCompat
           
protected  DecisionService decisionService
           
protected  String deploymentId
           
protected  boolean ensureCleanAfterTest
           
protected  ExternalTaskService externalTaskService
           
protected  FilterService filterService
           
protected  FormService formService
           
protected  HistoryService historyService
           
protected  IdentityService identityService
           
protected  ManagementService managementService
           
protected  ProcessEngine processEngine
           
protected  ProcessEngineConfigurationImpl processEngineConfiguration
           
protected  RepositoryService repositoryService
           
protected  RuntimeService runtimeService
           
protected  TaskService taskService
           
 
Constructor Summary
ProcessEngineRule()
           
ProcessEngineRule(boolean ensureCleanAfterTest)
           
ProcessEngineRule(ProcessEngine processEngine)
           
ProcessEngineRule(ProcessEngine processEngine, boolean ensureCleanAfterTest)
           
ProcessEngineRule(String configurationResource)
           
ProcessEngineRule(String configurationResource, boolean ensureCleanAfterTest)
           
 
Method Summary
 org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
           
protected  void clearServiceReferences()
           
 void finished(org.junit.runner.Description description)
           
 AuthorizationService getAuthorizationService()
          Returns the process engine's AuthorizationService.
 CaseService getCaseService()
          Returns the engine's CaseService.
 String getConfigurationResource()
           
 DecisionService getDecisionService()
          Returns the engine's DecisionService.
 ExternalTaskService getExternalTaskService()
          Returns the engine's ExternalTaskService.
 FilterService getFilterService()
          Returns the engine's FilterService.
 FormService getFormService()
          Returns the process engine's FormService.
 HistoryService getHistoryService()
          Returns the process engine's HistoryService.
 IdentityService getIdentityService()
          Returns the process engine's IdentityService.
 ManagementService getManagementService()
          Returns the process engine's ManagementService.
 ProcessEngine getProcessEngine()
           
 ProcessEngineConfigurationImpl getProcessEngineConfiguration()
           
 RepositoryService getRepositoryService()
          Returns the process engine's RepositoryService.
 RuntimeService getRuntimeService()
          Returns the process engine's RuntimeService.
 TaskService getTaskService()
          Returns the process engine's TaskService.
protected  void initializeProcessEngine()
           
protected  void initializeServices()
           
 void manageDeployment(Deployment deployment)
           
 void setAuthorizationService(AuthorizationService authorizationService)
           
 void setCaseService(CaseService caseService)
           
 void setConfigurationResource(String configurationResource)
           
 void setCurrentTime(Date currentTime)
           
 void setDecisionService(DecisionService decisionService)
           
 void setExternalTaskService(ExternalTaskService externalTaskService)
           
 void setFilterService(FilterService filterService)
           
 void setFormService(FormService formService)
           
 void setHistoricDataService(HistoryService historicService)
           
 void setHistoryService(HistoryService historyService)
           
 void setIdentityService(IdentityService identityService)
           
 void setManagementService(ManagementService managementService)
           
 void setProcessEngine(ProcessEngine processEngine)
           
 void setProcessEngineConfiguration(ProcessEngineConfigurationImpl processEngineConfiguration)
           
 void setRepositoryService(RepositoryService repositoryService)
           
 void setRuntimeService(RuntimeService runtimeService)
           
 void setTaskService(TaskService taskService)
           
 void starting(org.junit.runner.Description description)
           
 
Methods inherited from class org.junit.rules.TestWatcher
failed, skipped, succeeded
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configurationResource

protected String configurationResource

configurationResourceCompat

protected String configurationResourceCompat

deploymentId

protected String deploymentId

additionalDeployments

protected List<String> additionalDeployments

ensureCleanAfterTest

protected boolean ensureCleanAfterTest

processEngine

protected ProcessEngine processEngine

processEngineConfiguration

protected ProcessEngineConfigurationImpl processEngineConfiguration

repositoryService

protected RepositoryService repositoryService

runtimeService

protected RuntimeService runtimeService

taskService

protected TaskService taskService

historyService

protected HistoryService historyService

identityService

protected IdentityService identityService

managementService

protected ManagementService managementService

formService

protected FormService formService

filterService

protected FilterService filterService

authorizationService

protected AuthorizationService authorizationService

caseService

protected CaseService caseService

externalTaskService

protected ExternalTaskService externalTaskService

decisionService

protected DecisionService decisionService
Constructor Detail

ProcessEngineRule

public ProcessEngineRule()

ProcessEngineRule

public ProcessEngineRule(boolean ensureCleanAfterTest)

ProcessEngineRule

public ProcessEngineRule(String configurationResource)

ProcessEngineRule

public ProcessEngineRule(String configurationResource,
                         boolean ensureCleanAfterTest)

ProcessEngineRule

public ProcessEngineRule(ProcessEngine processEngine)

ProcessEngineRule

public ProcessEngineRule(ProcessEngine processEngine,
                         boolean ensureCleanAfterTest)
Method Detail

starting

public void starting(org.junit.runner.Description description)
Overrides:
starting in class org.junit.rules.TestWatcher

apply

public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base,
                                               org.junit.runner.Description description)
Specified by:
apply in interface org.junit.rules.TestRule
Overrides:
apply in class org.junit.rules.TestWatcher

initializeProcessEngine

protected void initializeProcessEngine()

initializeServices

protected void initializeServices()

clearServiceReferences

protected void clearServiceReferences()

finished

public void finished(org.junit.runner.Description description)
Overrides:
finished in class org.junit.rules.TestWatcher

setCurrentTime

public void setCurrentTime(Date currentTime)

getConfigurationResource

public String getConfigurationResource()

setConfigurationResource

public void setConfigurationResource(String configurationResource)

getProcessEngine

public ProcessEngine getProcessEngine()

setProcessEngine

public void setProcessEngine(ProcessEngine processEngine)

getProcessEngineConfiguration

public ProcessEngineConfigurationImpl getProcessEngineConfiguration()

setProcessEngineConfiguration

public void setProcessEngineConfiguration(ProcessEngineConfigurationImpl processEngineConfiguration)

getRepositoryService

public RepositoryService getRepositoryService()
Description copied from interface: ProcessEngineServices
Returns the process engine's RepositoryService.

Specified by:
getRepositoryService in interface ProcessEngineServices
Returns:
the RepositoryService object.

setRepositoryService

public void setRepositoryService(RepositoryService repositoryService)

getRuntimeService

public RuntimeService getRuntimeService()
Description copied from interface: ProcessEngineServices
Returns the process engine's RuntimeService.

Specified by:
getRuntimeService in interface ProcessEngineServices
Returns:
the RuntimeService object.

setRuntimeService

public void setRuntimeService(RuntimeService runtimeService)

getTaskService

public TaskService getTaskService()
Description copied from interface: ProcessEngineServices
Returns the process engine's TaskService.

Specified by:
getTaskService in interface ProcessEngineServices
Returns:
the TaskService object.

setTaskService

public void setTaskService(TaskService taskService)

getHistoryService

public HistoryService getHistoryService()
Description copied from interface: ProcessEngineServices
Returns the process engine's HistoryService.

Specified by:
getHistoryService in interface ProcessEngineServices
Returns:
the HistoryService object.

setHistoryService

public void setHistoryService(HistoryService historyService)

setHistoricDataService

public void setHistoricDataService(HistoryService historicService)
Parameters:
historicService - the historiy service instance
See Also:
setHistoryService(HistoryService)

getIdentityService

public IdentityService getIdentityService()
Description copied from interface: ProcessEngineServices
Returns the process engine's IdentityService.

Specified by:
getIdentityService in interface ProcessEngineServices
Returns:
the IdentityService object.

setIdentityService

public void setIdentityService(IdentityService identityService)

getManagementService

public ManagementService getManagementService()
Description copied from interface: ProcessEngineServices
Returns the process engine's ManagementService.

Specified by:
getManagementService in interface ProcessEngineServices
Returns:
the ManagementService object.

getAuthorizationService

public AuthorizationService getAuthorizationService()
Description copied from interface: ProcessEngineServices
Returns the process engine's AuthorizationService.

Specified by:
getAuthorizationService in interface ProcessEngineServices
Returns:
the AuthorizationService object.

setAuthorizationService

public void setAuthorizationService(AuthorizationService authorizationService)

getCaseService

public CaseService getCaseService()
Description copied from interface: ProcessEngineServices
Returns the engine's CaseService.

Specified by:
getCaseService in interface ProcessEngineServices
Returns:
the CaseService object.

setCaseService

public void setCaseService(CaseService caseService)

getFormService

public FormService getFormService()
Description copied from interface: ProcessEngineServices
Returns the process engine's FormService.

Specified by:
getFormService in interface ProcessEngineServices
Returns:
the FormService object.

setFormService

public void setFormService(FormService formService)

setManagementService

public void setManagementService(ManagementService managementService)

getFilterService

public FilterService getFilterService()
Description copied from interface: ProcessEngineServices
Returns the engine's FilterService.

Specified by:
getFilterService in interface ProcessEngineServices
Returns:
the FilterService object.

setFilterService

public void setFilterService(FilterService filterService)

getExternalTaskService

public ExternalTaskService getExternalTaskService()
Description copied from interface: ProcessEngineServices
Returns the engine's ExternalTaskService.

Specified by:
getExternalTaskService in interface ProcessEngineServices
Returns:
the ExternalTaskService object.

setExternalTaskService

public void setExternalTaskService(ExternalTaskService externalTaskService)

getDecisionService

public DecisionService getDecisionService()
Description copied from interface: ProcessEngineServices
Returns the engine's DecisionService.

Specified by:
getDecisionService in interface ProcessEngineServices
Returns:
the DecisionService object.

setDecisionService

public void setDecisionService(DecisionService decisionService)

manageDeployment

public void manageDeployment(Deployment deployment)


Copyright © 2017 camunda services GmbH. All rights reserved.