[jboss-dev-forums] [Design of JBoss jBPM] - extending decision test

kukeltje do-not-reply at jboss.com
Tue Jun 26 08:22:18 EDT 2007


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.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4057684#4057684

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4057684



More information about the jboss-dev-forums mailing list