3 Replies Latest reply on Nov 23, 2005 12:55 PM by Ronald van Kuijk

    A weird task-node error

    pedro costa Apprentice

      In this example, in the line

      log(token, task, "tn3", "t3", "Transition(to_tn4)");
      assertEquals("ADEUS", task.getActorId());

      Get the wrong task, but execute the right assignment class.
      It gives me task t2, and i expected task t3.

      I don't understand why. Any help?

      import org.jbpm.graph.def.ProcessDefinition;
      import org.jbpm.graph.exe.ProcessInstance;
      import org.jbpm.graph.exe.Token;
      import org.jbpm.taskmgmt.exe.TaskInstance;
      
      import junit.framework.*;
      
      public class TaskAssignmentTest extends TestCase {
      
       public void testTaskAssignment() {
       ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
       "<process-definition name='test'>" +
       " <start-state>" +
       " <transition name='to_tn1' to='tn1' />" +
       " </start-state>" +
      
       " <task-node name='tn1'>" +
       " <task name='t1'>" +
       " </task>" +
       " <transition name='to_state1' to='state1' />" +
       " </task-node>" +
      
       " <state name='state1'>" +
       " <transition name='to_tn2' to='tn2' />" +
       " </state>" +
      
       " <task-node name='tn2'>" +
       " <task name='t2'>" +
       " <assignment class='com.sample.jbpm.taskmgmt.Ola' />" +
       " </task>" +
       " <transition name='to_tn3' to='tn3' />" +
       " </task-node>" +
      
       " <task-node name='tn3'>" +
       " <task name='t3'>" +
       " <assignment class='com.sample.jbpm.taskmgmt.Adeus' />" +
       " </task>" +
       " <transition name='to_tn4' to='tn4' />" +
       " </task-node>" +
      
       " <task-node name='tn4'>" +
       " <task name='t4'>" +
       " </task>" +
       " <transition name='to_end' to='end' />" +
       " </task-node>" +
       /*
       " <state name='s'>" +
       " <transition name='to_end' to='end' />" +
       " </state>" +
       */
       " <end-state name='end' />" +
       "</process-definition>"
       );
      
       ProcessInstance processInstance = new ProcessInstance(processDefinition);
       processInstance.getInstances().values();
      
       Token token = processInstance.getRootToken();
       TaskInstance task = null;
      
       token.signal("to_tn1");
      
       //TN1
       task = (TaskInstance)processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
       System.out.println("---> " + token.getNode().getName());
       log(token, task, "tn1", "t1", "Transition(to_state1)");
       task.end("to_state1");
       //taskInstance.end();
      
       //STATE1
       //System.out.println(">>---> " + token.getNode().getName());
       //log(token, null);
       token.signal("to_tn2");
       token.end();
      
       //TN2
       task = (TaskInstance)processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
       //task.start();
       log(token, task, "tn2", "t2", "Transition(to_tn3)");
       assertEquals("OLA", task.getActorId());
       task.end("to_tn3");
      
       //TN3
       task = (TaskInstance)processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
       // Get the wrong task, but execute the right assignment class.
       log(token, task, "tn3", "t3", "Transition(to_tn4)");
       assertEquals("ADEUS", task.getActorId());
       task.end("to_tn4");
      
       // TN4
       task = (TaskInstance)processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
       log(token, task, "tn4", "t4", "Transition(to_end)");
      
       processInstance.end();
       }
      
       public void log(Token t, TaskInstance ti, String expectedTaskNode, String expectedTask, String expectedTransition)
       {
       assertEquals(expectedTaskNode, t.getNode().getName());
      
       if(ti != null) {
       assertEquals(expectedTask, ti.getTask().getName());
      
       for(int i=0; i<ti.getAvailableTransitions().size();i++)
       assertEquals(expectedTransition, ti.getAvailableTransitions().get(i).toString());
       }
       }
      }
      


      The other classes are:
      import org.jbpm.graph.exe.*;
      import org.jbpm.taskmgmt.def.*;
      import org.jbpm.taskmgmt.exe.Assignable;
      
      public class Adeus implements AssignmentHandler {
      
       private static final long serialVersionUID = 1L;
      
       public void assign(Assignable assignable, ExecutionContext executionContext) {
       assignable.setActorId("ADEUS");
       }
      
      }
      
      


      import org.jbpm.graph.exe.*;
      import org.jbpm.taskmgmt.def.*;
      import org.jbpm.taskmgmt.exe.Assignable;
      
      public class Ola implements AssignmentHandler {
      
       private static final long serialVersionUID = 1L;
      
       public void assign(Assignable assignable, ExecutionContext executionContext) {
       assignable.setActorId("OLA");
       }
      
      }
      
      


      Thanks.