Search in sources :

Example 16 with ActivityInstance

use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.

the class ProcessInstanceModificationTest method testStartActivityAndCancelCompensatingTask.

@Deployment(resources = TRANSACTION_WITH_COMPENSATION_PROCESS)
public void testStartActivityAndCancelCompensatingTask() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
    completeTasksInOrder("userTask");
    ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
    runtimeService.createProcessInstanceModification(processInstance.getId()).startBeforeActivity("userTask").cancelActivityInstance(getInstanceIdForActivity(tree, "undoTask")).execute();
    tree = runtimeService.getActivityInstance(processInstance.getId());
    assertThat(tree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).beginScope("tx").activity("userTask").done());
    completeTasksInOrder("userTask", "undoTask", "afterCancel");
    assertProcessEnded(processInstance.getId());
}
Also used : ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 17 with ActivityInstance

use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.

the class ProcessInstanceModificationTest method testCancellationWithWrongProcessInstanceId.

@Deployment(resources = PARALLEL_GATEWAY_PROCESS)
public void testCancellationWithWrongProcessInstanceId() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("parallelGateway");
    ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
    try {
        runtimeService.createProcessInstanceModification("foo").cancelActivityInstance(getInstanceIdForActivity(tree, "task1")).cancelActivityInstance(getInstanceIdForActivity(tree, "task2")).execute();
        assertProcessEnded(processInstance.getId());
    } catch (ProcessEngineException e) {
        assertThat(e.getMessage(), startsWith("ENGINE-13036"));
        assertThat(e.getMessage(), containsString("Process instance '" + "foo" + "' cannot be modified"));
    }
}
Also used : ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 18 with ActivityInstance

use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.

the class ProcessInstanceModificationTest method testStartAdditionalCompensatingTaskAndCompleteOldCompensationTask.

@Deployment(resources = TRANSACTION_WITH_COMPENSATION_PROCESS)
public void testStartAdditionalCompensatingTaskAndCompleteOldCompensationTask() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
    completeTasksInOrder("userTask");
    Task firstUndoTask = taskService.createTaskQuery().singleResult();
    runtimeService.createProcessInstanceModification(processInstance.getId()).startBeforeActivity("undoTask").execute();
    ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
    assertThat(tree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).beginScope("tx").activity("txEnd").activity("undoTask").activity("undoTask").done());
    taskService.complete(firstUndoTask.getId());
    Task secondUndoTask = taskService.createTaskQuery().taskDefinitionKey("undoTask").singleResult();
    assertNull(secondUndoTask);
    completeTasksInOrder("afterCancel");
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.camunda.bpm.engine.task.Task) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 19 with ActivityInstance

use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.

the class ProcessInstanceModificationTest method testStartActivityInTransactionWithCompensation.

@Deployment(resources = TRANSACTION_WITH_COMPENSATION_PROCESS)
public void testStartActivityInTransactionWithCompensation() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
    completeTasksInOrder("userTask");
    Task task = taskService.createTaskQuery().singleResult();
    assertEquals("undoTask", task.getTaskDefinitionKey());
    ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
    assertThat(tree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).beginScope("tx").activity("txEnd").activity("undoTask").done());
    runtimeService.createProcessInstanceModification(processInstance.getId()).startBeforeActivity("userTask").execute();
    tree = runtimeService.getActivityInstance(processInstance.getId());
    assertThat(tree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).beginScope("tx").activity("txEnd").activity("undoTask").activity("userTask").done());
    completeTasksInOrder("userTask");
    tree = runtimeService.getActivityInstance(processInstance.getId());
    assertThat(tree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).beginScope("tx").activity("txEnd").activity("undoTask").done());
    Task newTask = taskService.createTaskQuery().singleResult();
    assertNotSame(task.getId(), newTask.getId());
    completeTasksInOrder("undoTask", "afterCancel");
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.camunda.bpm.engine.task.Task) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 20 with ActivityInstance

use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.

the class ProcessInstanceModificationTest method testNoCompensationCreatedOnCancellation.

@Deployment
public void testNoCompensationCreatedOnCancellation() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("compensationProcess");
    ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
    // one on outerTask, one on innerTask
    assertEquals(2, taskService.createTaskQuery().count());
    // when inner task is cancelled
    runtimeService.createProcessInstanceModification(processInstance.getId()).cancelActivityInstance(getInstanceIdForActivity(tree, "innerTask")).execute();
    // then no compensation event subscription exists
    assertEquals(0, runtimeService.createEventSubscriptionQuery().count());
    // and the compensation throw event does not trigger compensation handlers
    Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    assertEquals("outerTask", task.getTaskDefinitionKey());
    taskService.complete(task.getId());
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.camunda.bpm.engine.task.Task) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)427 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)372 Deployment (org.camunda.bpm.engine.test.Deployment)277 Test (org.junit.Test)159 ExecutionTree (org.camunda.bpm.engine.test.util.ExecutionTree)130 ExecutionAssert.describeExecutionTree (org.camunda.bpm.engine.test.util.ExecutionAssert.describeExecutionTree)129 Task (org.camunda.bpm.engine.task.Task)108 ScenarioUnderTest (org.camunda.bpm.qa.upgrade.ScenarioUnderTest)80 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)56 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)54 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)47 TransitionInstance (org.camunda.bpm.engine.runtime.TransitionInstance)31 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)22 Job (org.camunda.bpm.engine.runtime.Job)21 Batch (org.camunda.bpm.engine.batch.Batch)15 DeploymentWithDefinitions (org.camunda.bpm.engine.repository.DeploymentWithDefinitions)12 Execution (org.camunda.bpm.engine.runtime.Execution)12 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)10 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)10 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)9