Imixs-Mock

Imixs-Mock is a testing library for mocking the Imixs Workflow engine.

License

License

GroupId

GroupId

org.imixs.workflow
ArtifactId

ArtifactId

imixs-mock
Last Version

Last Version

5.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

Imixs-Mock
Imixs-Mock is a testing library for mocking the Imixs Workflow engine.
Project URL

Project URL

https://github.com/imixs/imixs-mock
Project Organization

Project Organization

Imixs Software Solutions GmbH
Source Code Management

Source Code Management

https://github.com/imixs/imixs-mock/

Download imixs-mock

How to add to project

<!-- https://jarcasting.com/artifacts/org.imixs.workflow/imixs-mock/ -->
<dependency>
    <groupId>org.imixs.workflow</groupId>
    <artifactId>imixs-mock</artifactId>
    <version>5.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.imixs.workflow/imixs-mock/
implementation 'org.imixs.workflow:imixs-mock:5.2.0'
// https://jarcasting.com/artifacts/org.imixs.workflow/imixs-mock/
implementation ("org.imixs.workflow:imixs-mock:5.2.0")
'org.imixs.workflow:imixs-mock:jar:5.2.0'
<dependency org="org.imixs.workflow" name="imixs-mock" rev="5.2.0">
  <artifact name="imixs-mock" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.imixs.workflow', module='imixs-mock', version='5.2.0')
)
libraryDependencies += "org.imixs.workflow" % "imixs-mock" % "5.2.0"
[org.imixs.workflow/imixs-mock "5.2.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.imixs.workflow : imixs-workflow-engine jar 5.2.2
junit : junit jar 4.8.1
org.mockito : mockito-all jar 1.9.5

provided (1)

Group / Artifact Type Version
javax : javaee-api jar 6.0

Project Modules

There are no modules declared in this project.

Imixs-Mock

Build Status Join the chat at https://gitter.im/imixs/imixs-workflow License

Imixs-Mock is a testing library for mocking the Imixs Workflow engine.

Mocking is primarily used in unit testing. An object under test may have dependencies on other (complex) objects. To isolate the behavior of the object you want to replace the other objects by mocks that simulate the behavior of the real objects. This is useful if the real objects are impractical to incorporate into the unit test.

In short, mocking is creating objects that simulate the behavior of real objects.

How to Use

To use the library in your own project just add the following maven dependencies:

<dependency>
	<groupId>org.imixs.workflow</groupId>
	<artifactId>imixs-mock</artifactId>
	<version>4.4.1</version>
	<scope>test</scope>
</dependency>
<!-- JUnit Tests -->
<dependency>
	<groupId>junit</groupId>
	<artifactId>junit</artifactId>
	<version>4.8.1</version>
	<scope>test</scope>
</dependency>
<dependency>
	<groupId>org.mockito</groupId>
	<artifactId>mockito-all</artifactId>
	<version>1.9.5</version>
	<scope>test</scope>
</dependency>

Note: Take a look into the Release Notes to check the compatibility list for your Imixs-Workflow versiion.

Junit Tests

In a JUnit Test class you can initialize the Imixs-Workflow Mock environment:

public class TestMyWorkflow {
	WorkflowMockEnvironment workflowMockEnvironment;

	final static String MODEL_PATH = "/mymodel.bpmn";
	final static String MODEL_VERSION = "1.0.0";

	ItemCollection workitem = null;

	// setup the workflow envirnment
	@Before
	public void setup() throws PluginException, ModelException {

		// initialize @Mock annotations....
		MockitoAnnotations.initMocks(this);

		workflowMockEnvironment = new WorkflowMockEnvironment();
		workflowMockEnvironment.setModelPath(MODEL_PATH);
		workflowMockEnvironment.setup();

		// test model...
		Assert.assertNotNull(workflowMockEnvironment.getModel());
	}
	.....
}

You can find a full example of a jUnit Test here

Test Your Model

After you have setup the workflow Mock you can write test methods to test specific model situations. In your test method you simulate a Task and an Event in the following way:

@Test
public void testSimple() {

	workitem = new ItemCollection();
	workitem.model(MODEL_VERSION).task(2100).event(10);
	workitem.replaceItemValue("_subject", "Hello World");

	try {
		workitem = workflowMockEnvironment.getWorkflowService().processWorkItem(workitem);
	} catch (AccessDeniedException | ProcessingErrorException | PluginException | ModelException e) {
		Assert.fail();
	}

}

Testing Specific Plugins Only

You can overwrite the plug-in list defined by your model to test only specific plug-ins. This can be useful to reduce the complexity in a mock environment

// test only specific Plugins.....
try {
	workflowMockEnvironment.getModelService()
			.addModel(new ModelPluginMock(workflowMockEnvironment.getModel(),
					"org.imixs.marty.plugins.ApproverPlugin",
					"org.imixs.workflow.engine.plugins.RulePlugin"));
} catch (ModelException e) {
	e.printStackTrace();
}

Different Model Locations in Maven

In a Maven multi-module project your models are typical placed outside your java module (e.g. in the parent project). In this case you can define the location of test resources with the following additional configuraition in your pom.xml:

...
<build>
  ....
  <testResources>
		<testResource>
			<directory>${project.basedir}/../src/workflow</directory>
		</testResource>
  </testResources>
</build>

With this configuration your bpmn models are loaded from the parent module.

Simulate User Login

You can easily simulate a specific user in you test class by

.....
Principal principal = Mockito.mock(Principal.class);
when(workflowMockEnvironment.getWorkflowService().getUserName()).thenReturn("my.userid");
....

Set Log Level

To set the log level in a unit test you can simply change the standard logger:

Logger.getLogger("org.imixs.workflow.*").setLevel(Level.FINEST);
org.imixs.workflow

Imixs-Workflow Project

The open source technology for business process management

Versions

Version
5.2.0
5.1.0
5.0.2
5.0.1
5.0.0
4.5.5
4.4.1
4.4.0