Search in sources :

Example 61 with ProcessInstance

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());
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 62 with ProcessInstance

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());
    }
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 63 with ProcessInstance

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());
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance)

Example 64 with ProcessInstance

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());
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) DateTime(org.joda.time.DateTime) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 65 with ProcessInstance

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());
}
Also used : ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)2392 Deployment (org.camunda.bpm.engine.test.Deployment)1325 Test (org.junit.Test)1168 Task (org.camunda.bpm.engine.task.Task)660 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)415 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)372 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)272 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)258 HashMap (java.util.HashMap)235 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)230 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)203 Job (org.camunda.bpm.engine.runtime.Job)189 ScenarioUnderTest (org.camunda.bpm.qa.upgrade.ScenarioUnderTest)184 ExecutionTree (org.camunda.bpm.engine.test.util.ExecutionTree)149 Execution (org.camunda.bpm.engine.runtime.Execution)144 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)130 ExecutionAssert.describeExecutionTree (org.camunda.bpm.engine.test.util.ExecutionAssert.describeExecutionTree)129 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)122 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)86 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)84