Java Code Examples for org.camunda.bpm.engine.ProcessEngineConfiguration#HISTORY_ACTIVITY

The following examples show how to use org.camunda.bpm.engine.ProcessEngineConfiguration#HISTORY_ACTIVITY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UpdateProcessInstancesSuspendStateAsyncTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {"org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml",
  "org/camunda/bpm/engine/test/api/externaltask/twoExternalTaskProcess.bpmn20.xml"})
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testBatchActivationByHistoricProcessInstanceQuery() {
  // given
  ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
  ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("twoExternalTaskProcess");

  // when
  Batch suspendprocess = runtimeService.updateProcessInstanceSuspensionState().byHistoricProcessInstanceQuery(historyService.createHistoricProcessInstanceQuery().processInstanceIds(Sets.newHashSet(processInstance1.getId(), processInstance2.getId()))).suspendAsync();
  helper.completeSeedJobs(suspendprocess);
  helper.executeJobs(suspendprocess);
  Batch activateprocess = runtimeService.updateProcessInstanceSuspensionState().byHistoricProcessInstanceQuery(historyService.createHistoricProcessInstanceQuery().processInstanceIds(Sets.newHashSet(processInstance1.getId(), processInstance2.getId()))).activateAsync();
  helper.completeSeedJobs(activateprocess);
  helper.executeJobs(activateprocess);


  // then
  ProcessInstance p1c = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance1.getId()).singleResult();
  assertFalse(p1c.isSuspended());
  ProcessInstance p2c = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance2.getId()).singleResult();
  assertFalse(p2c.isSuspended());
}
 
Example 2
Source File: UpdateProcessInstancesSuspendStateAsyncTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {"org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml",
  "org/camunda/bpm/engine/test/api/externaltask/twoExternalTaskProcess.bpmn20.xml"})
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testBatchSuspensionByHistoricProcessInstanceQuery() {
  // given
  ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
  ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("twoExternalTaskProcess");

  // when
  Batch suspendprocess = runtimeService.updateProcessInstanceSuspensionState().byHistoricProcessInstanceQuery(historyService.createHistoricProcessInstanceQuery().processInstanceIds(Sets.newHashSet(processInstance1.getId(), processInstance2.getId()))).suspendAsync();
  helper.completeSeedJobs(suspendprocess);
  helper.executeJobs(suspendprocess);


  // then
  ProcessInstance p1c = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance1.getId()).singleResult();
  assertTrue(p1c.isSuspended());
  ProcessInstance p2c = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance2.getId()).singleResult();
  assertTrue(p2c.isSuspended());

}
 
Example 3
Source File: RuntimeServiceAsyncOperationsTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
@Deployment(resources = {
    "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"})
@Test
public void testDeleteProcessInstancesAsyncWithRuntimeAndHistoryQuery() {
  // given
  List<String> processIds = startTestProcesses(2);
  HistoricProcessInstanceQuery historicProcessInstanceQuery =
      historyService.createHistoricProcessInstanceQuery()
          .processInstanceId(processIds.get(0));

  ProcessInstanceQuery processInstanceQuery =
      runtimeService.createProcessInstanceQuery().processInstanceId(processIds.get(1));

  // when
  Batch batch = runtimeService.deleteProcessInstancesAsync(null, processInstanceQuery,
      historicProcessInstanceQuery, "", false, false);

  completeSeedJobs(batch);
  executeBatchJobs(batch);

  // then
  assertHistoricTaskDeletionPresent(processIds, "deleted", testRule);
  assertHistoricBatchExists(testRule);
  assertProcessInstancesAreDeleted();
}
 
Example 4
Source File: ManagementServiceAsyncOperationsTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
@Test
public void shouldSetInvocationsPerBatchTypeForJobsByProcessInstanceIds() {
  // given
  engineRule.getProcessEngineConfiguration()
      .getInvocationsPerBatchJobByBatchType()
      .put(Batch.TYPE_SET_JOB_RETRIES, 42);

  HistoricProcessInstanceQuery historicProcessInstanceQuery =
      historyService.createHistoricProcessInstanceQuery();

  //when
  Batch batch = managementService.setJobRetriesAsync(null, null,
      historicProcessInstanceQuery, RETRIES);

  // then
  Assertions.assertThat(batch.getInvocationsPerBatchJob()).isEqualTo(42);

  // clear
  engineRule.getProcessEngineConfiguration()
      .setInvocationsPerBatchJobByBatchType(new HashMap<>());
}
 
Example 5
Source File: ManagementServiceAsyncOperationsTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
@Test
public void testSetJobsRetryAsyncWithHistoryProcessQuery() {
  //given
  HistoricProcessInstanceQuery historicProcessInstanceQuery =
      historyService.createHistoricProcessInstanceQuery();

  //when
  Batch batch = managementService.setJobRetriesAsync(null, null,
      historicProcessInstanceQuery, RETRIES);
  completeSeedJobs(batch);
  List<Exception> exceptions = executeBatchJobs(batch);

  // then
  assertThat(exceptions.size(), is(0));
  assertRetries(ids, RETRIES);
  assertHistoricBatchExists(testRule);
}
 
Example 6
Source File: BoundedNumberOfMaxResultsTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
@Test
public void shouldReturnSingleResult_BoundedMaxResults() {
  // given
  BpmnModelInstance process = Bpmn.createExecutableProcess("process")
      .startEvent()
      .endEvent()
      .done();

  testHelper.deploy(process);

  runtimeService.startProcessInstanceByKey("process");

  HistoricProcessInstanceQuery historicProcessInstanceQuery =
      historyService.createHistoricProcessInstanceQuery();

  // when
  HistoricProcessInstance processInstance = historicProcessInstanceQuery.singleResult();

  // then
  assertThat(processInstance).isNotNull();
}
 
Example 7
Source File: BoundedNumberOfMaxResultsTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
@Test
public void shouldReturnResultWhenMaxResultsLimitNotExceeded2() {
  // given
  BpmnModelInstance process = Bpmn.createExecutableProcess("process")
      .startEvent("startEvent")
      .endEvent()
      .done();

  testHelper.deploy(process);

  runtimeService.startProcessInstanceByKey("process");

  HistoricProcessInstanceQuery historicProcessInstanceQuery =
      historyService.createHistoricProcessInstanceQuery();

  // when
  List<HistoricProcessInstance> historicProcessInstances =
      historicProcessInstanceQuery.listPage(0, 9);

  // then
  assertThat(historicProcessInstances.size()).isEqualTo(1);
}
 
Example 8
Source File: BoundedNumberOfMaxResultsTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
@Test
public void shouldThrowExceptionWhenUpdateProcInstSuspStateByHistProcInstQuery_LimitExceeded() {
  // given
  engineRule.getProcessEngineConfiguration().setQueryMaxResultsLimit(2);

  testHelper.deploy(simpleProcess);

  runtimeService.startProcessInstanceByKey("process");
  runtimeService.startProcessInstanceByKey("process");
  runtimeService.startProcessInstanceByKey("process");

  try {
    // when
    runtimeService.updateProcessInstanceSuspensionState()
        .byHistoricProcessInstanceQuery(historyService.createHistoricProcessInstanceQuery())
        .suspend();
    fail("Exception expected!");
  } catch (BadUserRequestException e) {

    // then
    assertThat(e).hasMessage("Max results limit of 2 exceeded!");
  }
}
 
Example 9
Source File: UpdateProcessInstancesSuspendStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {"org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml",
  "org/camunda/bpm/engine/test/api/externaltask/twoExternalTaskProcess.bpmn20.xml"})
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testBatchActivatationByHistoricProcessInstanceQuery() {
  // given
  ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
  ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("twoExternalTaskProcess");


  // when the process instances are suspended
  runtimeService.updateProcessInstanceSuspensionState()
    .byHistoricProcessInstanceQuery(historyService.createHistoricProcessInstanceQuery().processInstanceIds(Sets.newHashSet(processInstance1.getId(), processInstance2.getId()))).suspend();

  // when they are activated again
  runtimeService.updateProcessInstanceSuspensionState()
    .byHistoricProcessInstanceQuery(historyService.createHistoricProcessInstanceQuery().processInstanceIds(Sets.newHashSet(processInstance1.getId(), processInstance2.getId()))).activate();


  // Update the process instances and they are active again
  ProcessInstance p1c = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance1.getId()).singleResult();
  assertFalse(p1c.isSuspended());
  ProcessInstance p2c = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance2.getId()).singleResult();
  assertFalse(p2c.isSuspended());

}
 
Example 10
Source File: MigrationHistoricTaskInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testMigrateWithSubTask() {
  //given
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);

  MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
      .mapEqualActivities()
      .build();

  ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());

  Task task = taskService.createTaskQuery().singleResult();
  Task subTask = taskService.newTask();
  subTask.setParentTaskId(task.getId());
  taskService.saveTask(subTask);

  // when
  runtimeService.newMigration(migrationPlan)
    .processInstanceIds(Arrays.asList(processInstance.getId()))
    .execute();

  // then the historic sub task instance is still the same
  HistoricTaskInstance historicSubTaskAfterMigration = historyService
      .createHistoricTaskInstanceQuery().taskId(subTask.getId()).singleResult();

  Assert.assertNotNull(historicSubTaskAfterMigration);
  Assert.assertNull(historicSubTaskAfterMigration.getProcessDefinitionId());
  Assert.assertNull(historicSubTaskAfterMigration.getProcessDefinitionKey());
  Assert.assertNull(historicSubTaskAfterMigration.getExecutionId());
  Assert.assertNull(historicSubTaskAfterMigration.getActivityInstanceId());
}
 
Example 11
Source File: ProcessEngineTestCaseTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testRequiredHistoryLevelActivity() {

  assertThat(currentHistoryLevel(),
      CoreMatchers.<String>either(is(ProcessEngineConfiguration.HISTORY_ACTIVITY))
      .or(is(ProcessEngineConfiguration.HISTORY_AUDIT))
      .or(is(ProcessEngineConfiguration.HISTORY_FULL)));
}
 
Example 12
Source File: MigrationHistoricProcessInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testMigrateHistoryProcessInstance() {
  //given
  HistoricProcessInstanceQuery sourceHistoryProcessInstanceQuery =
      historyService.createHistoricProcessInstanceQuery()
        .processDefinitionId(sourceProcessDefinition.getId());
  HistoricProcessInstanceQuery targetHistoryProcessInstanceQuery =
      historyService.createHistoricProcessInstanceQuery()
        .processDefinitionId(targetProcessDefinition.getId());


  //when
  assertEquals(1, sourceHistoryProcessInstanceQuery.count());
  assertEquals(0, targetHistoryProcessInstanceQuery.count());
  ProcessInstanceQuery sourceProcessInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionId(sourceProcessDefinition.getId());
  runtimeService.newMigration(migrationPlan)
    .processInstanceQuery(sourceProcessInstanceQuery)
    .execute();

  //then
  assertEquals(0, sourceHistoryProcessInstanceQuery.count());
  assertEquals(1, targetHistoryProcessInstanceQuery.count());

  HistoricProcessInstance instance = targetHistoryProcessInstanceQuery.singleResult();
  assertEquals(instance.getProcessDefinitionKey(), targetProcessDefinition.getKey());
}
 
Example 13
Source File: MigrationHistoricActivityInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 14
Source File: BoundedNumberOfMaxResultsTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
@Test
public void shouldThrowExceptionWhenRestartProcessInstance_MaxResultsLimitExceeded() {
  // given
  engineRule.getProcessEngineConfiguration().setQueryMaxResultsLimit(2);

  BpmnModelInstance process = Bpmn.createExecutableProcess("process")
      .startEvent("startEvent")
      .endEvent()
      .done();

  String processDefinitionId =
      testHelper.deploy(process)
          .getDeployedProcessDefinitions()
          .get(0)
          .getId();

  runtimeService.startProcessInstanceByKey("process");
  runtimeService.startProcessInstanceByKey("process");
  runtimeService.startProcessInstanceByKey("process");

  try {
    // when
    runtimeService.restartProcessInstances(processDefinitionId)
        .historicProcessInstanceQuery(historyService.createHistoricProcessInstanceQuery())
        .startAfterActivity("startEvent")
        .execute();
    fail("Exception expected!");
  } catch (BadUserRequestException e) {

    // then
    assertThat(e).hasMessage("Max results limit of 2 exceeded!");
  }
}
 
Example 15
Source File: MigrationHistoricActivityInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 16
Source File: TaskListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
@Test
public void testUpdateTaskListenerOnCommentCreate() {
  // given
  createAndDeployModelWithTaskEventsRecorderOnUserTask(TaskListener.EVENTNAME_UPDATE);
  runtimeService.startProcessInstanceByKey("process");
  Task task = taskService.createTaskQuery().singleResult();

  // when
  taskService.createComment(task.getId(), null, "new comment");

  // then
  assertEquals(1, RecorderTaskListener.getTotalEventCount());
  assertEquals(1, RecorderTaskListener.getEventCount(TaskListener.EVENTNAME_UPDATE));
}
 
Example 17
Source File: TaskListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
@Test
public void testUpdateTaskListenerOnCommentAdd() {
  // given
  createAndDeployModelWithTaskEventsRecorderOnUserTask(TaskListener.EVENTNAME_UPDATE);
  runtimeService.startProcessInstanceByKey("process");
  Task task = taskService.createTaskQuery().singleResult();

  // when
  taskService.addComment(task.getId(), null, "new comment");

  // then
  assertEquals(1, RecorderTaskListener.getTotalEventCount());
  assertEquals(1, RecorderTaskListener.getEventCount(TaskListener.EVENTNAME_UPDATE));
}
 
Example 18
Source File: BoundedNumberOfMaxResultsTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
@Test
public void shouldReturnUnboundedResults_InsideCmd2() {
  // given
  engineRule.getProcessEngineConfiguration()
      .setQueryMaxResultsLimit(2);

  BpmnModelInstance process = Bpmn.createExecutableProcess("process")
      .startEvent("startEvent")
      .endEvent()
      .done();

  String processDefinitionId = testHelper.deploy(process)
      .getDeployedProcessDefinitions()
      .get(0)
      .getId();

  String processInstanceId = runtimeService.startProcessInstanceByKey("process")
      .getProcessInstanceId();

  try {
    // when
    runtimeService.restartProcessInstances(processDefinitionId)
        .processInstanceIds(processInstanceId)
        .startAfterActivity("startEvent")
        .execute();

    // then
    // do not fail
  } catch (BadUserRequestException e) {
    fail("The query inside the command should not throw an exception!");
  }
}
 
Example 19
Source File: CompensateEventTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void FAILING_testDeleteInstanceWithEventScopeExecution()
{
  // given
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("foo")
  .startEvent("start")
  .subProcess("subProcess")
    .embeddedSubProcess()
      .startEvent("subProcessStart")
      .endEvent("subProcessEnd")
  .subProcessDone()
  .userTask("userTask")
  .done();

  modelInstance = ModifiableBpmnModelInstance.modify(modelInstance)
    .addSubProcessTo("subProcess")
    .id("eventSubProcess")
      .triggerByEvent()
      .embeddedSubProcess()
        .startEvent()
          .compensateEventDefinition()
          .compensateEventDefinitionDone()
        .endEvent()
    .done();

  deployment(modelInstance);

  long dayInMillis = 1000 * 60 * 60 * 24;
  Date date1 = new Date(10 * dayInMillis);
  ClockUtil.setCurrentTime(date1);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("foo");

  // when
  Date date2 = new Date(date1.getTime() + dayInMillis);
  ClockUtil.setCurrentTime(date2);
  runtimeService.deleteProcessInstance(processInstance.getId(), null);

  // then
  List<HistoricActivityInstance> historicActivityInstance = historyService.createHistoricActivityInstanceQuery()
      .orderByActivityId().asc().list();
  assertEquals(5, historicActivityInstance.size());

  assertEquals("start", historicActivityInstance.get(0).getActivityId());
  assertEquals(date1, historicActivityInstance.get(0).getEndTime());
  assertEquals("subProcess", historicActivityInstance.get(1).getActivityId());
  assertEquals(date1, historicActivityInstance.get(1).getEndTime());
  assertEquals("subProcessEnd", historicActivityInstance.get(2).getActivityId());
  assertEquals(date1, historicActivityInstance.get(2).getEndTime());
  assertEquals("subProcessStart", historicActivityInstance.get(3).getActivityId());
  assertEquals(date1, historicActivityInstance.get(3).getEndTime());
  assertEquals("userTask", historicActivityInstance.get(4).getActivityId());
  assertEquals(date2, historicActivityInstance.get(4).getEndTime());


}
 
Example 20
Source File: MigrationHistoricTaskInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@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());
}