Package org.imixs.workflow.engine
Class MockWorkflowEnvironment
java.lang.Object
org.imixs.workflow.engine.MockWorkflowEnvironment
The
MockWorkflowEnvironment can be used as a base class for junit
tests to mock the Imixs WorkflowService, WorkflowContextService and
ModelService.
Junit tests can instantiate this class to verify specific method implementations of the workflowService, Plugin classes or Adapters in a easy way.
Because this is a abstract base test class we annotate the MockitoSettings
Strictness to avoid
org.mockito.exceptions.misusing.UnnecessaryStubbingException.
- Author:
- rsoika
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List<org.imixs.workflow.Adapter>protected org.imixs.workflow.engine.DocumentServiceprotected static final Loggerprotected org.imixs.workflow.ModelManagerprotected org.imixs.workflow.engine.ModelServiceprotected List<org.imixs.workflow.Plugin>protected jakarta.ejb.SessionContextprotected org.imixs.workflow.engine.WorkflowService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCreate a test database with some workItems and a simple modelorg.openbpmn.bpmn.BPMNModelfetchModel(String version) Helper method to load a model from internal cache (not thread save)org.imixs.workflow.engine.DocumentServiceorg.imixs.workflow.ModelManagerorg.imixs.workflow.engine.ModelServiceorg.imixs.workflow.engine.WorkflowServicevoidinjectMockIntoField(Object targetObject, String fieldName, Object value) Helper method to inject a mock into a private/protected field using reflection.voidloadBPMNModelFromFile(String modelPath) Loads a new modelvoidregisterAdapter(org.imixs.workflow.Adapter adapter) Can be used to register an Adapter before SetupvoidregisterPlugin(org.imixs.workflow.Plugin plugin) Can be used to register an plugin before SetupvoidsetUp()The Setup method initializes a mock environment to test the imixs workflow service.voidupdatePluginDefinition(org.openbpmn.bpmn.BPMNModel model, List<String> newPlugins) This method updates the plugin definitions for a registered Model.
-
Field Details
-
logger
-
sessionContext
protected jakarta.ejb.SessionContext sessionContext -
database
-
documentService
@Mock protected org.imixs.workflow.engine.DocumentService documentService -
modelService
@InjectMocks protected org.imixs.workflow.engine.ModelService modelService -
workflowService
@InjectMocks protected org.imixs.workflow.engine.WorkflowService workflowService -
adapterList
-
pluginList
-
modelManager
protected org.imixs.workflow.ModelManager modelManager
-
-
Constructor Details
-
MockWorkflowEnvironment
public MockWorkflowEnvironment()
-
-
Method Details
-
setUp
public void setUp() throws org.imixs.workflow.exceptions.PluginExceptionThe Setup method initializes a mock environment to test the imixs workflow service. It initializes a in-memory database and a model Service as also a Session context object.You can overwrite this method in a junit test to add additional test settings.
- Throws:
org.imixs.workflow.exceptions.PluginException
-
getModelManager
public org.imixs.workflow.ModelManager getModelManager() -
getModelService
public org.imixs.workflow.engine.ModelService getModelService() -
getDocumentService
public org.imixs.workflow.engine.DocumentService getDocumentService() -
getWorkflowService
public org.imixs.workflow.engine.WorkflowService getWorkflowService() -
registerAdapter
public void registerAdapter(org.imixs.workflow.Adapter adapter) Can be used to register an Adapter before Setup- Parameters:
adapter-
-
registerPlugin
public void registerPlugin(org.imixs.workflow.Plugin plugin) throws org.imixs.workflow.exceptions.PluginException Can be used to register an plugin before Setup- Parameters:
adapter-- Throws:
org.imixs.workflow.exceptions.PluginException
-
fetchModel
public org.openbpmn.bpmn.BPMNModel fetchModel(String version) throws org.imixs.workflow.exceptions.ModelException Helper method to load a model from internal cache (not thread save)- Parameters:
version-- Returns:
- Throws:
org.imixs.workflow.exceptions.ModelException
-
loadBPMNModelFromFile
Loads a new model- Parameters:
modelPath-
-
createTestDatabase
protected void createTestDatabase()Create a test database with some workItems and a simple model -
injectMockIntoField
Helper method to inject a mock into a private/protected field using reflection.- Parameters:
targetObject- The object into which the field is to be injected.fieldName- The name of the field to inject.value- The mock or object to inject into the field.
-
updatePluginDefinition
This method updates the plugin definitions for a registered Model. This can be helpful if a junit test needs a reduced plugin list to reduce complexity of a test.
-