In Camunda workflow, exclusive gateway have below expression to check if instance with same business key running.
Expression: ${historyService.createHistoricProcessInstanceQuery().processInstanceBusinessKey(execution.getProcessBusinessKey()).active().count() > 0}
Workflow is running as expected but in junit test case using scenario library getting below error:
org.camunda.bpm.engine.ProcessEngineException: Unknown property used in expression: ${historyService.createHistoricProcessInstanceQuery().processInstanceBusinessKey(execution.getProcessBusinessKey()).active().count() > 0}. Cause: Cannot resolve identifier ‘historyService’
at org.camunda.bpm.engine.impl.el.JuelExpression.getValue(JuelExpression.java:63)
Attaching the junit test case and workflow with the post. Please can someone guide to solve the issue
Junit Test Case:
package com.testcase.automation.samples;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.camunda.bpm.engine.ProcessEngineConfiguration;
import org.camunda.bpm.engine.test.Deployment;
import org.camunda.bpm.engine.test.ProcessEngineRule;
import org.camunda.bpm.engine.test.RequiredHistoryLevel;
import org.camunda.bpm.scenario.ProcessScenario;
import org.camunda.bpm.scenario.Scenario;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
public class CheckInstanceRunning {
@Rule
public ProcessEngineRule processEngineRule = new ProcessEngineRule();
public ProcessScenario scenario = mock(ProcessScenario.class);
@Before
public void setUp() throws Exception {
when(scenario.waitsAtUserTask("Activity_0q9mdpf")).thenReturn(userTask -> {
userTask.complete();
});
}
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL)
@Deployment(resources = { "bpmn/sample/check_instance_running.bpmn" })
public void test() {
String businessKey = "12345";
Scenario.run(scenario)
.startByKey("CheckInstanceRunning", businessKey)
.execute();
}
}
Thanks
Mahantesh
check_instance_running.bpmn (4.8 KB)