ProcessInstance pi = new ProcessInstance( pd );
TaskMgmtInstance taskMgmtInstance = (TaskMgmtInstance) pi.getInstance(TaskMgmtInstance.class);
pi.signal();
Token token = pi.getRootToken();
// after start, the token is waiting in state b
assertSame( pd.getNode("b"), token.getNode() );
// and no tasks have been created yet
assertEquals(0, taskMgmtInstance.getUnfinishedTasks(token).size() );
// now we signal the process to move on.
// execution will arrive at the task-node
// the default behaviour of the task node is to create each task and wait till the last one finishes
pi.signal();
// now, 3 tasks have been created...
List tasks = new ArrayList( taskMgmtInstance.getUnfinishedTasks(token) );
assertEquals(3, tasks.size());
// ... and the process is in the task state
assertSame( pd.getNode("t"), token.getNode() );
// now we finish the tasks one by one
// finish task 0
((TaskInstance)tasks.get(0)).end();
// still 2 tasks remaining
assertEquals(2, taskMgmtInstance.getUnfinishedTasks(token).size() );
// and the process is still in node t
assertSame( pd.getNode("t"), token.getNode() );
// finish task 1
((TaskInstance)tasks.get(1)).end();
// still 1 task remaining
assertEquals(1, taskMgmtInstance.getUnfinishedTasks(token).size() );
// and the process is still in node t
assertSame( pd.getNode("t"), token.getNode() );
// finish task 2
((TaskInstance)tasks.get(2)).end();
// no more tasks remaining
assertEquals(0, taskMgmtInstance.getUnfinishedTasks(token).size() );
// and the process has moved to node c
assertEquals( pd.getNode("c"), token.getNode() );
}