Class ProcessEngineExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback,org.junit.jupiter.api.extension.AfterEachCallback,org.junit.jupiter.api.extension.BeforeAllCallback,org.junit.jupiter.api.extension.BeforeEachCallback,org.junit.jupiter.api.extension.Extension,org.junit.jupiter.api.extension.ParameterResolver,org.junit.jupiter.api.extension.TestInstancePostProcessor,org.junit.jupiter.api.extension.TestInstantiationAwareExtension,org.junit.jupiter.api.extension.TestWatcher,ProcessEngineProvider,ProcessEngineServices
- Direct Known Subclasses:
CustomProcessEngineExtension
ProcessEngine into test classes.
This extension provides a managed instance of ProcessEngine and its services, which can
be automatically injected into test fields. The process engine configuration can be provided
through an operaton.cfg.xml file on the classpath or customized using a builder pattern.
Basic Usage:
@ExtendWith(ProcessEngineExtension.class)
class YourTest {
ProcessEngine processEngine;
RuntimeService runtimeService;
TaskService taskService;
// other engine services
...
}
For advanced usage, where specific configurations are required, the extension can be registered manually with a custom configuration file:
@RegisterExtension
ProcessEngineExtension extension = ProcessEngineExtension.builder()
.configurationResource("customConfiguration.xml")
.build();
Annotations:
Deployment- Deploys a specified deployment before each test and cascades deletion after each test execution.RequiredHistoryLevel- Skips tests if the engine's history level does not meet the required level.
Injected Services:
In addition to ProcessEngine, the extension also injects various BPM services:
RepositoryService, RuntimeService, TaskService, HistoryService,
IdentityService, ManagementService, FormService, FilterService,
AuthorizationService, CaseService, ExternalTaskService, and
DecisionService. Each of these services can be injected directly into the test class
fields to simplify access within tests.
Builder Pattern:
This extension supports a fluent builder pattern for advanced configuration:
ProcessEngineExtension extension = ProcessEngineExtension.builder()
.configurationResource("myCustomConfig.xml")
.ensureCleanAfterTest(true)
.build();
configurationResource(String)- Specifies a custom configuration file.ensureCleanAfterTest(boolean)- Ensures a clean database state after each test.useProcessEngine(ProcessEngine)- Reuses an existing process engine instance.manageDeployment(Deployment)- Adds deployments that will be managed and cleaned up after tests.
Setting History Level:
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.
Test Lifecycle Callbacks:
This extension implements multiple JUnit lifecycle callbacks:
TestInstancePostProcessor- Initializes and injects the process engine instance before each test.BeforeEachCallback- Sets up deployment and history level requirements before each test.AfterEachCallback- Cleans up deployments, services, and resets the engine state after each test.AfterAllCallback- Clears service references once all tests in a class have been executed.
Database and Diagnostics:
After each test execution, the extension ensures a clean database state by validating and cleaning the engine's cache and database if configured to do so. This feature is particularly useful for tests that rely on database consistency. The extension also resets the engine’s diagnostic state to maintain a clean testing environment.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AuthorizationServiceprotected CaseServiceprotected Stringprotected DecisionServiceprotected Stringprotected booleanprotected ExternalTaskServiceprotected FilterServiceprotected FormServiceprotected HistoryServiceprotected IdentityServiceprotected static final org.slf4j.Loggerprotected ManagementServiceprotected ProcessEngineprotected ProcessEngineConfigurationImplprotected Consumer<ProcessEngineConfigurationImpl> protected RepositoryServiceprotected RuntimeServiceprotected TaskService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterAll(org.junit.jupiter.api.extension.ExtensionContext context) voidafterEach(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context) build()static ProcessEngineExtensionbuilder()When set then the created ProcessEngine will be closed after all tests in the class have been executed.When set then the created ProcessEngine will be closed after each test and recreated afterwards.configurationResource(String configurationResource) configurator(Consumer<ProcessEngineConfigurationImpl> processEngineConfigurator) ensureCleanAfterTest(boolean ensureCleanAfterTest) Returns the process engine'sAuthorizationService.Returns the engine'sCaseService.Returns the engine'sDecisionService.Returns the engine'sExternalTaskService.Returns the engine'sFilterService.Returns the process engine'sFormService.Returns the process engine'sHistoryService.Returns the process engine'sIdentityService.Returns the process engine'sManagementService.Returns the process engine'sRepositoryService.Returns the process engine'sRuntimeService.Returns the process engine'sTaskService.protected Supplier<IllegalStateException> voidvoidprotected voidDeprecated, for removal: This API element is subject to removal in a future version.protected voidbooleanmanageDeployment(Deployment deployment) voidpostProcessTestInstance(Object testInstance, org.junit.jupiter.api.extension.ExtensionContext context) Sets the process engine name to a random name.resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) voidsetAuthorizationService(AuthorizationService authorizationService) voidsetCaseService(CaseService caseService) voidsetConfigurationResource(String configurationResource) voidsetCurrentTime(Date currentTime) voidsetDecisionService(DecisionService decisionService) voidsetEnsureCleanAfterTest(boolean ensureCleanAfterTest) voidsetExternalTaskService(ExternalTaskService externalTaskService) voidsetFilterService(FilterService filterService) voidsetFormService(FormService formService) voidsetHistoryService(HistoryService historyService) voidsetIdentityService(IdentityService identityService) voidsetManagementService(ManagementService managementService) voidsetProcessEngine(ProcessEngine processEngine) voidsetProcessEngineConfiguration(ProcessEngineConfigurationImpl processEngineConfiguration) voidsetRepositoryService(RepositoryService repositoryService) voidsetRuntimeService(RuntimeService runtimeService) voidsetTaskService(TaskService taskService) booleansupportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) useProcessEngine(ProcessEngine engine) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScopeMethods inherited from interface org.junit.jupiter.api.extension.TestWatcher
testAborted, testDisabled, testFailed, testSuccessful
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOG -
processEngine
-
processEngineConfiguration
-
repositoryService
-
runtimeService
-
taskService
-
historyService
-
identityService
-
managementService
-
formService
-
filterService
-
authorizationService
-
caseService
-
externalTaskService
-
decisionService
-
configurationResource
-
deploymentId
-
ensureCleanAfterTest
protected boolean ensureCleanAfterTest -
additionalDeployments
-
processEngineConfigurator
-
-
Constructor Details
-
ProcessEngineExtension
public ProcessEngineExtension()
-
-
Method Details
-
initializeProcessEngine
public void initializeProcessEngine() -
initializeServices
public void initializeServices() -
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
supportsParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
resolveParameter
public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
resolveParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
beforeEach
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
-
afterEach
public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
afterEachin interfaceorg.junit.jupiter.api.extension.AfterEachCallback
-
beforeAll
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
-
afterAll
public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
afterAllin interfaceorg.junit.jupiter.api.extension.AfterAllCallback
-
postProcessTestInstance
public void postProcessTestInstance(Object testInstance, org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
postProcessTestInstancein interfaceorg.junit.jupiter.api.extension.TestInstancePostProcessor
-
builder
-
configurationResource
-
useProcessEngine
-
ensureCleanAfterTest
-
manageDeployment
-
configurator
public ProcessEngineExtension configurator(Consumer<ProcessEngineConfigurationImpl> processEngineConfigurator) -
closeEngineAfterAllTests
When set then the created ProcessEngine will be closed after all tests in the class have been executed.Use this method before calling #
build(). -
closeEngineAfterEachTest
When set then the created ProcessEngine will be closed after each test and recreated afterwards. -
randomEngineName
Sets the process engine name to a random name.Use this method before calling #
build(). -
build
-
illegalStateException
-
inject
Deprecated, for removal: This API element is subject to removal in a future version.Useinject(Object, Field, Object)instead. -
inject
-
setCurrentTime
-
getProcessEngine
- Specified by:
getProcessEnginein interfaceProcessEngineProvider
-
setProcessEngine
-
getConfigurationResource
-
getProcessEngineConfiguration
-
getRepositoryService
Description copied from interface:ProcessEngineServicesReturns the process engine'sRepositoryService.- Specified by:
getRepositoryServicein interfaceProcessEngineServices- Returns:
- the
RepositoryServiceobject.
-
setRepositoryService
-
getRuntimeService
Description copied from interface:ProcessEngineServicesReturns the process engine'sRuntimeService.- Specified by:
getRuntimeServicein interfaceProcessEngineServices- Returns:
- the
RuntimeServiceobject.
-
setRuntimeService
-
getTaskService
Description copied from interface:ProcessEngineServicesReturns the process engine'sTaskService.- Specified by:
getTaskServicein interfaceProcessEngineServices- Returns:
- the
TaskServiceobject.
-
setTaskService
-
getHistoryService
Description copied from interface:ProcessEngineServicesReturns the process engine'sHistoryService.- Specified by:
getHistoryServicein interfaceProcessEngineServices- Returns:
- the
HistoryServiceobject.
-
setHistoryService
-
getIdentityService
Description copied from interface:ProcessEngineServicesReturns the process engine'sIdentityService.- Specified by:
getIdentityServicein interfaceProcessEngineServices- Returns:
- the
IdentityServiceobject.
-
setIdentityService
-
getManagementService
Description copied from interface:ProcessEngineServicesReturns the process engine'sManagementService.- Specified by:
getManagementServicein interfaceProcessEngineServices- Returns:
- the
ManagementServiceobject.
-
setManagementService
-
getFormService
Description copied from interface:ProcessEngineServicesReturns the process engine'sFormService.- Specified by:
getFormServicein interfaceProcessEngineServices- Returns:
- the
FormServiceobject.
-
setFormService
-
getFilterService
Description copied from interface:ProcessEngineServicesReturns the engine'sFilterService.- Specified by:
getFilterServicein interfaceProcessEngineServices- Returns:
- the
FilterServiceobject.
-
setFilterService
-
getAuthorizationService
Description copied from interface:ProcessEngineServicesReturns the process engine'sAuthorizationService.- Specified by:
getAuthorizationServicein interfaceProcessEngineServices- Returns:
- the
AuthorizationServiceobject.
-
setAuthorizationService
-
getCaseService
Description copied from interface:ProcessEngineServicesReturns the engine'sCaseService.- Specified by:
getCaseServicein interfaceProcessEngineServices- Returns:
- the
CaseServiceobject.
-
setCaseService
-
getExternalTaskService
Description copied from interface:ProcessEngineServicesReturns the engine'sExternalTaskService.- Specified by:
getExternalTaskServicein interfaceProcessEngineServices- Returns:
- the
ExternalTaskServiceobject.
-
setExternalTaskService
-
getDecisionService
Description copied from interface:ProcessEngineServicesReturns the engine'sDecisionService.- Specified by:
getDecisionServicein interfaceProcessEngineServices- Returns:
- the
DecisionServiceobject.
-
setDecisionService
-
setProcessEngineConfiguration
public void setProcessEngineConfiguration(ProcessEngineConfigurationImpl processEngineConfiguration) -
setConfigurationResource
-
getDeploymentId
-
isEnsureCleanAfterTest
public boolean isEnsureCleanAfterTest() -
setEnsureCleanAfterTest
public void setEnsureCleanAfterTest(boolean ensureCleanAfterTest)
-
inject(Object, Field, Object)instead.