AnsweredAssumed Answered

Query process instances by key with no results

Question asked by planetenxin on Jun 30, 2014
Latest reply on Jul 1, 2014 by martin.grofcik
I tried to query process instances with this simple test:

package org.activiti.designer.test;

import static org.junit.Assert.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.BeforeClass;
import org.junit.Test;

public class MyProcess_StartProcessWithParam_Test {

   private static RuntimeService runtimeService;

   @BeforeClass
   public static void init() throws Exception {
      ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration().buildProcessEngine();
      RepositoryService repositoryService = processEngine.getRepositoryService();
      repositoryService.createDeployment()
/         .addClasspathResource("MyProcess.bpmn")
         .deploy();
      runtimeService = processEngine.getRuntimeService();
   }
   
   @Test
   public void startProcessInstance() {
      Map<String, Object> variableMap = new HashMap<String, Object>();
      variableMap.put("param1", "123456");
      ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess", variableMap);
      assertNotNull(processInstance.getId());
      System.out.println("Process ID: " + processInstance.getId() + " " + processInstance.getProcessDefinitionId());
      
      // Query for running process instances
      List<ProcessInstance> instanceList = runtimeService.createProcessInstanceQuery().processDefinitionKey("myProcess").list();
      
      // Debug
      System.out.println(instanceList.isEmpty());
      
      for (ProcessInstance queryProcessInstance : instanceList) {
         assertEquals(false, queryProcessInstance.isEnded());
         System.out.println("id " + queryProcessInstance.getId() + ", ended=" + queryProcessInstance.isEnded());
      }
   }
}


A process instance has been created but the list of instances is empty. I get the following debug output:

Process ID: 5 myProcess:1:4
true


For some reason the process instances list is empty. What's wrong with my code?
* Activiti 5.14.1

Outcomes