Search in sources :

Example 96 with ProcessDefinition

use of org.camunda.bpm.engine.repository.ProcessDefinition in project camunda-bpm-platform by camunda.

the class RestartProcessInstanceSyncTest method shouldRetainTenantIdOfSharedProcessDefinition.

@Test
public void shouldRetainTenantIdOfSharedProcessDefinition() {
    // given
    engineRule.getProcessEngineConfiguration().setTenantIdProvider(new TestTenantIdProvider());
    ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
    assertEquals(processInstance.getTenantId(), TestTenantIdProvider.TENANT_ID);
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
    // when
    runtimeService.restartProcessInstances(processDefinition.getId()).startBeforeActivity(ProcessModels.USER_TASK_ID).processInstanceIds(processInstance.getId()).execute();
    // then
    ProcessInstance restartedInstance = runtimeService.createProcessInstanceQuery().active().processDefinitionId(processDefinition.getId()).singleResult();
    assertNotNull(restartedInstance);
    assertEquals(restartedInstance.getTenantId(), TestTenantIdProvider.TENANT_ID);
}
Also used : ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test)

Example 97 with ProcessDefinition

use of org.camunda.bpm.engine.repository.ProcessDefinition in project camunda-bpm-platform by camunda.

the class RuntimeServiceAsyncOperationsTest method testDeleteProcessInstancesAsyncWithListInDifferentDeployments.

@Test
public void testDeleteProcessInstancesAsyncWithListInDifferentDeployments() {
    // given
    ProcessDefinition sourceDefinition1 = testRule.deployAndGetDefinition(modify(ProcessModels.ONE_TASK_PROCESS).changeElementId(ProcessModels.PROCESS_KEY, "ONE_TASK_PROCESS"));
    ProcessDefinition sourceDefinition2 = testRule.deployAndGetDefinition(modify(ProcessModels.TWO_TASKS_PROCESS).changeElementId(ProcessModels.PROCESS_KEY, "TWO_TASKS_PROCESS"));
    List<String> processInstanceIds = createProcessInstances(sourceDefinition1, sourceDefinition2, 15, 10);
    final String firstDeploymentId = sourceDefinition1.getDeploymentId();
    final String secondDeploymentId = sourceDefinition2.getDeploymentId();
    List<String> processInstanceIdsFromFirstDeployment = getProcessInstanceIdsByDeploymentId(firstDeploymentId);
    List<String> processInstanceIdsFromSecondDeployment = getProcessInstanceIdsByDeploymentId(secondDeploymentId);
    engineRule.getProcessEngineConfiguration().setInvocationsPerBatchJob(2);
    engineRule.getProcessEngineConfiguration().setBatchJobsPerSeed(3);
    // when
    Batch batch = runtimeService.deleteProcessInstancesAsync(processInstanceIds, null, "test_reason");
    String seedJobDefinitionId = batch.getSeedJobDefinitionId();
    // seed jobs
    int expectedSeedJobsCount = 5;
    createAndExecuteSeedJobs(seedJobDefinitionId, expectedSeedJobsCount);
    // then
    List<Job> jobs = managementService.createJobQuery().jobDefinitionId(batch.getBatchJobDefinitionId()).list();
    // execute jobs related to the first deployment
    List<String> jobIdsForFirstDeployment = getJobIdsByDeployment(jobs, firstDeploymentId);
    assertNotNull(jobIdsForFirstDeployment);
    for (String jobId : jobIdsForFirstDeployment) {
        managementService.executeJob(jobId);
    }
    // the process instances related to the first deployment should be deleted
    assertEquals(0, runtimeService.createProcessInstanceQuery().deploymentId(firstDeploymentId).count());
    assertHistoricTaskDeletionPresent(processInstanceIdsFromFirstDeployment, "test_reason", testRule);
    // and process instances related to the second deployment should not be deleted
    assertEquals(processInstanceIdsFromSecondDeployment.size(), runtimeService.createProcessInstanceQuery().deploymentId(secondDeploymentId).count());
    assertHistoricTaskDeletionPresent(processInstanceIdsFromSecondDeployment, null, testRule);
    // execute jobs related to the second deployment
    List<String> jobIdsForSecondDeployment = getJobIdsByDeployment(jobs, secondDeploymentId);
    assertNotNull(jobIdsForSecondDeployment);
    for (String jobId : jobIdsForSecondDeployment) {
        managementService.executeJob(jobId);
    }
    // all of the process instances should be deleted
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
Also used : HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Job(org.camunda.bpm.engine.runtime.Job) AbstractAsyncOperationsTest(org.camunda.bpm.engine.test.api.AbstractAsyncOperationsTest) Test(org.junit.Test)

Example 98 with ProcessDefinition

use of org.camunda.bpm.engine.repository.ProcessDefinition in project camunda-bpm-platform by camunda.

the class MigrationCompensationRemoveSubProcessTest method testCase1AssertExecutionTree.

@Test
public void testCase1AssertExecutionTree() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(CompensationModels.COMPENSATION_TWO_TASKS_SUBPROCESS_MODEL);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(CompensationModels.ONE_COMPENSATION_TASK_MODEL);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask2", "userTask2").mapActivities("compensationBoundary", "compensationBoundary").build();
    ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
    testHelper.completeTask("userTask1");
    // when
    testHelper.migrateProcessInstance(migrationPlan, processInstance);
    // then
    testHelper.assertExecutionTreeAfterMigration().hasProcessDefinitionId(targetProcessDefinition.getId()).matches(describeExecutionTree("userTask2").scope().id(testHelper.snapshotBeforeMigration.getProcessInstanceId()).done());
}
Also used : MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test)

Example 99 with ProcessDefinition

use of org.camunda.bpm.engine.repository.ProcessDefinition 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 100 with ProcessDefinition

use of org.camunda.bpm.engine.repository.ProcessDefinition in project camunda-bpm-platform by camunda.

the class MigrationCompensationRemoveSubProcessTest method testCanRemoveEventScopeWithVariables.

@Test
public void testCanRemoveEventScopeWithVariables() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(CompensationModels.COMPENSATION_ONE_TASK_SUBPROCESS_MODEL);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(CompensationModels.ONE_COMPENSATION_TASK_MODEL);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask2", "userTask2").mapActivities("compensationBoundary", "compensationBoundary").build();
    ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
    Execution subProcessExecution = rule.getRuntimeService().createExecutionQuery().activityId("userTask1").singleResult();
    rule.getRuntimeService().setVariableLocal(subProcessExecution.getId(), "foo", "bar");
    testHelper.completeTask("userTask1");
    // when
    testHelper.migrateProcessInstance(migrationPlan, processInstance);
    // then
    Assert.assertEquals(0, rule.getRuntimeService().createVariableInstanceQuery().count());
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test)

Aggregations

ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)1093 Test (org.junit.Test)761 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)474 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)415 Deployment (org.camunda.bpm.engine.test.Deployment)230 Job (org.camunda.bpm.engine.runtime.Job)148 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)119 Batch (org.camunda.bpm.engine.batch.Batch)95 Task (org.camunda.bpm.engine.task.Task)87 HashMap (java.util.HashMap)77 JobDefinition (org.camunda.bpm.engine.management.JobDefinition)64 JobQuery (org.camunda.bpm.engine.runtime.JobQuery)55 JobDefinitionQuery (org.camunda.bpm.engine.management.JobDefinitionQuery)54 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)47 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)42 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)41 MigrationPlanValidationException (org.camunda.bpm.engine.migration.MigrationPlanValidationException)40 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)39 Date (java.util.Date)38 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)35