AnsweredAssumed Answered

Unable to get a variable set in service task

Question asked by gouthr on Sep 24, 2014
Latest reply on Sep 24, 2014 by gouthr
I am new to Activiti and Java. I am trying to create a simple unit test to invoke a Java service task from Activiti engine. Below is a code snippet:

ServiceTask.java:


package test;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;

public class Servicetask implements JavaDelegate {
   public void execute(DelegateExecution execution) {
   
      System.out.println("execution id " + execution.getId());
   
      String empname = (String) execution.getVariable("Empname");
      
      System.out.println("received employee name " + empname);
      
      empname = empname.toUpperCase();
       execution.setVariable("input", empname);
    }

}

JUNIT test:
package org.activiti.designer.test;

import static org.junit.Assert.*;

import java.util.HashMap;
import java.util.Map;
import java.io.FileInputStream;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.test.ActivitiRule;
import org.junit.Rule;
import org.junit.Test;

public class ProcessTestLeaveProcess {

   private String filename = "C:\\junoWsp3\\SimpleLeave-Process\\src\\main\\resources\\diagrams\\SimpleLeaveProcess.bpmn";

   @Rule
   public ActivitiRule activitiRule = new ActivitiRule();

   @Test
   public void startProcess() throws Exception {
      RepositoryService repositoryService = activitiRule.getRepositoryService();
      repositoryService.createDeployment().addInputStream("SimpleLeaveProcess.bpmn20.xml",
            new FileInputStream(filename)).deploy();
      RuntimeService runtimeService = activitiRule.getRuntimeService();
      Map<String, Object> variableMap = new HashMap<String, Object>();
      variableMap.put("Empname", "Goutham");
      ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("leaveProcess", variableMap);
      assertNotNull(processInstance.getId());
      System.out.println("id " + processInstance.getId() + " "
            + processInstance.getProcessDefinitionId());

      String empnameBold = (String) runtimeService.getVariable(processInstance.getId(), "input");
      assertNotNull(empnameBold);

      System.out.println("Name in bold: " + empnameBold);
   }
}

When I run the above code, the last println line isn't displayed. What am I missing here?

Thanks!

Outcomes