Search in sources :

Example 31 with BpmnModelInstance

use of org.camunda.bpm.model.bpmn.BpmnModelInstance in project camunda-bpm-platform by camunda.

the class RestartProcessInstanceSyncTest method shouldRestartProcessInstanceWithInitialVariables.

@Test
public void shouldRestartProcessInstanceWithInitialVariables() {
    // given
    BpmnModelInstance instance = Bpmn.createExecutableProcess("Process").startEvent("startEvent").userTask("userTask1").camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, SetVariableExecutionListenerImpl.class.getName()).userTask("userTask2").endEvent().done();
    ProcessDefinition processDefinition = testRule.deployAndGetDefinition(instance);
    // initial variable
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process", Variables.createVariables().putValue("var", "bar"));
    // variable update
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).active().singleResult();
    taskService.complete(task.getId());
    // delete process instance
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
    // when
    runtimeService.restartProcessInstances(processDefinition.getId()).startBeforeActivity("userTask1").initialSetOfVariables().processInstanceIds(processInstance.getId()).execute();
    // then
    ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().active().singleResult();
    VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().processInstanceIdIn(restartedProcessInstance.getId()).singleResult();
    assertEquals(variableInstance.getExecutionId(), restartedProcessInstance.getId());
    assertEquals("var", variableInstance.getName());
    assertEquals("bar", variableInstance.getValue());
}
Also used : Task(org.camunda.bpm.engine.task.Task) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test)

Example 32 with BpmnModelInstance

use of org.camunda.bpm.model.bpmn.BpmnModelInstance in project camunda-bpm-platform by camunda.

the class RuntimeServiceAsyncOperationsTest method testDeleteProcessInstancesAsyncWithSkipCustomListeners.

@Test
public void testDeleteProcessInstancesAsyncWithSkipCustomListeners() {
    // given
    IncrementCounterListener.counter = 0;
    BpmnModelInstance instance = ProcessModels.newModel(ONE_TASK_PROCESS).startEvent().userTask().camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, IncrementCounterListener.class.getName()).endEvent().done();
    testRule.deploy(instance);
    List<String> processIds = startTestProcesses(1);
    // when
    Batch batch = runtimeService.deleteProcessInstancesAsync(processIds, null, TESTING_INSTANCE_DELETE, true);
    executeSeedJob(batch);
    executeBatchJobs(batch);
    // then
    assertThat(IncrementCounterListener.counter, is(0));
}
Also used : HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) IncrementCounterListener(org.camunda.bpm.engine.test.api.runtime.util.IncrementCounterListener) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) AbstractAsyncOperationsTest(org.camunda.bpm.engine.test.api.AbstractAsyncOperationsTest) Test(org.junit.Test)

Example 33 with BpmnModelInstance

use of org.camunda.bpm.model.bpmn.BpmnModelInstance 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)

Example 34 with BpmnModelInstance

use of org.camunda.bpm.model.bpmn.BpmnModelInstance in project camunda-bpm-platform by camunda.

the class MigrationBoundaryEventsParameterizedTest method testMigrateBoundaryEventOnConcurrentUserTaskAndTriggerEvent.

@Test
public void testMigrateBoundaryEventOnConcurrentUserTaskAndTriggerEvent() {
    // given
    BpmnModelInstance sourceProcess = ProcessModels.PARALLEL_GATEWAY_PROCESS.clone();
    MigratingBpmnEventTrigger eventTrigger = eventFactory.addBoundaryEvent(rule.getProcessEngine(), sourceProcess, USER_TASK_1_ID, BOUNDARY_ID);
    ModifiableBpmnModelInstance.wrap(sourceProcess).flowNodeBuilder(BOUNDARY_ID).userTask(AFTER_BOUNDARY_TASK).endEvent().done();
    BpmnModelInstance targetProcess = modify(sourceProcess).changeElementId("boundary", "newBoundary");
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(sourceProcess);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(targetProcess);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities(USER_TASK_1_ID, USER_TASK_1_ID).mapActivities(USER_TASK_2_ID, USER_TASK_2_ID).mapActivities(BOUNDARY_ID, NEW_BOUNDARY_ID).updateEventTrigger().build();
    // when
    ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan);
    // then it is possible to trigger the event and successfully complete the migrated instance
    eventTrigger.inContextOf(NEW_BOUNDARY_ID).trigger(processInstance.getId());
    testHelper.completeTask(AFTER_BOUNDARY_TASK);
    testHelper.completeTask(USER_TASK_2_ID);
    testHelper.assertProcessEnded(testHelper.snapshotBeforeMigration.getProcessInstanceId());
}
Also used : MigratingBpmnEventTrigger(org.camunda.bpm.engine.test.api.runtime.migration.util.MigratingBpmnEventTrigger) 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)

Example 35 with BpmnModelInstance

use of org.camunda.bpm.model.bpmn.BpmnModelInstance in project camunda-bpm-platform by camunda.

the class MigrationBoundaryEventsParameterizedTest method testMigrateBoundaryEventOnConcurrentUserTask.

@Test
public void testMigrateBoundaryEventOnConcurrentUserTask() {
    // given
    BpmnModelInstance sourceProcess = ProcessModels.PARALLEL_GATEWAY_PROCESS.clone();
    MigratingBpmnEventTrigger eventTrigger = eventFactory.addBoundaryEvent(rule.getProcessEngine(), sourceProcess, USER_TASK_1_ID, BOUNDARY_ID);
    ModifiableBpmnModelInstance.wrap(sourceProcess).flowNodeBuilder(BOUNDARY_ID).userTask(AFTER_BOUNDARY_TASK).endEvent().done();
    BpmnModelInstance targetProcess = modify(sourceProcess).changeElementId("boundary", "newBoundary");
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(sourceProcess);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(targetProcess);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities(USER_TASK_1_ID, USER_TASK_1_ID).mapActivities(USER_TASK_2_ID, USER_TASK_2_ID).mapActivities(BOUNDARY_ID, NEW_BOUNDARY_ID).updateEventTrigger().build();
    // when
    testHelper.createProcessInstanceAndMigrate(migrationPlan);
    // then
    eventTrigger.assertEventTriggerMigrated(testHelper, NEW_BOUNDARY_ID);
    // and it is possible to successfully complete the migrated instance
    testHelper.completeTask(USER_TASK_1_ID);
    testHelper.completeTask(USER_TASK_2_ID);
    testHelper.assertProcessEnded(testHelper.snapshotBeforeMigration.getProcessInstanceId());
}
Also used : MigratingBpmnEventTrigger(org.camunda.bpm.engine.test.api.runtime.migration.util.MigratingBpmnEventTrigger) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Aggregations

BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)587 Test (org.junit.Test)408 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)258 Task (org.camunda.bpm.engine.task.Task)139 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)124 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)119 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)67 ProcessApplicationDeployment (org.camunda.bpm.engine.repository.ProcessApplicationDeployment)47 Deployment (org.camunda.bpm.engine.repository.Deployment)39 ProcessDefinitionQuery (org.camunda.bpm.engine.repository.ProcessDefinitionQuery)27 Job (org.camunda.bpm.engine.runtime.Job)24 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)22 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)21 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)16 Date (java.util.Date)15 HashMap (java.util.HashMap)15 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)14 Execution (org.camunda.bpm.engine.runtime.Execution)14 MigratingBpmnEventTrigger (org.camunda.bpm.engine.test.api.runtime.migration.util.MigratingBpmnEventTrigger)14 SequenceFlow (org.camunda.bpm.model.bpmn.instance.SequenceFlow)14