use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testCompleteSuspendedTask.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testCompleteSuspendedTask() {
// given
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
LockedExternalTask task = externalTasks.get(0);
// when suspending the process instance
runtimeService.suspendProcessInstanceById(processInstance.getId());
// then the external task cannot be completed
try {
externalTaskService.complete(task.getId(), WORKER_ID);
fail("expected exception");
} catch (ProcessEngineException e) {
assertTextPresent("ExternalTask with id '" + task.getId() + "' is suspended", e.getMessage());
}
assertProcessNotEnded(processInstance.getId());
// when activating the process instance again
runtimeService.activateProcessInstanceById(processInstance.getId());
// then the task can be completed
externalTaskService.complete(task.getId(), WORKER_ID);
assertProcessEnded(processInstance.getId());
}
use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testHandleBpmnErrorSuspendedTask.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testHandleBpmnErrorSuspendedTask() {
// given
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
LockedExternalTask task = externalTasks.get(0);
// when suspending the process instance
runtimeService.suspendProcessInstanceById(processInstance.getId());
// then the external task cannot be completed
try {
externalTaskService.handleBpmnError(task.getId(), WORKER_ID, "ERROR-OCCURED");
fail("expected exception");
} catch (ProcessEngineException e) {
assertTextPresent("ExternalTask with id '" + task.getId() + "' is suspended", e.getMessage());
}
}
use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testCompleteWithNonLocalVariables.
public void testCompleteWithNonLocalVariables() {
// given
BpmnModelInstance instance = Bpmn.createExecutableProcess("Process").startEvent().serviceTask("externalTask").camundaType("external").camundaTopic("foo").camundaTaskPriority("100").camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, ReadLocalVariableListenerImpl.class).userTask("user").endEvent().done();
deployment(instance);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process");
List<LockedExternalTask> lockedTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic("foo", 1L).execute();
// when
externalTaskService.complete(lockedTasks.get(0).getId(), WORKER_ID, Variables.createVariables().putValue("abc", "bar"), null);
// then
VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().processInstanceIdIn(processInstance.getId()).singleResult();
assertNotNull(variableInstance);
assertEquals("bar", variableInstance.getValue());
assertEquals("abc", variableInstance.getName());
}
use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testCompleteLockExpiredTask.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testCompleteLockExpiredTask() {
// given
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
// when
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
// and the lock expires without the task being reclaimed
ClockUtil.setCurrentTime(new DateTime(ClockUtil.getCurrentTime()).plus(LOCK_TIME * 2).toDate());
// then the task can successfully be completed
externalTaskService.complete(externalTasks.get(0).getId(), WORKER_ID);
externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
assertEquals(0, externalTasks.size());
assertProcessEnded(processInstance.getId());
}
use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testFetchWithPriorityExpression.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/externalTaskPriorityExpression.bpmn20.xml")
public void testFetchWithPriorityExpression() {
// given
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoExternalTaskWithPriorityProcess", Variables.createVariables().putValue("priority", 18));
// when
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID, true).topic(TOPIC_NAME, LOCK_TIME).execute();
// then
assertEquals(1, externalTasks.size());
LockedExternalTask task = externalTasks.get(0);
assertNotNull(task.getId());
assertEquals(processInstance.getId(), task.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), task.getProcessDefinitionId());
assertEquals("externalTaskWithPrio", task.getActivityId());
assertEquals("twoExternalTaskWithPriorityProcess", task.getProcessDefinitionKey());
assertEquals(TOPIC_NAME, task.getTopicName());
assertEquals(18, task.getPriority());
ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstance.getId()).getActivityInstances("externalTaskWithPrio")[0];
assertEquals(activityInstance.getId(), task.getActivityInstanceId());
assertEquals(activityInstance.getExecutionIds()[0], task.getExecutionId());
AssertUtil.assertEqualsSecondPrecision(nowPlus(LOCK_TIME), task.getLockExpirationTime());
assertEquals(WORKER_ID, task.getWorkerId());
}
Aggregations