use of org.camunda.bpm.engine.history.HistoricActivityInstance in project camunda-bpm-platform by camunda.
the class MigrationHistoricActivityInstanceTest method testHistoricActivityInstanceBecomeScope.
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testHistoricActivityInstanceBecomeScope() {
// given
ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.SCOPE_TASK_PROCESS);
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()).mapEqualActivities().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(1, historicInstances.size());
assertMigratedTo(historicInstances.get(0), targetDefinition, "userTask");
assertEquals(processInstance.getId(), historicInstances.get(0).getParentActivityInstanceId());
}
use of org.camunda.bpm.engine.history.HistoricActivityInstance in project camunda-bpm-platform by camunda.
the class MigrationHistoricActivityInstanceTest method testMigrateHistoricSubProcessInstance.
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testMigrateHistoricSubProcessInstance() {
// given
ProcessDefinition processDefinition = testHelper.deployAndGetDefinition(ProcessModels.SCOPE_TASK_SUBPROCESS_PROCESS);
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(processDefinition.getId(), processDefinition.getId()).mapEqualActivities().build();
ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(processDefinition.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), processDefinition, "subProcess");
assertMigratedTo(historicInstances.get(1), processDefinition, "userTask");
assertEquals(processInstance.getId(), historicInstances.get(0).getParentActivityInstanceId());
assertEquals(historicInstances.get(0).getId(), historicInstances.get(1).getParentActivityInstanceId());
}
use of org.camunda.bpm.engine.history.HistoricActivityInstance in project camunda-bpm-platform by camunda.
the class MigrationHistoricActivityInstanceTest method testMigrateHistoryActivityInstance.
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testMigrateHistoryActivityInstance() {
// given
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(ProcessModels.ONE_TASK_PROCESS).changeElementId("Process", "Process2").changeElementId("userTask", "userTask2").changeElementName("userTask", "new activity name"));
MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask", "userTask2").build();
ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());
HistoricActivityInstanceQuery sourceHistoryActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery().processDefinitionId(sourceProcessDefinition.getId());
HistoricActivityInstanceQuery targetHistoryActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery().processDefinitionId(targetProcessDefinition.getId());
// when
assertEquals(2, sourceHistoryActivityInstanceQuery.count());
assertEquals(0, targetHistoryActivityInstanceQuery.count());
ProcessInstanceQuery sourceProcessInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionId(sourceProcessDefinition.getId());
runtimeService.newMigration(migrationPlan).processInstanceQuery(sourceProcessInstanceQuery).execute();
// then one instance of the start event still belongs to the source process
// and one active user task instances is now migrated to the target process
assertEquals(1, sourceHistoryActivityInstanceQuery.count());
assertEquals(1, targetHistoryActivityInstanceQuery.count());
HistoricActivityInstance instance = targetHistoryActivityInstanceQuery.singleResult();
assertMigratedTo(instance, targetProcessDefinition, "userTask2");
assertEquals("new activity name", instance.getActivityName());
assertEquals(processInstance.getId(), instance.getParentActivityInstanceId());
assertEquals("userTask", instance.getActivityType());
}
use of org.camunda.bpm.engine.history.HistoricActivityInstance in project camunda-bpm-platform by camunda.
the class NestedCompensationScenarioTest method testHistory.
@Test
@ScenarioUnderTest("init.throwCompensate.1")
public void testHistory() {
// given
Task compensationHandler = rule.taskQuery().singleResult();
// when
rule.getTaskService().complete(compensationHandler.getId());
// then history is written for the remaining activity instances
HistoricProcessInstance historicProcessInstance = rule.historicProcessInstance();
Assert.assertNotNull(historicProcessInstance);
Assert.assertNotNull(historicProcessInstance.getEndTime());
HistoricActivityInstance subProcessInstance = rule.getHistoryService().createHistoricActivityInstanceQuery().processInstanceId(historicProcessInstance.getId()).activityId("subProcess").singleResult();
Assert.assertNotNull(subProcessInstance);
Assert.assertNotNull(subProcessInstance.getEndTime());
Assert.assertEquals(historicProcessInstance.getId(), subProcessInstance.getParentActivityInstanceId());
HistoricActivityInstance compensationThrowInstance = rule.getHistoryService().createHistoricActivityInstanceQuery().processInstanceId(historicProcessInstance.getId()).activityId("throwCompensate").singleResult();
Assert.assertNotNull(compensationThrowInstance);
Assert.assertNotNull(compensationThrowInstance.getEndTime());
Assert.assertEquals(subProcessInstance.getId(), compensationThrowInstance.getParentActivityInstanceId());
HistoricActivityInstance compensationHandlerInstance = rule.getHistoryService().createHistoricActivityInstanceQuery().processInstanceId(historicProcessInstance.getId()).activityId("undoTask").singleResult();
Assert.assertNotNull(compensationHandlerInstance);
Assert.assertNotNull(compensationHandlerInstance.getEndTime());
Assert.assertEquals(subProcessInstance.getId(), compensationHandlerInstance.getParentActivityInstanceId());
}
use of org.camunda.bpm.engine.history.HistoricActivityInstance in project camunda-bpm-platform by camunda.
the class MultiInstanceTest method testParallelCallActivityHistory.
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/multiinstance/MultiInstanceTest.testParallelCallActivity.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/multiinstance/MultiInstanceTest.externalSubProcess.bpmn20.xml" })
public void testParallelCallActivityHistory() {
runtimeService.startProcessInstanceByKey("miParallelCallActivity");
List<Task> tasks = taskService.createTaskQuery().list();
assertEquals(12, tasks.size());
for (int i = 0; i < tasks.size(); i++) {
taskService.complete(tasks.get(i).getId());
}
if (processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
// Validate historic processes
List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().list();
// 6 subprocesses + main process
assertEquals(7, historicProcessInstances.size());
for (HistoricProcessInstance hpi : historicProcessInstances) {
assertNotNull(hpi.getStartTime());
assertNotNull(hpi.getEndTime());
}
// Validate historic activities
List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityType("callActivity").list();
assertEquals(6, historicActivityInstances.size());
for (HistoricActivityInstance hai : historicActivityInstances) {
assertNotNull(hai.getStartTime());
assertNotNull(hai.getEndTime());
}
}
if (processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_ACTIVITY) {
// Validate historic tasks
List<HistoricTaskInstance> historicTaskInstances = historyService.createHistoricTaskInstanceQuery().list();
assertEquals(12, historicTaskInstances.size());
for (HistoricTaskInstance hti : historicTaskInstances) {
assertNotNull(hti.getStartTime());
assertNotNull(hti.getEndTime());
assertNotNull(hti.getAssignee());
assertEquals("completed", hti.getDeleteReason());
}
}
}
Aggregations