Skip to content

Commit

Permalink
fixed parseInt error, added JUnit tests for WorkflowKernel
Browse files Browse the repository at this point in the history
issue #299
  • Loading branch information
rsoika committed Sep 10, 2017
1 parent 613588f commit 3649f35
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ private ItemCollection getNextTask(ItemCollection documentContext, ItemCollectio
String key = entry.getKey();
String expression = entry.getValue();
if (key.startsWith("task=")) {
int taskID=Integer.parseInt(key.substring(4));
int taskID=Integer.parseInt(key.substring(5));
boolean bmatch=ruleEngine.evaluateBooleanExpression(expression, documentContext);
if (bmatch) {
logger.fine("matching conditional event: " + expression);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package org.imixs.workflow;

import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;

import javax.xml.parsers.ParserConfigurationException;

import org.imixs.workflow.bpmn.BPMNParser;
import org.imixs.workflow.exceptions.ModelException;
import org.xml.sax.SAXException;

/**
* Static mokup model
Expand Down Expand Up @@ -32,6 +40,21 @@ public MokModelManager() {
}



/**
* Load a test model by filename
* @throws IOException
* @throws SAXException
* @throws ParserConfigurationException
* @throws ParseException
* @throws ModelException
**/
public MokModelManager(String sModelPath) throws ParseException, ParserConfigurationException, SAXException, IOException, ModelException {
InputStream inputStream = getClass().getResourceAsStream(sModelPath);
model = BPMNParser.parseModel(inputStream, "UTF-8");
}


@Override
public Model getModel(String version) throws ModelException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@
import org.mockito.Mockito;

/**
* Test class for workflow kernel
* Test class for Imixs WorkflowKernel using a static default model. The test
* class verifies basic functionality. See the test class
* TestWorklfowKernelTestModels for more complex model tests.
*
* @author rsoika
*
*/
public class KernelTest {
public class TestWorkflowKernelDefaultModel {

WorkflowKernel kernel = null;
protected SessionContext ctx;
protected WorkflowContext workflowContext;
private static Logger logger = Logger.getLogger(KernelTest.class.getName());
private static Logger logger = Logger.getLogger(TestWorkflowKernelDefaultModel.class.getName());

@Before
public void setup() throws PluginException {
Expand Down Expand Up @@ -70,7 +71,7 @@ public void testProcess() {
Assert.assertEquals(itemCollection.getItemValueString("txttitel"), "Hello");

try {
itemCollection=kernel.process(itemCollection);
itemCollection = kernel.process(itemCollection);
} catch (PluginException e) {
Assert.fail();
e.printStackTrace();
Expand All @@ -86,7 +87,6 @@ public void testProcess() {
Assert.assertEquals(100, itemCollection.getItemValueInteger("$processid"));
}


/**
* This if a plugin which returns null influences the workitem
*/
Expand All @@ -107,14 +107,14 @@ public void testProcessNullPlugin() {

MokPluginNull mokPlugin = new MokPluginNull();
kernel.registerPlugin(mokPlugin);
itemCollection.replaceItemValue("txtname","test");
itemCollection.replaceItemValue("txtname", "test");

kernel.process(itemCollection);
// kernel should throw exception...
Assert.fail();
} catch (PluginException e) {
Assert.assertEquals(WorkflowKernel.PLUGIN_ERROR,e.getErrorCode());
Assert.assertEquals(WorkflowKernel.PLUGIN_ERROR, e.getErrorCode());

} catch (ProcessingErrorException e) {
Assert.fail();
e.printStackTrace();
Expand All @@ -126,8 +126,7 @@ public void testProcessNullPlugin() {
Assert.assertEquals("test", itemCollection.getItemValueString("txtname"));
Assert.assertEquals(100, itemCollection.getItemValueInteger("$processid"));
}



@Test
@Category(org.imixs.workflow.WorkflowKernel.class)
public void testForward() {
Expand All @@ -140,7 +139,7 @@ public void testForward() {
Assert.assertEquals(itemCollection.getItemValueString("txttitel"), "Hello");

try {
itemCollection=kernel.process(itemCollection);
itemCollection = kernel.process(itemCollection);
} catch (PluginException e) {
Assert.fail();
e.printStackTrace();
Expand Down Expand Up @@ -169,7 +168,7 @@ public void testFollowup() {
Assert.assertEquals(itemCollection.getItemValueString("txttitel"), "Hello");

try {
itemCollection=kernel.process(itemCollection);
itemCollection = kernel.process(itemCollection);
} catch (PluginException e) {
Assert.fail();
e.printStackTrace();
Expand Down Expand Up @@ -235,13 +234,13 @@ public void testActivityLog() {
try {
// simulate two steps
itemCollection.replaceItemValue("$activityid", 10);
itemCollection=kernel.process(itemCollection);
itemCollection = kernel.process(itemCollection);

itemCollection.replaceItemValue("$activityid", 20);
// sumulate a Log Comment...
itemCollection.replaceItemValue("txtworkflowactivitylogComment", "userid|comment");

itemCollection=kernel.process(itemCollection);
itemCollection = kernel.process(itemCollection);

} catch (PluginException e) {
Assert.fail();
Expand Down Expand Up @@ -311,8 +310,8 @@ public void testActivityLog() {
}

/**
* This method tests the generation of the txtworkflowactivitylog entries
* and the restriction to a maximum length of 30 entries.
* This method tests the generation of the txtworkflowactivitylog entries and
* the restriction to a maximum length of 30 entries.
*
* Issue https://github.com/imixs/imixs-workflow/issues/179
*
Expand All @@ -337,13 +336,13 @@ public void testActivityLogMaxLength() {
try {
// simulate two steps
itemCollection.replaceItemValue("$activityid", 10);
itemCollection=kernel.process(itemCollection);
itemCollection = kernel.process(itemCollection);

itemCollection.replaceItemValue("$activityid", 20);
// sumulate a Log Comment...
itemCollection.replaceItemValue("txtworkflowactivitylogComment", "userid|comment");

itemCollection=kernel.process(itemCollection);
itemCollection = kernel.process(itemCollection);

} catch (PluginException e) {
Assert.fail();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
package org.imixs.workflow;

import static org.mockito.Mockito.when;

import java.io.IOException;
import java.security.Principal;
import java.text.ParseException;
import java.util.logging.Logger;

import javax.ejb.SessionContext;
import javax.xml.parsers.ParserConfigurationException;

import org.imixs.workflow.exceptions.ModelException;
import org.imixs.workflow.exceptions.PluginException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;
import org.xml.sax.SAXException;

/**
* Test class for Imixs WorkflowKernel using the test models. The test class
* verifies complex model situations based on the test models.
*
* @author rsoika
*
*/
public class TestWorkflowKernelTestModels {

WorkflowKernel kernel = null;
protected SessionContext ctx;
protected WorkflowContext workflowContext;
private static Logger logger = Logger.getLogger(TestWorkflowKernelTestModels.class.getName());

@Before
public void setup() throws PluginException, ModelException, ParseException, ParserConfigurationException,
SAXException, IOException {

ctx = Mockito.mock(SessionContext.class);
// simulate SessionContext ctx.getCallerPrincipal().getName()
Principal principal = Mockito.mock(Principal.class);
when(principal.getName()).thenReturn("manfred");
when(ctx.getCallerPrincipal()).thenReturn(principal);

workflowContext = Mockito.mock(WorkflowContext.class);

// MokWorkflowContext ctx = new MokWorkflowContext();
kernel = new WorkflowKernel(workflowContext);

MokPlugin mokPlugin = new MokPlugin();
kernel.registerPlugin(mokPlugin);

logger.fine("init mocks completed");
}

/**
* Simple test
*
* @throws IOException
* @throws SAXException
* @throws ParserConfigurationException
* @throws ParseException
* @throws ModelException
*/
@Test
@Category(org.imixs.workflow.WorkflowKernel.class)
public void testSimpleModel() {
try {
// provide a mock modelManger class
when(workflowContext.getModelManager()).thenReturn(new MokModelManager("/bpmn/simple.bpmn"));

ItemCollection itemCollection = new ItemCollection();
itemCollection.replaceItemValue("txtTitel", "Hello");
itemCollection.replaceItemValue("$processid", 1000);
itemCollection.replaceItemValue("$activityid", 10);

itemCollection.replaceItemValue("$modelversion", MokModel.DEFAULT_MODEL_VERSION);

itemCollection = kernel.process(itemCollection);
Assert.assertEquals("Hello", itemCollection.getItemValueString("txttitel"));

Assert.assertEquals(1100, itemCollection.getProcessID());

} catch (Exception e) {
Assert.fail();
e.printStackTrace();
}

}

/**
* ticket.bpmn test
*
* @throws IOException
* @throws SAXException
* @throws ParserConfigurationException
* @throws ParseException
* @throws ModelException
*/
@Test
@Category(org.imixs.workflow.WorkflowKernel.class)
public void testTicketModel() {
try {
// provide a mock modelManger class
when(workflowContext.getModelManager()).thenReturn(new MokModelManager("/bpmn/ticket.bpmn"));

ItemCollection itemCollection = new ItemCollection();
itemCollection.replaceItemValue("txtTitel", "Hello");
itemCollection.replaceItemValue("$processid", 1100);
itemCollection.replaceItemValue("$activityid", 20);

itemCollection.replaceItemValue("$modelversion", MokModel.DEFAULT_MODEL_VERSION);

itemCollection = kernel.process(itemCollection);
Assert.assertEquals("Hello", itemCollection.getItemValueString("txttitel"));

Assert.assertEquals(1200, itemCollection.getProcessID());

} catch (Exception e) {
Assert.fail();
e.printStackTrace();
}

}

/**
* Test conditional-event models.
*
* @throws IOException
* @throws SAXException
* @throws ParserConfigurationException
* @throws ParseException
* @throws ModelException
*/
@Test
@Category(org.imixs.workflow.WorkflowKernel.class)
public void testConditionalEventModel() {
try {
// provide a mock modelManger class
when(workflowContext.getModelManager()).thenReturn(new MokModelManager("/bpmn/conditional_event1.bpmn"));

// test Condition 1
ItemCollection itemCollection = new ItemCollection();
itemCollection.replaceItemValue("txtTitel", "Hello");
itemCollection.replaceItemValue("$processid", 1000);
itemCollection.replaceItemValue("$activityid", 10);
itemCollection.replaceItemValue("$modelversion", MokModel.DEFAULT_MODEL_VERSION);

itemCollection.replaceItemValue("_budget", 99);

itemCollection = kernel.process(itemCollection);
Assert.assertEquals("Hello", itemCollection.getItemValueString("txttitel"));
Assert.assertEquals(1200, itemCollection.getProcessID());

// test Condition 2
itemCollection = new ItemCollection();
itemCollection.replaceItemValue("txtTitel", "Hello");
itemCollection.replaceItemValue("$processid", 1000);
itemCollection.replaceItemValue("$activityid", 10);
itemCollection.replaceItemValue("$modelversion", MokModel.DEFAULT_MODEL_VERSION);

itemCollection.replaceItemValue("_budget", 9999);

itemCollection = kernel.process(itemCollection);
Assert.assertEquals("Hello", itemCollection.getItemValueString("txttitel"));

Assert.assertEquals(1100, itemCollection.getProcessID());

} catch (Exception e) {
Assert.fail();
e.printStackTrace();

}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@

import javax.xml.parsers.ParserConfigurationException;

import junit.framework.Assert;

import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.exceptions.ModelException;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.xml.sax.SAXException;

import junit.framework.Assert;

/**
* Test class test the Imixs BPMNParser.
*
Expand Down
2 changes: 1 addition & 1 deletion imixs-workflow-core/src/test/resources/bpmn/simple.bpmn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?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.2.201512032052" targetNamespace="http://www.imixs.org/bpmn2">
<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.4.2.RC1-v20170907-1720-B1" targetNamespace="http://www.imixs.org/bpmn2">
<bpmn2:extensionElements>
<imixs:item name="txtworkflowmodelversion" type="xs:string">
<imixs:value><![CDATA[1.0.0]]></imixs:value>
Expand Down
2 changes: 1 addition & 1 deletion imixs-workflow-core/src/test/resources/bpmn/ticket.bpmn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?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.2.201512032052" targetNamespace="http://www.imixs.org/bpmn2">
<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.4.2.RC1-v20170907-1720-B1" targetNamespace="http://www.imixs.org/bpmn2">
<bpmn2:extensionElements>
<imixs:item name="txtfieldmapping" type="xs:string">
<imixs:value><![CDATA[Manager|namManager]]></imixs:value>
Expand Down

0 comments on commit 3649f35

Please sign in to comment.