Search in sources :

Example 46 with ActivityInstance

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

the class RestartProcessInstanceAsyncTest method shouldRestartProcessInstanceWithParallelGateway.

@Test
public void shouldRestartProcessInstanceWithParallelGateway() {
    // given
    ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.PARALLEL_GATEWAY_PROCESS);
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("Process");
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("Process");
    runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
    // when
    Batch batch = runtimeService.restartProcessInstances(processDefinition.getId()).startBeforeActivity("userTask1").startBeforeActivity("userTask2").processInstanceIds(processInstance1.getId(), processInstance2.getId()).executeAsync();
    helper.completeBatch(batch);
    // then
    List<ProcessInstance> restartedProcessInstances = runtimeService.createProcessInstanceQuery().active().list();
    for (ProcessInstance restartedProcessInstance : restartedProcessInstances) {
        ActivityInstance updatedTree = runtimeService.getActivityInstance(restartedProcessInstance.getId());
        assertNotNull(updatedTree);
        assertEquals(restartedProcessInstance.getId(), updatedTree.getProcessInstanceId());
        assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processDefinition.getId()).activity("userTask1").activity("userTask2").done());
    }
}
Also used : ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) Batch(org.camunda.bpm.engine.batch.Batch) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test)

Example 47 with ActivityInstance

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

the class ProcessInstantiationAtActivitiesHistoryTest method testHistoricProcessInstanceAsyncStartEvent.

@Deployment(resources = ASYNC_PROCESS)
public void testHistoricProcessInstanceAsyncStartEvent() {
    // when
    ProcessInstance instance = runtimeService.createProcessInstanceByKey("exclusiveGateway").startBeforeActivity("task2").setVariable("aVar", "aValue").execute();
    // then
    HistoricProcessInstance historicInstance = historyService.createHistoricProcessInstanceQuery().singleResult();
    assertNotNull(historicInstance);
    assertEquals(instance.getId(), historicInstance.getId());
    assertNotNull(historicInstance.getStartTime());
    assertNull(historicInstance.getEndTime());
    // should be the first activity started
    assertEquals("task2", historicInstance.getStartActivityId());
    // task2 wasn't entered yet
    assertEquals(0, historyService.createHistoricActivityInstanceQuery().count());
    // history events for variables exist already
    ActivityInstance activityInstance = runtimeService.getActivityInstance(instance.getId());
    HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().variableName("aVar").singleResult();
    assertNotNull(historicVariable);
    assertEquals(instance.getId(), historicVariable.getProcessInstanceId());
    assertEquals(activityInstance.getId(), historicVariable.getActivityInstanceId());
    assertEquals("aVar", historicVariable.getName());
    assertEquals("aValue", historicVariable.getValue());
    HistoricDetail historicDetail = historyService.createHistoricDetailQuery().variableInstanceId(historicVariable.getId()).singleResult();
    assertEquals(instance.getId(), historicDetail.getProcessInstanceId());
    assertNotNull(historicDetail);
    // TODO: fix if this is not ok due to CAM-3886
    assertNull(historicDetail.getActivityInstanceId());
    assertTrue(historicDetail instanceof HistoricVariableUpdate);
    assertEquals("aVar", ((HistoricVariableUpdate) historicDetail).getVariableName());
    assertEquals("aValue", ((HistoricVariableUpdate) historicDetail).getValue());
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 48 with ActivityInstance

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

the class RestartProcessInstanceSyncTest method shouldRestartProcessInstanceWithSubProcess.

@Test
public void shouldRestartProcessInstanceWithSubProcess() {
    // given
    ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.SUBPROCESS_PROCESS);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process");
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
    // when
    runtimeService.restartProcessInstances(processDefinition.getId()).startBeforeActivity("subProcess").processInstanceIds(processInstance.getId()).execute();
    // then
    ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().active().singleResult();
    ActivityInstance updatedTree = runtimeService.getActivityInstance(restartedProcessInstance.getId());
    assertNotNull(updatedTree);
    assertEquals(restartedProcessInstance.getId(), updatedTree.getProcessInstanceId());
    assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processDefinition.getId()).beginScope("subProcess").activity("userTask").done());
}
Also used : ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test)

Example 49 with ActivityInstance

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

the class RestartProcessInstanceSyncTest method shouldRestartProcessInstanceUsingHistoricProcessInstanceQuery.

@Test
public void shouldRestartProcessInstanceUsingHistoricProcessInstanceQuery() {
    // given
    ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process");
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
    // when
    HistoricProcessInstanceQuery historicProcessInstanceQuery = engineRule.getHistoryService().createHistoricProcessInstanceQuery().processDefinitionId(processDefinition.getId());
    runtimeService.restartProcessInstances(processDefinition.getId()).startBeforeActivity("userTask1").historicProcessInstanceQuery(historicProcessInstanceQuery).execute();
    // then
    ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().active().singleResult();
    ActivityInstance updatedTree = runtimeService.getActivityInstance(restartedProcessInstance.getId());
    assertNotNull(updatedTree);
    assertEquals(restartedProcessInstance.getId(), updatedTree.getProcessInstanceId());
    assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processDefinition.getId()).activity("userTask1").done());
}
Also used : HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test)

Example 50 with ActivityInstance

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

the class MigrationCompensationRemoveSubProcessTest method testCanOnlyTriggerCompensationInParentOfRemovedScope.

@Test
public void testCanOnlyTriggerCompensationInParentOfRemovedScope() {
    BpmnModelInstance sourceModel = ProcessModels.newModel().startEvent().subProcess("outerSubProcess").embeddedSubProcess().startEvent().userTask("userTask1").boundaryEvent("compensationBoundary").compensateEventDefinition().compensateEventDefinitionDone().moveToActivity("userTask1").subProcess("innerSubProcess").embeddedSubProcess().startEvent().userTask("userTask2").endEvent().subProcessDone().endEvent().subProcessDone().done();
    CompensationModels.addUserTaskCompensationHandler(sourceModel, "compensationBoundary", "compensationHandler");
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(sourceModel);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(CompensationModels.COMPENSATION_TWO_TASKS_SUBPROCESS_MODEL).endEventBuilder("subProcessEnd").compensateEventDefinition().waitForCompletion(true).compensateEventDefinitionDone().done());
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("innerSubProcess", "subProcess").mapActivities("userTask2", "userTask2").mapActivities("compensationBoundary", "compensationBoundary").build();
    ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
    testHelper.completeTask("userTask1");
    testHelper.migrateProcessInstance(migrationPlan, processInstance);
    // when
    testHelper.completeTask("userTask2");
    // then compensation is not triggered from inside the inner sub process
    // but only on process definition level
    ActivityInstance activityInstance = rule.getRuntimeService().getActivityInstance(processInstance.getId());
    assertThat(activityInstance).hasStructure(describeActivityInstanceTree(targetProcessDefinition.getId()).activity("compensationEvent").beginScope("subProcess").activity("compensationHandler").done());
}
Also used : ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

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