Below is a simple unit test.  What I am trying to do is set some values in the 
context on creation of the task in the start state.  The event is firing and my 
action "SetupSuspiciousTransaction" is being run.  This action sets variables 
in the context.  Later on I try to retrieve the variables and there values in 
the method "retrieveVariables".  When I step through this method "mappedName" 
has the right variable name but "value" has null as the value.  I was expecting 
to get back the values I had put in earlier.


  | import java.io.InputStream;
  | import java.util.Iterator;
  | import java.util.List;
  | 
  | import org.jbpm.JbpmConfiguration;
  | import org.jbpm.JbpmContext;
  | import org.jbpm.context.def.VariableAccess;
  | import org.jbpm.graph.def.ProcessDefinition;
  | import org.jbpm.graph.exe.ProcessInstance;
  | import org.jbpm.taskmgmt.def.TaskController;
  | import org.jbpm.taskmgmt.exe.TaskInstance;
  | import junit.framework.TestCase;
  | 
  | public class TaskEventTestCase extends TestCase {
  |     static JbpmConfiguration jbpmConfiguration = null ;
  |     
  |     public TaskEventTestCase(){
  |             super("TaskEventTestCase") ;
  |     }
  |     
  |     static {
  |         InputStream is = 
ClassLoader.getSystemResourceAsStream("default.jbpm.cfg.xml");
  |         jbpmConfiguration = JbpmConfiguration.parseInputStream(is) ;
  |     }
  | 
  |     public void testSimplePersistence(){
  |             deployProcessDefinition() ;
  |             createStartTask() ;
  |     }
  |     
  |     public static void main(String[] args){
  |             new TaskEventTestCase().testSimplePersistence() ;
  |     }
  |     
  |     public void createStartTask(){
  |             JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext() 
;
  |             try{
  |                     jbpmContext.setActorId("Fraud Investigator");           
                        
  |                 ProcessInstance processInstance = null;
  |                 processInstance = jbpmContext.newProcessInstance("test");   
                 
  |                 TaskInstance result = null;
  |                 result = 
processInstance.getTaskMgmtInstance().createStartTaskInstance();
  |                 jbpmContext.save(processInstance) ;
  |                 retrieveVariables(result) ;
  |             }
  |             catch (Exception e){
  |                     throw new RuntimeException(e.getMessage()) ;
  |             } finally {
  |                     jbpmContext.close() ;
  |             }
  |     }
  |     
  |     protected void retrieveVariables(TaskInstance ti){
  |         TaskController taskController = ti.getTask().getTaskController();
  |         if (taskController!=null) {
  |           List variableAccesses = taskController.getVariableAccesses();
  |           Iterator iter = variableAccesses.iterator();
  |           while (iter.hasNext()) {
  |             VariableAccess variableAccess = (VariableAccess) iter.next();
  |             String mappedName = variableAccess.getMappedName();
  |             String value = (String)ti.getVariable(mappedName);
  |           }
  |         }           
  |     }
  |     public void deployProcessDefinition(){
  |             ProcessDefinition processDefinition = 
ProcessDefinition.parseXmlString(
  |                             "<process-definition name='test'>" + 
  |                             "<start-state name='state1'>" + 
  |                             "<task name='Investigate Transaction' 
swimlane='Fraud Investigator'>" + 
  |                             "<controller>" + 
  |                             "<variable name='transaction value' 
access='read,write,required'></variable>" + 
  |                             "<variable name='account number' 
access='read,write,required'></variable>" + 
  |                             "<variable name='transaction status' 
access='read,write,required'></variable>" + 
  |                             "</controller>" + 
  |                             "<event type='task-create'>" +
  |                             "       <action 
class='com.nr.tms.workflow.objectservices.actionhandlers.SetupSuspiciousTransaction'/>"
 +
  |                             "</event>" +
  |                             "</task>" +
  |                             "<transition name='default' 
to='end1'></transition>" + 
  |                             "</start-state>" + 
  |                             "<end-state name='end1'></end-state>" +
  |                             "</process-definition>"
  |             ) ; 
  |             
  |             JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext() 
;
  |             try{
  |                     jbpmContext.deployProcessDefinition(processDefinition) ;
  |             } finally {
  |                     jbpmContext.close() ;
  |             }
  |     }
  | }
  | 
  | 

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

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4128834
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to