Search in sources :

Example 51 with RequiredHistoryLevel

use of org.camunda.bpm.engine.test.RequiredHistoryLevel in project camunda-bpm-platform by camunda.

the class MigrationHistoricActivityInstanceTest method testMigrateHistoricActivityInstanceAddScope.

@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testMigrateHistoricActivityInstanceAddScope() {
    // given
    ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.SUBPROCESS_PROCESS);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()).mapActivities("userTask", "userTask").build();
    ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceDefinition.getId());
    // when
    rule.getRuntimeService().newMigration(migrationPlan).processInstanceIds(Arrays.asList(processInstance.getId())).execute();
    // then
    List<HistoricActivityInstance> historicInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).unfinished().orderByActivityId().asc().list();
    Assert.assertEquals(2, historicInstances.size());
    assertMigratedTo(historicInstances.get(0), targetDefinition, "subProcess");
    assertMigratedTo(historicInstances.get(1), targetDefinition, "userTask");
    assertEquals(processInstance.getId(), historicInstances.get(0).getParentActivityInstanceId());
    assertEquals(historicInstances.get(0).getId(), historicInstances.get(1).getParentActivityInstanceId());
}
Also used : MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance) Test(org.junit.Test) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Example 52 with RequiredHistoryLevel

use of org.camunda.bpm.engine.test.RequiredHistoryLevel in project camunda-bpm-platform by camunda.

the class MigrationHistoricVariablesTest method noHistoryUpdateOnAddScopeMigration.

@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL)
public void noHistoryUpdateOnAddScopeMigration() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(CONCURRENT_BOUNDARY_TASKS);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(SUBPROCESS_CONCURRENT_BOUNDARY_TASKS);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask1", "userTask1").mapActivities("userTask2", "userTask2").build();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());
    ExecutionTree executionTreeBeforeMigration = ExecutionTree.forExecution(processInstance.getId(), rule.getProcessEngine());
    ExecutionTree userTask1CCExecutionBefore = executionTreeBeforeMigration.getLeafExecutions("userTask1").get(0).getParent();
    runtimeService.setVariableLocal(userTask1CCExecutionBefore.getId(), "foo", 42);
    // when
    testHelper.migrateProcessInstance(migrationPlan, processInstance);
    // then there is still one historic variable instance
    Assert.assertEquals(1, historyService.createHistoricVariableInstanceQuery().count());
    // and no additional historic details
    Assert.assertEquals(1, historyService.createHistoricDetailQuery().count());
}
Also used : ExecutionTree(org.camunda.bpm.engine.test.util.ExecutionTree) 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) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Example 53 with RequiredHistoryLevel

use of org.camunda.bpm.engine.test.RequiredHistoryLevel in project camunda-bpm-platform by camunda.

the class MigrationHistoricVariablesTest method testMigrateEventScopeVariable.

@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_AUDIT)
public void testMigrateEventScopeVariable() {
    // given
    ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(CompensationModels.COMPENSATION_ONE_TASK_SUBPROCESS_MODEL);
    ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(CompensationModels.COMPENSATION_ONE_TASK_SUBPROCESS_MODEL);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()).mapActivities("userTask2", "userTask2").mapActivities("subProcess", "subProcess").mapActivities("compensationBoundary", "compensationBoundary").build();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceDefinition.getId());
    Execution subProcessExecution = runtimeService.createExecutionQuery().activityId("userTask1").singleResult();
    runtimeService.setVariableLocal(subProcessExecution.getId(), "foo", "bar");
    testHelper.completeTask("userTask1");
    Execution eventScopeExecution = runtimeService.createExecutionQuery().activityId("subProcess").singleResult();
    HistoricVariableInstance eventScopeVariable = historyService.createHistoricVariableInstanceQuery().executionIdIn(eventScopeExecution.getId()).singleResult();
    // when
    runtimeService.newMigration(migrationPlan).processInstanceIds(processInstance.getId()).execute();
    // then
    HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().variableId(eventScopeVariable.getId()).singleResult();
    Assert.assertEquals(targetDefinition.getId(), historicVariableInstance.getProcessDefinitionId());
}
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) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) Test(org.junit.Test) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Example 54 with RequiredHistoryLevel

use of org.camunda.bpm.engine.test.RequiredHistoryLevel in project camunda-bpm-platform by camunda.

the class MigrationHistoricTaskInstanceTest method testMigrateHistoryUserTaskInstance.

@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testMigrateHistoryUserTaskInstance() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(ProcessModels.ONE_TASK_PROCESS).changeElementId("Process", "Process2").changeElementId("userTask", "userTask2"));
    MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask", "userTask2").build();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());
    HistoricTaskInstanceQuery sourceHistoryTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery().processDefinitionId(sourceProcessDefinition.getId());
    HistoricTaskInstanceQuery targetHistoryTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery().processDefinitionId(targetProcessDefinition.getId());
    ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstance.getId());
    // when
    assertEquals(1, sourceHistoryTaskInstanceQuery.count());
    assertEquals(0, targetHistoryTaskInstanceQuery.count());
    ProcessInstanceQuery sourceProcessInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionId(sourceProcessDefinition.getId());
    runtimeService.newMigration(migrationPlan).processInstanceQuery(sourceProcessInstanceQuery).execute();
    // then
    assertEquals(0, sourceHistoryTaskInstanceQuery.count());
    assertEquals(1, targetHistoryTaskInstanceQuery.count());
    HistoricTaskInstance instance = targetHistoryTaskInstanceQuery.singleResult();
    assertEquals(targetProcessDefinition.getKey(), instance.getProcessDefinitionKey());
    assertEquals(targetProcessDefinition.getId(), instance.getProcessDefinitionId());
    assertEquals("userTask2", instance.getTaskDefinitionKey());
    assertEquals(activityInstance.getActivityInstances("userTask")[0].getId(), instance.getActivityInstanceId());
}
Also used : ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) HistoricTaskInstance(org.camunda.bpm.engine.history.HistoricTaskInstance) 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) HistoricTaskInstanceQuery(org.camunda.bpm.engine.history.HistoricTaskInstanceQuery) Test(org.junit.Test) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Example 55 with RequiredHistoryLevel

use of org.camunda.bpm.engine.test.RequiredHistoryLevel in project camunda-bpm-platform by camunda.

the class HistoricTaskInstanceQueryTest method testGroupTaskQuery.

@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL)
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testGroupTaskQuery() {
    // given
    runtimeService.startProcessInstanceByKey("oneTaskProcess");
    String taskId = taskService.createTaskQuery().singleResult().getId();
    // if
    identityService.setAuthenticatedUserId("aAssignerId");
    taskService.addCandidateUser(taskId, "aUserId");
    taskService.addCandidateGroup(taskId, "aGroupId");
    taskService.addCandidateGroup(taskId, "bGroupId");
    Task taskOne = taskService.newTask("taskOne");
    taskOne.setAssignee("aUserId");
    taskService.saveTask(taskOne);
    Task taskTwo = taskService.newTask("taskTwo");
    taskTwo.setAssignee("aUserId");
    taskService.saveTask(taskTwo);
    Task taskThree = taskService.newTask("taskThree");
    taskThree.setOwner("aUserId");
    taskService.saveTask(taskThree);
    taskService.deleteCandidateGroup(taskId, "aGroupId");
    taskService.deleteCandidateGroup(taskId, "bGroupId");
    historyService.createHistoricTaskInstanceQuery();
    // Query test
    HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery();
    assertEquals(4, query.taskInvolvedUser("aUserId").count());
    query = historyService.createHistoricTaskInstanceQuery();
    assertEquals(1, query.taskHadCandidateUser("aUserId").count());
    query = historyService.createHistoricTaskInstanceQuery();
    assertEquals(1, query.taskHadCandidateGroup("aGroupId").count());
    assertEquals(1, query.taskHadCandidateGroup("bGroupId").count());
    assertEquals(0, query.taskInvolvedUser("aUserId").count());
    query = historyService.createHistoricTaskInstanceQuery();
    assertEquals(4, query.taskInvolvedUser("aUserId").count());
    assertEquals(1, query.taskHadCandidateUser("aUserId").count());
    assertEquals(1, query.taskInvolvedUser("aUserId").count());
    // delete task
    taskService.deleteTask("taskOne", true);
    taskService.deleteTask("taskTwo", true);
    taskService.deleteTask("taskThree", true);
}
Also used : Task(org.camunda.bpm.engine.task.Task) HistoricTaskInstanceQuery(org.camunda.bpm.engine.history.HistoricTaskInstanceQuery) Deployment(org.camunda.bpm.engine.test.Deployment) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Aggregations

RequiredHistoryLevel (org.camunda.bpm.engine.test.RequiredHistoryLevel)76 Test (org.junit.Test)47 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)43 Deployment (org.camunda.bpm.engine.test.Deployment)24 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)17 Batch (org.camunda.bpm.engine.batch.Batch)13 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)13 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)12 Task (org.camunda.bpm.engine.task.Task)12 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)12 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)11 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)10 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 Calendar (java.util.Calendar)6 HistoricTaskInstance (org.camunda.bpm.engine.history.HistoricTaskInstance)6 Job (org.camunda.bpm.engine.runtime.Job)6 VariableInstanceQuery (org.camunda.bpm.engine.runtime.VariableInstanceQuery)6 ProcessInstanceQuery (org.camunda.bpm.engine.runtime.ProcessInstanceQuery)5 GregorianCalendar (java.util.GregorianCalendar)4