Skip to content

Commit

Permalink
junit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoika committed Aug 23, 2024
1 parent 2dd2142 commit 2924a68
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ protected void registerAdapters(WorkflowKernel workflowkernel) {
boolean debug = logger.isLoggable(Level.FINE);
if (debug && (adapters == null || !adapters.iterator().hasNext())) {
logger.finest("......no CDI Adapters injected");
} else {
} else if (this.adapters != null) {
// iterate over all injected adapters....
for (Adapter adapter : this.adapters) {
if (debug) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.imixs.workflow.WorkflowKernel;
import org.imixs.workflow.exceptions.AccessDeniedException;
import org.imixs.workflow.exceptions.ModelException;
import org.imixs.workflow.exceptions.PluginException;
import org.imixs.workflow.exceptions.ProcessingErrorException;
import org.junit.Assert;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -20,9 +21,13 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.stubbing.Answer;
import org.openbpmn.bpmn.BPMNModel;
import org.openbpmn.bpmn.exceptions.BPMNModelException;
import org.openbpmn.bpmn.util.BPMNModelFactory;

/**
* Test class for WorkflowService
Expand All @@ -42,16 +47,27 @@ public class TestWorkflowServiceNew {
@Mock
private DocumentService documentService;

@InjectMocks
ModelService modelService;

@InjectMocks
WorkflowService workflowServiceMock;

MockWorkflowEngineContext workflowContext = null;

@BeforeEach
public void setUp() {

// MockitoAnnotations.openMocks(this);
MockitoAnnotations.openMocks(this);

// define return value database mock
createTestDatabase();

loadBPMNModel("/bpmn/plugin-test.bpmn");
workflowServiceMock.modelService = modelService;
workflowContext = new MockWorkflowEngineContext();
workflowServiceMock.ctx = workflowContext.getSessionContext();

// Mock Database Service...
when(documentService.load(Mockito.anyString())).thenAnswer(new Answer<ItemCollection>() {
@Override
public ItemCollection answer(InvocationOnMock invocation) throws Throwable {
Expand All @@ -65,6 +81,18 @@ public ItemCollection answer(InvocationOnMock invocation) throws Throwable {
return result;
}
});
when(documentService.save(Mockito.any())).thenAnswer(new Answer<ItemCollection>() {
@Override
public ItemCollection answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
ItemCollection data = (ItemCollection) args[0];
if (data != null) {
database.put(data.getUniqueID(), data);
}
return data;
}
});

}

/**
Expand Down Expand Up @@ -95,6 +123,34 @@ public void testProcessSimple() {

}

/**
* This test simulates a workflowService process call by mocking the entity and
* model service.
*
* This is just a simple simulation...
*
* @throws ProcessingErrorException
* @throws AccessDeniedException
* @throws ModelException
*/
@Test
public void testProcessSimple2()
throws AccessDeniedException, ProcessingErrorException, PluginException, ModelException {
// load test workitem

ItemCollection workitem = documentService.load("W0000-00001");
workitem.replaceItemValue(WorkflowKernel.MODELVERSION, WorkflowMockEnvironment.DEFAULT_MODEL_VERSION);
workitem.setTaskID(100);

workitem = workflowServiceMock.processWorkItem(workitem);
assertNotNull(workitem);

Assert.assertEquals("1.0.0", workitem.getItemValueString("$ModelVersion"));
Assert.assertEquals(10, workitem.getItemValueInteger("$lastEvent"));
Assert.assertEquals(0, workitem.getEventID());

}

/**
* Create a test database with some workItems and a simple model
*/
Expand All @@ -115,6 +171,20 @@ protected void createTestDatabase() {
entity.replaceItemValue(DocumentService.ISAUTHOR, true);
database.put(entity.getItemValueString(WorkflowKernel.UNIQUEID), entity);
}
}

/**
* Loads a new model
*
* @param modelPath
*/
public void loadBPMNModel(String modelPath) {
try {
BPMNModel model = BPMNModelFactory.read(modelPath);
modelService.getOpenBPMNModelManager().addModel(model);
} catch (BPMNModelException | ModelException e) {
e.printStackTrace();
Assert.fail();
}
}
}
102 changes: 57 additions & 45 deletions imixs-workflow-engine/src/test/resources/bpmn/plugin-test.bpmn
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- origin at X=0.0 Y=0.0 -->
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:ext="http://org.eclipse.bpmn2/ext" xmlns:imixs="http://www.imixs.org/bpmn2" xmlns:xs="http://www.w3.org/2001/XMLSchema" id="Definitions_1" exporter="org.eclipse.bpmn2.modeler.core" exporterVersion="1.2.4.Final-v20160330-1625-B110" targetNamespace="http://www.imixs.org/bpmn2">
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- origin at X=0.0 Y=0.0 --><bpmn2:definitions xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:ext="http://org.eclipse.bpmn2/ext" xmlns:imixs="http://www.imixs.org/bpmn2" xmlns:open-bpmn="http://open-bpmn.org/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exporter="org.eclipse.bpmn2.modeler.core" exporterVersion="1.2.4.Final-v20160330-1625-B110" id="Definitions_1" targetNamespace="http://www.imixs.org/bpmn2">
<bpmn2:extensionElements>
<imixs:item name="txtfieldmapping" type="xs:string">
<imixs:value><![CDATA[Manager|namManager]]></imixs:value>
Expand All @@ -10,22 +9,26 @@
<imixs:value><![CDATA[Date|datDate]]></imixs:value>
</imixs:item>
<imixs:item name="txtplugins" type="xs:string">
<imixs:value><![CDATA[org.imixs.workflow.engine.plugins.AccessPlugin]]></imixs:value>
<imixs:value><![CDATA[org.imixs.workflow.engine.plugins.OwnerPlugin]]></imixs:value>
<imixs:value><![CDATA[org.imixs.workflow.engine.plugins.HistoryPlugin]]></imixs:value>
<imixs:value><![CDATA[org.imixs.workflow.engine.plugins.ResultPlugin]]></imixs:value>
</imixs:item>
<imixs:item name="txtworkflowmodelversion" type="xs:string">
<imixs:value><![CDATA[1.0.0]]></imixs:value>
</imixs:item>
<open-bpmn:auto-align/>
</bpmn2:extensionElements>
<bpmn2:process id="ticket" name="Ticket" isExecutable="false">
<bpmn2:process id="ticket" isExecutable="false" name="Ticket" processType="Public">
<bpmn2:startEvent id="StartEvent_1" name="Start">
<bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
<bpmn2:documentation id="documentation_HJDBzA"/>
</bpmn2:startEvent>
<bpmn2:sequenceFlow id="SequenceFlow_1" sourceRef="StartEvent_1" targetRef="Task_1"/>
<bpmn2:sequenceFlow id="SequenceFlow_1" sourceRef="StartEvent_1" targetRef="Task_1">
<bpmn2:documentation id="documentation_aQBvQA"/>
</bpmn2:sequenceFlow>
<bpmn2:endEvent id="EndEvent_1" name="End">
<bpmn2:incoming>SequenceFlow_5</bpmn2:incoming>
<bpmn2:documentation id="documentation_JAE7Kw"/>
</bpmn2:endEvent>
<bpmn2:task id="Task_1" imixs:processid="100" name="New Ticket">
<bpmn2:extensionElements>
Expand All @@ -36,7 +39,7 @@
<imixs:value><![CDATA[Create a new Ticket workflow]]></imixs:value>
</imixs:item>
</bpmn2:extensionElements>
<bpmn2:documentation id="Documentation_5">&lt;b>Create&lt;/b> a new ticket</bpmn2:documentation>
<bpmn2:documentation id="Documentation_5">&lt;b&gt;Create&lt;/b&gt; a new ticket</bpmn2:documentation>
<bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_11</bpmn2:outgoing>
</bpmn2:task>
Expand All @@ -49,6 +52,7 @@
<bpmn2:incoming>SequenceFlow_3</bpmn2:incoming>
<bpmn2:incoming>SequenceFlow_6</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_5</bpmn2:outgoing>
<bpmn2:documentation id="documentation_9x9dMQ"/>
</bpmn2:task>
<bpmn2:intermediateCatchEvent id="IntermediateCatchEvent_1" imixs:activityid="10" name="submit">
<bpmn2:extensionElements>
Expand All @@ -64,90 +68,98 @@
<imixs:value><![CDATA[namManager]]></imixs:value>
</imixs:item>
</bpmn2:extensionElements>
<bpmn2:documentation id="Documentation_1">&lt;b>Submitt&lt;/b> new ticket</bpmn2:documentation>
<bpmn2:documentation id="Documentation_1">&lt;b&gt;Submitt&lt;/b&gt; new ticket</bpmn2:documentation>
<bpmn2:incoming>SequenceFlow_11</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_3</bpmn2:outgoing>
</bpmn2:intermediateCatchEvent>
<bpmn2:intermediateCatchEvent id="IntermediateCatchEvent_2" imixs:activityid="10" name="save">
<bpmn2:outgoing>SequenceFlow_6</bpmn2:outgoing>
<bpmn2:documentation id="documentation_NJ6sPA"/>
</bpmn2:intermediateCatchEvent>
<bpmn2:sequenceFlow id="SequenceFlow_3" sourceRef="IntermediateCatchEvent_1" targetRef="Task_2"/>
<bpmn2:sequenceFlow id="SequenceFlow_6" sourceRef="IntermediateCatchEvent_2" targetRef="Task_2"/>
<bpmn2:sequenceFlow id="SequenceFlow_11" sourceRef="Task_1" targetRef="IntermediateCatchEvent_1"/>
<bpmn2:sequenceFlow id="SequenceFlow_5" sourceRef="Task_2" targetRef="EndEvent_1"/>
<bpmn2:sequenceFlow id="SequenceFlow_3" sourceRef="IntermediateCatchEvent_1" targetRef="Task_2">
<bpmn2:documentation id="documentation_DryR6A"/>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="SequenceFlow_6" sourceRef="IntermediateCatchEvent_2" targetRef="Task_2">
<bpmn2:documentation id="documentation_DlL6hg"/>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="SequenceFlow_11" sourceRef="Task_1" targetRef="IntermediateCatchEvent_1">
<bpmn2:documentation id="documentation_XA1LJw"/>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="SequenceFlow_5" sourceRef="Task_2" targetRef="EndEvent_1">
<bpmn2:documentation id="documentation_v0VqEQ"/>
</bpmn2:sequenceFlow>
<bpmn2:documentation id="documentation_OcMECg"/>
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1" name="Default Process Diagram">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="ticket">
<bpmndi:BPMNShape id="BPMNShape_1" bpmnElement="StartEvent_1">
<bpmndi:BPMNPlane bpmnElement="ticket" id="BPMNPlane_1">
<bpmndi:BPMNShape bpmnElement="StartEvent_1" id="BPMNShape_1">
<dc:Bounds height="36.0" width="36.0" x="40.0" y="90.0"/>
<bpmndi:BPMNLabel id="BPMNLabel_1" labelStyle="BPMNLabelStyle_1">
<dc:Bounds height="14.0" width="25.0" x="45.0" y="126.0"/>
<dc:Bounds height="20.0" width="100.0" x="7.5" y="126.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_2" bpmnElement="EndEvent_1">
<bpmndi:BPMNShape bpmnElement="EndEvent_1" id="BPMNShape_2">
<dc:Bounds height="36.0" width="36.0" x="580.0" y="90.0"/>
<bpmndi:BPMNLabel id="BPMNLabel_2" labelStyle="BPMNLabelStyle_1">
<dc:Bounds height="14.0" width="22.0" x="587.0" y="126.0"/>
<dc:Bounds height="20.0" width="100.0" x="548.0" y="126.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_Task_1" bpmnElement="Task_1">
<bpmndi:BPMNShape bpmnElement="Task_1" id="BPMNShape_Task_1">
<dc:Bounds height="50.0" width="110.0" x="170.0" y="83.0"/>
<bpmndi:BPMNLabel id="BPMNLabel_4" labelStyle="BPMNLabelStyle_1">
<dc:Bounds height="14.0" width="60.0" x="195.0" y="101.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_Task_2" bpmnElement="Task_2">
<bpmndi:BPMNShape bpmnElement="Task_2" id="BPMNShape_Task_2">
<dc:Bounds height="50.0" width="110.0" x="391.0" y="83.0"/>
<bpmndi:BPMNLabel id="BPMNLabel_5" labelStyle="BPMNLabelStyle_1">
<dc:Bounds height="14.0" width="30.0" x="431.0" y="101.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_IntermediateCatchEvent_1" bpmnElement="IntermediateCatchEvent_1">
<bpmndi:BPMNShape bpmnElement="IntermediateCatchEvent_1" id="BPMNShape_IntermediateCatchEvent_1">
<dc:Bounds height="36.0" width="36.0" x="320.0" y="90.0"/>
<bpmndi:BPMNLabel id="BPMNLabel_8" labelStyle="BPMNLabelStyle_1">
<dc:Bounds height="14.0" width="38.0" x="319.0" y="126.0"/>
<dc:Bounds height="20.0" width="100.0" x="288.0" y="126.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_IntermediateCatchEvent_2" bpmnElement="IntermediateCatchEvent_2">
<bpmndi:BPMNShape bpmnElement="IntermediateCatchEvent_2" id="BPMNShape_IntermediateCatchEvent_2">
<dc:Bounds height="36.0" width="36.0" x="428.0" y="200.0"/>
<bpmndi:BPMNLabel id="BPMNLabel_9" labelStyle="BPMNLabelStyle_1">
<dc:Bounds height="14.0" width="26.0" x="433.0" y="236.0"/>
<dc:Bounds height="20.0" width="100.0" x="396.0" y="236.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_1" bpmnElement="SequenceFlow_1" sourceElement="BPMNShape_1" targetElement="BPMNShape_Task_1">
<di:waypoint xsi:type="dc:Point" x="76.0" y="108.0"/>
<di:waypoint xsi:type="dc:Point" x="123.0" y="108.0"/>
<di:waypoint xsi:type="dc:Point" x="170.0" y="108.0"/>
<bpmndi:BPMNEdge bpmnElement="SequenceFlow_1" id="BPMNEdge_SequenceFlow_1" sourceElement="BPMNShape_1" targetElement="BPMNShape_Task_1">
<bpmndi:BPMNLabel id="BPMNLabel_3" labelStyle="BPMNLabelStyle_1"/>
<di:waypoint x="76.0" y="108.0"/>
<di:waypoint x="123.0" y="108.0"/>
<di:waypoint x="170.0" y="108.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_3" bpmnElement="SequenceFlow_3" sourceElement="BPMNShape_IntermediateCatchEvent_1" targetElement="BPMNShape_Task_2">
<di:waypoint xsi:type="dc:Point" x="356.0" y="108.0"/>
<di:waypoint xsi:type="dc:Point" x="373.0" y="108.0"/>
<di:waypoint xsi:type="dc:Point" x="373.0" y="108.0"/>
<di:waypoint xsi:type="dc:Point" x="391.0" y="108.0"/>
<bpmndi:BPMNEdge bpmnElement="SequenceFlow_3" id="BPMNEdge_SequenceFlow_3" sourceElement="BPMNShape_IntermediateCatchEvent_1" targetElement="BPMNShape_Task_2">
<bpmndi:BPMNLabel id="BPMNLabel_12" labelStyle="BPMNLabelStyle_1"/>
<di:waypoint x="356.0" y="108.0"/>
<di:waypoint x="391.0" y="108.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_6" bpmnElement="SequenceFlow_6" sourceElement="BPMNShape_IntermediateCatchEvent_2" targetElement="BPMNShape_Task_2">
<di:waypoint xsi:type="dc:Point" x="446.0" y="200.0"/>
<di:waypoint xsi:type="dc:Point" x="446.0" y="167.0"/>
<di:waypoint xsi:type="dc:Point" x="446.0" y="133.0"/>
<bpmndi:BPMNEdge bpmnElement="SequenceFlow_6" id="BPMNEdge_SequenceFlow_6" sourceElement="BPMNShape_IntermediateCatchEvent_2" targetElement="BPMNShape_Task_2">
<bpmndi:BPMNLabel id="BPMNLabel_17" labelStyle="BPMNLabelStyle_1"/>
<di:waypoint x="446.0" y="200.0"/>
<di:waypoint x="446.0" y="167.0"/>
<di:waypoint x="446.0" y="133.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_11" bpmnElement="SequenceFlow_11" sourceElement="BPMNShape_Task_1" targetElement="BPMNShape_IntermediateCatchEvent_1">
<di:waypoint xsi:type="dc:Point" x="280.0" y="108.0"/>
<di:waypoint xsi:type="dc:Point" x="300.0" y="108.0"/>
<di:waypoint xsi:type="dc:Point" x="320.0" y="108.0"/>
<bpmndi:BPMNEdge bpmnElement="SequenceFlow_11" id="BPMNEdge_SequenceFlow_11" sourceElement="BPMNShape_Task_1" targetElement="BPMNShape_IntermediateCatchEvent_1">
<bpmndi:BPMNLabel id="BPMNLabel_25"/>
<di:waypoint x="280.0" y="108.0"/>
<di:waypoint x="300.0" y="108.0"/>
<di:waypoint x="320.0" y="108.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_5" bpmnElement="SequenceFlow_5" sourceElement="BPMNShape_Task_2" targetElement="BPMNShape_2">
<di:waypoint xsi:type="dc:Point" x="501.0" y="108.0"/>
<di:waypoint xsi:type="dc:Point" x="570.0" y="108.0"/>
<di:waypoint xsi:type="dc:Point" x="580.0" y="108.0"/>
<bpmndi:BPMNEdge bpmnElement="SequenceFlow_5" id="BPMNEdge_SequenceFlow_5" sourceElement="BPMNShape_Task_2" targetElement="BPMNShape_2">
<bpmndi:BPMNLabel id="BPMNLabel_16"/>
<di:waypoint x="501.0" y="108.0"/>
<di:waypoint x="570.0" y="108.0"/>
<di:waypoint x="580.0" y="108.0"/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
<bpmndi:BPMNLabelStyle id="BPMNLabelStyle_1">
<dc:Font name="arial" size="9.0"/>
</bpmndi:BPMNLabelStyle>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>
</bpmn2:definitions>

0 comments on commit 2924a68

Please sign in to comment.