Class MockWorkflowEnvironment

java.lang.Object
org.imixs.workflow.engine.MockWorkflowEnvironment

public class MockWorkflowEnvironment extends Object
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 Details

    • logger

      protected static final Logger logger
    • sessionContext

      protected jakarta.ejb.SessionContext sessionContext
    • database

      protected Map<String,org.imixs.workflow.ItemCollection> 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

      protected List<org.imixs.workflow.Adapter> adapterList
    • pluginList

      protected List<org.imixs.workflow.Plugin> pluginList
    • modelManager

      protected org.imixs.workflow.ModelManager modelManager
  • Constructor Details

    • MockWorkflowEnvironment

      public MockWorkflowEnvironment()
  • Method Details

    • setUp

      public void setUp() throws org.imixs.workflow.exceptions.PluginException
      The 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

      public void loadBPMNModelFromFile(String modelPath)
      Loads a new model
      Parameters:
      modelPath -
    • createTestDatabase

      protected void createTestDatabase()
      Create a test database with some workItems and a simple model
    • injectMockIntoField

      public void injectMockIntoField(Object targetObject, String fieldName, Object value)
      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

      public void updatePluginDefinition(org.openbpmn.bpmn.BPMNModel model, List<String> newPlugins)
      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.