0 Replies Latest reply on Jun 26, 2007 8:22 AM by Ronald van Kuijk

    extending decision test

    Ronald van Kuijk Master

      Hi,

      I'm extending the desiciontest a little with access to custom object.

      i'm not sure though if it should be in the org.jbpm.jpdl.exe.DecisionConditionsTest or a new test in org.jbpm.jpdl.el (also called DecisionConditionsTest then)

      The code is:

      package org.jbpm.jpdl.[el|exe];
      
      import junit.framework.TestCase;
      
      import org.jbpm.graph.def.ProcessDefinition;
      import org.jbpm.graph.exe.ProcessInstance;
      
      public class DecisionConditionsTest extends TestCase {
      
       public static class Customer {
       String priority;
      
       int number;
      
       public Customer(String priority) {
       this.priority = priority;
       }
      
       public Customer(int number) {
       this.number = number;
       }
      
       public String getPriority() {
       return priority;
       }
      
       public int getNumber() {
       return number;
       }
       }
      
       public ProcessDefinition createCustomerPriorityProcess() {
       return ProcessDefinition.parseXmlString(
       "<process-definition>" +
       " <start-state>" +
       " <transition to='d'/>" +
       " </start-state>" +
       " <decision name='d'>" +
       " <transition to='l' >" +
       " <condition>#{customer.priority == 'LOW'}</condition>" +
       " </transition>" +
       " <transition to='m'>" +
       " <condition>#{customer.priority == 'MEDIUM'}</condition>" +
       " </transition>" +
       " <transition to='h'>" +
       " <condition>#{customer.priority == 'HIGH'}</condition>" +
       " </transition>" +
       " </decision>" +
       " <state name='l' />" +
       " <state name='m' />" +
       " <state name='h' />" +
       "</process-definition>"
       );
       }
      
       public void testCustomerPriorityLow() {
       ProcessDefinition processDefinition = createCustomerPriorityProcess();
       ProcessInstance processInstance = new ProcessInstance(processDefinition);
       processInstance.getContextInstance().setVariable("customer", new Customer("LOW"));
       processInstance.signal();
      
       assertEquals("l", processInstance.getRootToken().getNode().getName());
       }
      
       public void testCustomerPriorityMedium() {
       ProcessDefinition processDefinition = createCustomerPriorityProcess();
       ProcessInstance processInstance = new ProcessInstance(processDefinition);
       processInstance.getContextInstance().setVariable("customer", new Customer("MEDIUM"));
       processInstance.signal();
      
       assertEquals("m", processInstance.getRootToken().getNode().getName());
       }
      
       public void testCustomerPriorityHigh() {
       ProcessDefinition processDefinition = createCustomerPriorityProcess();
       ProcessInstance processInstance = new ProcessInstance(processDefinition);
       processInstance.getContextInstance().setVariable("customer", new Customer("HIGH"));
       processInstance.signal();
      
       assertEquals("h", processInstance.getRootToken().getNode().getName());
       }
      
       public void testCustomerPriorityUndefined() {
       ProcessDefinition processDefinition = createCustomerPriorityProcess();
       ProcessInstance processInstance = new ProcessInstance(processDefinition);
       processInstance.getContextInstance().setVariable("customer", new Customer("UNDEFINED"));
       processInstance.signal();
      
       // 'Default' transition
       assertEquals("l", processInstance.getRootToken().getNode().getName());
       }
      
       public void testCustomerPriorityNull() {
       ProcessDefinition processDefinition = createCustomerPriorityProcess();
       ProcessInstance processInstance = new ProcessInstance(processDefinition);
       processInstance.getContextInstance().setVariable("customer", new Customer(null));
       processInstance.signal();
      
       // 'Default' transition
       assertEquals("l", processInstance.getRootToken().getNode().getName());
       }
      }
      


      If it is a new class then with copyright info

      I think it should go in el.