cancel
Showing results for 
Search instead for 
Did you mean: 

Query process instances by key with no results

planetenxin
Champ in-the-making
Champ in-the-making
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
1 REPLY 1

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

What's wrong with my code?
I do not know. I have found almost the same jUnit test in the activiti sources. org.activiti.engine.test.api.runtime.RuntimeServiceTest#testStartProcessInstanceByIdNullVariablesIt should work.
Could you zip your jUnit test project and add it to the reply?

Regards
Martin