Skip to content

Commit

Permalink
refactoring WofklowKernel, changed junit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoika committed Jun 7, 2018
1 parent 1fd5e27 commit 6abc1b9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public class WorkflowKernel {
public static final String WORKITEMID = "$workitemid";
public static final String MODELVERSION = "$modelversion";

@Deprecated
public static final String PROCESSID = "$processid";
//public static final String ACTIVITYID = "$activityid";

public static final String TASKID = "$taskid";
public static final String EVENTID = "$eventid";
Expand Down Expand Up @@ -257,16 +257,16 @@ public ItemCollection process(final ItemCollection workitem) throws PluginExcept
throw new ProcessingErrorException(WorkflowKernel.class.getSimpleName(), UNDEFINED_WORKITEM,
"processing error: workitem is null");

// check $processID
if (workitem.getItemValueInteger(PROCESSID) <= 0)
// check $TaskID
if (workitem.getTaskID() <= 0)
throw new ProcessingErrorException(WorkflowKernel.class.getSimpleName(), UNDEFINED_PROCESSID,
"processing error: $processid undefined (" + workitem.getItemValueInteger(PROCESSID) + ")");
"processing error: $taskID undefined (" + workitem.getTaskID() + ")");


// check $eventId
if (workitem.getEventID() <= 0)
throw new ProcessingErrorException(WorkflowKernel.class.getSimpleName(), UNDEFINED_ACTIVITYID,
"processing error: $eventid undefined (" + workitem.getEventID() + ")");
"processing error: $eventID undefined (" + workitem.getEventID() + ")");


ItemCollection documentResult = new ItemCollection(workitem);
Expand Down Expand Up @@ -323,7 +323,7 @@ public ItemCollection findNextTask(ItemCollection documentContext, ItemCollectio
ItemCollection itemColNextTask = null;

int iNewProcessID = event.getItemValueInteger("numnextprocessid");
logger.finest("......next $processid=" + iNewProcessID + "");
logger.finest("......next $taskID=" + iNewProcessID + "");

// test if we have an conditional exclusive Task exits...
itemColNextTask = findConditionalExclusiveTask(event, documentContext);
Expand Down Expand Up @@ -406,7 +406,7 @@ private ItemCollection updateEventList(final ItemCollection documentContext) {
* Before a plug-in is called the method updates the 'type' attribute defined by
* the next Task.
*
* After all plug-ins are processed, the attributes $processid, $workflowstatus
* After all plug-ins are processed, the attributes $taskID, $workflowstatus
* and $workflowgroup are updated.
*
* If an FollowUp Activity is defined (keyFollowUp="1" & numNextActivityID>0)
Expand All @@ -419,8 +419,8 @@ private ItemCollection processEvent(final ItemCollection documentContext, final
ItemCollection documentResult = documentContext;
// log the general processing message
String msg = "processing=" + documentContext.getItemValueString(UNIQUEID) + ", MODELVERSION="
+ documentContext.getItemValueString(MODELVERSION) + ", $processid="
+ documentContext.getItemValueInteger(PROCESSID) + ", $eventid="
+ documentContext.getItemValueString(MODELVERSION) + ", $taskID="
+ documentContext.getTaskID() + ", $eventID="
+ documentContext.getEventID();

if (ctx == null) {
Expand Down Expand Up @@ -464,10 +464,9 @@ private ItemCollection processEvent(final ItemCollection documentContext, final
// instance.
evaluateSplitEvent(event, documentResult);

// Update the attributes $ProcessID and $WorkflowStatus
documentResult.replaceItemValue(PROCESSID,
Integer.valueOf(itemColNextTask.getItemValueInteger("numprocessid")));
logger.finest("......new $processid=" + documentResult.getTaskID());
// Update the attributes $taskID and $WorkflowStatus
documentResult.setTaskID(Integer.valueOf(itemColNextTask.getItemValueInteger("numprocessid")));
logger.finest("......new $taskID=" + documentResult.getTaskID());
documentResult.replaceItemValue(WORKFLOWSTATUS, itemColNextTask.getItemValueString("txtname"));
logger.finest("......new $workflowStatus=" + documentResult.getItemValueString(WORKFLOWSTATUS));
// update deprecated attributes txtworkflowStatus and txtworkflowGroup
Expand Down Expand Up @@ -696,10 +695,8 @@ private void evaluateSplitEvent(ItemCollection event, ItemCollection documentCon
// clone current instance to a new version...
ItemCollection cloned = createVersion(documentContext);
logger.finest("......created new version=" + cloned.getUniqueID());
// set new $processid
cloned.replaceItemValue(PROCESSID,
Integer.valueOf(itemColNextTask.getItemValueInteger("numprocessid")));

// set new $taskID
cloned.setTaskID(Integer.valueOf(itemColNextTask.getItemValueInteger("numprocessid")));
cloned.setEventID(eventID);
// add temporary attribute $isversion...
cloned.replaceItemValue(ISVERSION, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ public interface WorkflowManager {

/**
* This method processes a workItem. The workItem needs at least provide the
* valid attributes $ProcessID and $EventID (integer values) to identify
* valid attributes $taskID and $EventID (integer values) to identify
* the current processEntity the workItem belongs to and the concrete
* activtyEntity which should be processed by the wokflowManager
* implementation. If the workItem is new the method creates a new instance
* for the corresoponding process.
* for the corresponding process.
*
* The method is responsible to persist the workItem after successfully
* processing. The method returns the workItem with additional workflow
* informations defined by the workfowManager Implementation.
*
* The Method throws an InvalidWorkitemException if the provided workItem is
* invalid or the provided attributes $ProcessID and $EventID (integer)
* invalid or the provided attributes $taskID and $EventID (integer)
* did not match an valid modelEntity the workItem can be processed to.
*
* @param workitem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public void testBasicAttributes() {
ItemCollection itemCollection1 = new ItemCollection();

itemCollection1.replaceItemValue(WorkflowKernel.MODELVERSION, "1.0.0");
itemCollection1.replaceItemValue(WorkflowKernel.PROCESSID, 100);
itemCollection1.replaceItemValue(WorkflowKernel.TASKID, 100);
itemCollection1.replaceItemValue(WorkflowKernel.EVENTID, 10);
itemCollection1.replaceItemValue(WorkflowKernel.TYPE, "workitem_test");
itemCollection1.replaceItemValue(WorkflowKernel.UNIQUEID, "ABC-123");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testProcess() {
ItemCollection itemCollectionProcessed=null;
ItemCollection itemCollection = new ItemCollection();
itemCollection.replaceItemValue("txtTitel", "Hello");
itemCollection.replaceItemValue("$processid", 100);
itemCollection.setTaskID(100);
itemCollection.setEventID(10);
itemCollection.replaceItemValue("$modelversion", MokModel.DEFAULT_MODEL_VERSION);

Expand All @@ -85,7 +85,7 @@ public void testProcess() {
}

Assert.assertEquals(1, itemCollectionProcessed.getItemValueInteger("runs"));
Assert.assertEquals(100, itemCollectionProcessed.getItemValueInteger("$processid"));
Assert.assertEquals(100, itemCollectionProcessed.getTaskID());

// initial and processed workitems are not the same and not equals!
Assert.assertNotSame(itemCollection, itemCollectionProcessed);
Expand Down Expand Up @@ -139,7 +139,7 @@ public void testProcessWithDeprecatedField() {
public void testProcessNullPlugin() {
ItemCollection itemCollection = new ItemCollection();
itemCollection.replaceItemValue("txtTitel", "Hello");
itemCollection.replaceItemValue("$processid", 100);
itemCollection.setTaskID(100);
itemCollection.setEventID(10);
itemCollection.replaceItemValue("$modelversion", MokModel.DEFAULT_MODEL_VERSION);

Expand Down Expand Up @@ -205,7 +205,7 @@ public void testForward() {
public void testFollowup() {
ItemCollection itemCollection = new ItemCollection();
itemCollection.replaceItemValue("txtTitel", "Hello");
itemCollection.replaceItemValue("$processid", 100);
itemCollection.setTaskID(100);
itemCollection.setEventID(11);
itemCollection.replaceItemValue("$modelversion", MokModel.DEFAULT_MODEL_VERSION);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void testSimpleModel() {
itemCollection = kernel.process(itemCollection);
Assert.assertEquals("Hello", itemCollection.getItemValueString("txttitel"));

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

} catch (Exception e) {
Assert.fail();
Expand All @@ -108,15 +108,15 @@ public void testTicketModel() {

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

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

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

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

} catch (Exception e) {
Assert.fail();
Expand Down Expand Up @@ -146,20 +146,20 @@ public void testConditionalEventModel1() {
// test Condition 1
ItemCollection itemCollection = new ItemCollection();
itemCollection.replaceItemValue("txtTitel", "Hello");
itemCollection.replaceItemValue("$processid", 1000);
itemCollection.setTaskID(1000);
itemCollection.setEventID(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());
Assert.assertEquals(1200, itemCollection.getTaskID());

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

Expand All @@ -168,7 +168,7 @@ public void testConditionalEventModel1() {
itemCollection = kernel.process(itemCollection);
Assert.assertEquals("Hello", itemCollection.getItemValueString("txttitel"));

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

} catch (Exception e) {
Assert.fail();
Expand Down Expand Up @@ -199,29 +199,26 @@ public void testConditionalEventModel2() {
// test Condition 1
ItemCollection itemCollection = new ItemCollection();
itemCollection.replaceItemValue("txtTitel", "Hello");
itemCollection.replaceItemValue("$processid", 1000);
itemCollection.setTaskID(1000);
itemCollection.setEventID(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());
Assert.assertEquals(1100, itemCollection.getTaskID());

// test Condition 2
itemCollection = new ItemCollection();
itemCollection = new ItemCollection().model(MokModel.DEFAULT_MODEL_VERSION).task(1000).event(10);
itemCollection.replaceItemValue("txtTitel", "Hello");
itemCollection.replaceItemValue("$processid", 1000);
itemCollection.setEventID(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());
Assert.assertEquals(1200, itemCollection.getTaskID());

} catch (Exception e) {
Assert.fail();
Expand Down Expand Up @@ -258,7 +255,7 @@ public void testSplitEventModel1() {

itemCollection = kernel.process(itemCollection);
Assert.assertEquals("Hello", itemCollection.getItemValueString("_subject"));
Assert.assertEquals(1100, itemCollection.getProcessID());
Assert.assertEquals(1100, itemCollection.getTaskID());
Assert.assertEquals(10, itemCollection.getItemValueInteger("$lastEvent"));

// test new version...
Expand All @@ -268,7 +265,7 @@ public void testSplitEventModel1() {
ItemCollection version = versions.get(0);

Assert.assertEquals("Hello", version.getItemValueString("_subject"));
Assert.assertEquals(1200, version.getProcessID());
Assert.assertEquals(1200, version.getTaskID());
// $lastEvent should be 20
Assert.assertEquals(20, version.getItemValueInteger("$lastEvent"));

Expand Down

0 comments on commit 6abc1b9

Please sign in to comment.