AnsweredAssumed Answered

taskService.createTaskQuery() not returning values in unit test

Question asked by rogerparkinson on Apr 13, 2015
Latest reply on Apr 14, 2015 by rogerparkinson
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?

Outcomes