cancel
Showing results for 
Search instead for 
Did you mean: 

taskService.createTaskQuery() not returning values in unit test

rogerparkinson
Champ in-the-making
Champ in-the-making
Here's a simple unit test snippet:

public class ProcessTestMyProcess {

   private String filename = "/home/roger/activiti/ghi-core-processes/NMC.bpmn";

   @Rule
   public ActivitiRule activitiRule = new ActivitiRule();

   @Test
   public void startProcess() throws Exception {
      RepositoryService repositoryService = activitiRule.getRepositoryService();
      repositoryService.createDeployment().addInputStream("myProcess.bpmn20.xml",
            new FileInputStream(filename)).deploy();
      RuntimeService runtimeService = activitiRule.getRuntimeService();
      TaskService taskService = activitiRule.getTaskService();
      Map<String, Object> variableMap = new HashMap<String, Object>();
      variableMap.put("name", "Activiti");
      variableMap.put("claimId", "test");
      ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess", variableMap);
      final String pid = processInstance.getId();
      assertNotNull(pid);
      
      List<String> activityIds = runtimeService.getActiveActivityIds(pid);
      assertEquals(activityIds.size(),1);
      assertEquals("reviewClaim", activityIds.get(0));
      
      Task task = taskService.createTaskQuery().processInstanceId(pid).singleResult();
      assertNotNull(task);
      …
That last assert fails, variable task is null.
I expected it to find a task corresponding to my 'reviewClaim' userTask:

    <userTask id="reviewClaim" name="Review Claim" activiti:async="true" activiti:assignee="kermit">
      <extensionElements>
        <activiti:formProperty id="claimId" name="Claim" type="long" writable="false" required="true"></activiti:formProperty>
      </extensionElements>
    </userTask>

I tried
Task task = taskService.createTaskQuery().taskAssignee("kermit").singleResult();
but got the same result.
The only odd thing I can think of about the process it it has a serviceTask executed first, then an exclusive gateway and then this userTask. But that doesn't seem so very odd. Based on the contents of activityIds it clearly went to the right userTask, but I need the Task to do the next step ie
taskService.complete(task.getId())


What have I misunderstood here?
2 REPLIES 2

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Roger,

activiti:async="true"

there are 2 possibilities:
    # let jobexecutor to execute all jobs (is job executor running? do you wait for execute all jobs?),
    # make user task synchronous.
regards
Martin

rogerparkinson
Champ in-the-making
Champ in-the-making
Option #2 worked for me. Thanks.