use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testFetchNonExistingVariable.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testFetchNonExistingVariable() {
// given
runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
// when
List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).variables("nonExistingVariable").execute();
LockedExternalTask task = tasks.get(0);
// then
assertTrue(task.getVariables().isEmpty());
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testFetchSerializedVariables.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/ExternalTaskServiceTest.testFetchVariables.bpmn20.xml")
public void testFetchSerializedVariables() {
// given
ExternalTaskCustomValue customValue = new ExternalTaskCustomValue();
customValue.setTestValue("value1");
runtimeService.startProcessInstanceByKey("subProcessExternalTask", Variables.createVariables().putValue("processVar1", customValue));
// when
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).variables("processVar1").enableCustomObjectDeserialization().execute();
// then
LockedExternalTask task = externalTasks.get(0);
VariableMap variables = task.getVariables();
assertEquals(1, variables.size());
final ExternalTaskCustomValue receivedCustomValue = (ExternalTaskCustomValue) variables.get("processVar1");
assertNotNull(receivedCustomValue);
assertNotNull(receivedCustomValue.getTestValue());
assertEquals("value1", receivedCustomValue.getTestValue());
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testHandleFailureThenComplete.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/twoExternalTaskProcess.bpmn20.xml")
public void testHandleFailureThenComplete() {
// given a failed external task with incident
runtimeService.startProcessInstanceByKey("twoExternalTaskProcess");
List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
LockedExternalTask task = tasks.get(0);
externalTaskService.handleFailure(task.getId(), WORKER_ID, "someError", 0, LOCK_TIME);
// when
externalTaskService.complete(task.getId(), WORKER_ID);
// then the task has been completed nonetheless
Task followingTask = taskService.createTaskQuery().singleResult();
assertNotNull(followingTask);
assertEquals("afterExternalTask", followingTask.getTaskDefinitionKey());
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask 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.externaltask.LockedExternalTask 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