org.camunda.bpm.engine.history.HistoricActivityInstance Java Examples

The following examples show how to use org.camunda.bpm.engine.history.HistoricActivityInstance. 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: HistoricActivityInstanceDto.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static void fromHistoricActivityInstance(HistoricActivityInstanceDto dto,
                                                HistoricActivityInstance historicActivityInstance) {

  dto.id = historicActivityInstance.getId();
  dto.parentActivityInstanceId = historicActivityInstance.getParentActivityInstanceId();
  dto.activityId = historicActivityInstance.getActivityId();
  dto.activityName = historicActivityInstance.getActivityName();
  dto.activityType = historicActivityInstance.getActivityType();
  dto.processDefinitionKey = historicActivityInstance.getProcessDefinitionKey();
  dto.processDefinitionId = historicActivityInstance.getProcessDefinitionId();
  dto.processInstanceId = historicActivityInstance.getProcessInstanceId();
  dto.executionId = historicActivityInstance.getExecutionId();
  dto.taskId = historicActivityInstance.getTaskId();
  dto.calledProcessInstanceId = historicActivityInstance.getCalledProcessInstanceId();
  dto.calledCaseInstanceId = historicActivityInstance.getCalledCaseInstanceId();
  dto.assignee = historicActivityInstance.getAssignee();
  dto.startTime = historicActivityInstance.getStartTime();
  dto.endTime = historicActivityInstance.getEndTime();
  dto.durationInMillis = historicActivityInstance.getDurationInMillis();
  dto.canceled = historicActivityInstance.isCanceled();
  dto.completeScope = historicActivityInstance.isCompleteScope();
  dto.tenantId = historicActivityInstance.getTenantId();
  dto.removalTime = historicActivityInstance.getRemovalTime();
  dto.rootProcessInstanceId = historicActivityInstance.getRootProcessInstanceId();
}
 
Example #2
Source File: HistoricActivityInstanceStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testEventSubprocessErrorCancel() {
  ProcessInstance processInstance = startProcess();
  runtimeService.correlateMessage("continue");
  assertProcessEnded(processInstance.getId());

  List<HistoricActivityInstance> allInstances = getAllActivityInstances();

  assertIsCanceledActivityInstances(allInstances, "userTask", 1);
  assertNonCompletingActivityInstance(allInstances, "userTask");

  assertIsCanceledActivityInstances(allInstances, "errorEnd", 1);
  assertNonCompletingActivityInstance(allInstances, "errorEnd");

  assertNonCanceledActivityInstance(allInstances, "eventSubprocessStart");
  assertNonCompletingActivityInstance(allInstances, "eventSubprocessStart");

  assertNonCanceledActivityInstance(allInstances, "eventSubprocessEnd");
  assertIsCompletingActivityInstances(allInstances, "eventSubprocessEnd", 1);
}
 
Example #3
Source File: HistoricActivityInstanceRestServiceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryFilterWithoutTenantIdParameter() {
  // given
  HistoricActivityInstance activityInstance = MockProvider.createMockHistoricActivityInstance(null);
  mockedQuery = setUpMockHistoricActivityInstanceQuery(Collections.singletonList(activityInstance));

  // when
  Response response = given()
      .queryParam("withoutTenantId", true)
      .then().expect()
      .statusCode(Status.OK.getStatusCode())
      .when()
      .get(HISTORIC_ACTIVITY_INSTANCE_RESOURCE_URL);

  // then
  verify(mockedQuery).withoutTenantId();
  verify(mockedQuery).list();

  String content = response.asString();
  List<String> definitions = from(content).getList("");
  assertThat(definitions).hasSize(1);

  String returnedTenantId = from(content).getString("[0].tenantId");
  assertThat(returnedTenantId).isEqualTo(null);
}
 
Example #4
Source File: ProcessInstantiationAtActivitiesHistoryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS)
public void testHistoricProcessInstanceForSingleActivityInstantiation() {
  // when
  ProcessInstance instance = runtimeService
    .createProcessInstanceByKey("exclusiveGateway")
    .startBeforeActivity("task1")
    .execute();

  // then
  HistoricProcessInstance historicInstance = historyService.createHistoricProcessInstanceQuery().singleResult();
  assertNotNull(historicInstance);
  assertEquals(instance.getId(), historicInstance.getId());
  assertNotNull(historicInstance.getStartTime());
  assertNull(historicInstance.getEndTime());

  // should be the first activity started
  assertEquals("task1", historicInstance.getStartActivityId());

  HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().singleResult();
  assertNotNull(historicActivityInstance);
  assertEquals("task1", historicActivityInstance.getActivityId());
  assertNotNull(historicActivityInstance.getId());
  assertFalse(instance.getId().equals(historicActivityInstance.getId()));
  assertNotNull(historicActivityInstance.getStartTime());
  assertNull(historicActivityInstance.getEndTime());
}
 
Example #5
Source File: HistoricRootProcessInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldResolveHistoricActivityInstance() {
  // given
  testRule.deploy(CALLING_PROCESS);

  testRule.deploy(CALLED_PROCESS);

  // when
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY);

  HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery()
    .activityId("userTask")
    .singleResult();

  // assume
  assertThat(historicActivityInstance, notNullValue());

  // then
  assertThat(historicActivityInstance.getRootProcessInstanceId(), is(processInstance.getProcessInstanceId()));
}
 
Example #6
Source File: BatchSetRemovalTimeNonHierarchicalTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSetRemovalTime_ActivityInstance() {
  // given
  testRule.process().userTask().deploy().start();

  HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery();

  // when
  testRule.syncExec(
    historyService.setRemovalTimeToHistoricProcessInstances()
      .absoluteRemovalTime(REMOVAL_TIME)
      .byQuery(query)
      .executeAsync()
  );

  HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery()
    .activityName("userTask")
    .singleResult();

  // then
  assertThat(historicActivityInstance.getRemovalTime()).isEqualTo(REMOVAL_TIME);
}
 
Example #7
Source File: HistoricActivityInstanceStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testBoundarySignalCancel() {
  ProcessInstance processInstance = startProcess();

  // should wait in user task
  assertFalse(processInstance.isEnded());

  // signal sub process
  runtimeService.signalEventReceived("interrupt");

  List<HistoricActivityInstance> allInstances = getAllActivityInstances();

  assertNonCompletingActivityInstance(allInstances, "subprocess");
  assertIsCanceledActivityInstances(allInstances, "subprocess", 1);

  assertIsCanceledActivityInstances(allInstances, "userTask", 1);
  assertNonCompletingActivityInstance(allInstances, "userTask");

  assertNonCanceledActivityInstance(allInstances, "subprocessBoundary");
  assertNonCompletingActivityInstance(allInstances, "subprocessBoundary");

  assertNonCanceledActivityInstance(allInstances, "endAfterBoundary");
  assertIsCompletingActivityInstances(allInstances, "endAfterBoundary", 1);
}
 
Example #8
Source File: OptimizeRestService.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/activity-instance/running")
public List<OptimizeHistoricActivityInstanceDto> getRunningHistoricActivityInstances(@QueryParam("startedAfter") String startedAfterAsString,
                                                                                     @QueryParam("startedAt") String startedAtAsString,
                                                                                     @QueryParam("maxResults") int maxResults) {

  Date startedAfter = dateConverter.convertQueryParameterToType(startedAfterAsString);
  Date startedAt = dateConverter.convertQueryParameterToType(startedAtAsString);
  maxResults = ensureValidMaxResults(maxResults);

  ProcessEngineConfigurationImpl config =
    (ProcessEngineConfigurationImpl) getProcessEngine().getProcessEngineConfiguration();

  List<HistoricActivityInstance> historicActivityInstances =
    config.getOptimizeService().getRunningHistoricActivityInstances(startedAfter, startedAt, maxResults);

  List<OptimizeHistoricActivityInstanceDto> result = new ArrayList<>();
  for (HistoricActivityInstance instance : historicActivityInstances) {
    OptimizeHistoricActivityInstanceDto dto = OptimizeHistoricActivityInstanceDto.fromHistoricActivityInstance(instance);
    result.add(dto);
  }
  return result;
}
 
Example #9
Source File: LinkEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testEventLinkMultipleSources() {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("linkEventValid");
  List<String> activeActivities = runtimeService.getActiveActivityIds(pi.getId());

  // assert that the link event was triggered and that we are
  assertEquals(Arrays.asList(new String []{"WaitAfterLink", "WaitAfterLink"}), activeActivities);

  runtimeService.deleteProcessInstance(pi.getId(), "test done");

  // validate history
  if(processEngineConfiguration.getHistoryLevel().getId() >= ProcessEngineConfigurationImpl.HISTORYLEVEL_ACTIVITY) {
    List<HistoricActivityInstance> activities = historyService.createHistoricActivityInstanceQuery().processInstanceId(pi.getId()).orderByActivityId().asc().list();
    assertEquals(5, activities.size());
    assertEquals("ManualTask_1", activities.get(0).getActivityId());
    assertEquals("ParallelGateway_1", activities.get(1).getActivityId());
    assertEquals("StartEvent_1", activities.get(2).getActivityId());
    assertEquals("WaitAfterLink", activities.get(3).getActivityId());
    assertEquals("WaitAfterLink", activities.get(4).getActivityId());
  }

}
 
Example #10
Source File: HistoricActivityInstanceRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public List<HistoricActivityInstanceDto> queryHistoricActivityInstances(HistoricActivityInstanceQueryDto queryDto, Integer firstResult, Integer maxResults) {
  queryDto.setObjectMapper(objectMapper);
  HistoricActivityInstanceQuery query = queryDto.toQuery(processEngine);

  List<HistoricActivityInstance> matchingHistoricActivityInstances;
  if (firstResult != null || maxResults != null) {
    matchingHistoricActivityInstances = executePaginatedQuery(query, firstResult, maxResults);
  } else {
    matchingHistoricActivityInstances = query.list();
  }

  List<HistoricActivityInstanceDto> historicActivityInstanceResults = new ArrayList<HistoricActivityInstanceDto>();
  for (HistoricActivityInstance historicActivityInstance : matchingHistoricActivityInstances) {
    HistoricActivityInstanceDto resultHistoricActivityInstance = new HistoricActivityInstanceDto();
    HistoricActivityInstanceDto.fromHistoricActivityInstance(resultHistoricActivityInstance, historicActivityInstance);
    historicActivityInstanceResults.add(resultHistoricActivityInstance);
  }
  return historicActivityInstanceResults;
}
 
Example #11
Source File: DeferredExecutable.java    From camunda-bpm-assert-scenario with Apache License 2.0 6 votes vote down vote up
protected DeferredExecutable(ProcessRunnerImpl runner, HistoricActivityInstance instance, String period, Deferred action) {
  super(runner);
  this.delegate = instance;
  this.isExecutableAt = Time.dateAfter(period);
  this.action = action;
  Log.Action.Deferring_Action.log(
      instance.getActivityType(),
      instance.getActivityName(),
      instance.getActivityId(),
      runner.getProcessDefinitionKey(),
      instance.getProcessInstanceId(),
      action.toString(),
      isExecutableAt
  );
  Deferreds.add(this);
}
 
Example #12
Source File: HistoricActivityInstanceStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment (resources={ "org/camunda/bpm/engine/test/history/HistoricActivityInstanceStateTest.testCancelProcessInstanceInUserTask.bpmn",
    "org/camunda/bpm/engine/test/history/HistoricActivityInstanceStateTest.testEndTerminateEventWithCallActivity.bpmn" })
public void testEndTerminateEventCancelWithCallActivity() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process1");
  runtimeService.correlateMessage("continue");
  assertProcessEnded(processInstance.getId());

  List<HistoricActivityInstance> allInstances = getAllActivityInstances();

  assertIsCanceledActivityInstances(allInstances, "callActivity", 1);
  assertNonCompletingActivityInstance(allInstances, "callActivity");

  assertIsCanceledActivityInstances(allInstances, "userTask", 1);
  assertNonCompletingActivityInstance(allInstances, "userTask");

  assertNonCanceledActivityInstance(allInstances, "terminateEnd");
  assertIsCompletingActivityInstances(allInstances, "terminateEnd", 1);

}
 
Example #13
Source File: GetRunningHistoricActivityInstancesForOptimizeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void startedAtParameterWorks() {
  // given
  BpmnModelInstance simpleDefinition = Bpmn.createExecutableProcess("process")
    .startEvent("startEvent")
    .userTask("userTask")
    .endEvent("endEvent")
    .done();
  testHelper.deploy(simpleDefinition);
  Date now = new Date();
  Date nowPlus2Seconds = new Date(now.getTime() + 2000L);
  ClockUtil.setCurrentTime(now);
  ProcessInstance firstProcessInstance =
    engineRule.getRuntimeService().startProcessInstanceByKey("process");

  // when
  ClockUtil.setCurrentTime(nowPlus2Seconds);
  engineRule.getRuntimeService().startProcessInstanceByKey("process");
  List<HistoricActivityInstance> runningHistoricActivityInstances =
    optimizeService.getRunningHistoricActivityInstances(null, now, 10);

  // then
  assertThat(runningHistoricActivityInstances.size(), is(1));
  assertThat(runningHistoricActivityInstances.get(0).getProcessInstanceId(), is(firstProcessInstance.getId()));
}
 
Example #14
Source File: HistoricActivityInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testHistoricActivityInstanceProperties() {
  // Start process instance
  runtimeService.startProcessInstanceByKey("taskAssigneeProcess");

  // Get task list
  HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("theTask").singleResult();

  Task task = taskService.createTaskQuery().singleResult();
  assertEquals(task.getId(), historicActivityInstance.getTaskId());
  assertEquals("kermit", historicActivityInstance.getAssignee());

  // change assignee of the task
  taskService.setAssignee(task.getId(), "gonzo");
  task = taskService.createTaskQuery().singleResult();

  historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("theTask").singleResult();
  assertEquals("gonzo", historicActivityInstance.getAssignee());
}
 
Example #15
Source File: GetCompletedHistoricActivityInstancesForOptimizeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void getCompletedHistoricActivityInstances() {
   // given
  BpmnModelInstance simpleDefinition = Bpmn.createExecutableProcess("process")
    .startEvent("startEvent")
      .name("start")
    .endEvent("endEvent")
      .name("end")
    .done();
  testHelper.deploy(simpleDefinition);
  runtimeService.startProcessInstanceByKey("process");

  // when
  List<HistoricActivityInstance> completedHistoricActivityInstances =
    optimizeService.getCompletedHistoricActivityInstances(pastDate(), null, 10);

  // then
  assertThat(completedHistoricActivityInstances.size(), is(2));
  assertThatActivitiesHaveAllImportantInformation(completedHistoricActivityInstances);
}
 
Example #16
Source File: HistoricActivityInstanceStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void assertCorrectCompletingState(List<HistoricActivityInstance> allInstances, String activityId, int expectedCount, boolean completing) {
  int found = 0;

  for (HistoricActivityInstance instance : allInstances) {
    if (instance.getActivityId().equals(activityId)) {
      found++;
      assertEquals(String.format("expect <%s> to be %scompleting", activityId, (completing ? "" : "non-")), completing, instance.isCompleteScope());
    }
  }

  assertTrue("contains entry for activity <" + activityId + ">", found > 0);

  if (expectedCount != -1) {
    assertTrue("contains <" + expectedCount + "> entries for activity <" + activityId + ">", found == expectedCount);
  }
}
 
Example #17
Source File: GetCompletedHistoricActivityInstancesForOptimizeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void fishedAfterAndFinishedAtParameterWorks() {
   // given
  BpmnModelInstance simpleDefinition = Bpmn.createExecutableProcess("process")
    .startEvent("startEvent")
    .userTask("userTask")
    .endEvent("endEvent")
    .done();
  testHelper.deploy(simpleDefinition);
  Date now = new Date();
  Date nowPlus2Seconds = new Date(now.getTime() + 2000L);
  ClockUtil.setCurrentTime(now);
  engineRule.getRuntimeService().startProcessInstanceByKey("process");

  // when
  ClockUtil.setCurrentTime(nowPlus2Seconds);
  completeAllUserTasks();
  List<HistoricActivityInstance> completedHistoricActivityInstances =
    optimizeService.getCompletedHistoricActivityInstances(now, now, 10);

  // then
  assertThat(completedHistoricActivityInstances.size(), is(0));
}
 
Example #18
Source File: HistoricActivityInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/history/HistoricActivityInstanceTest.testHistoricActivityInstanceQueryByCompleteScope.bpmn")
public void testHistoricActivityInstanceQueryByCanceled() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");

  runtimeService.deleteProcessInstance(processInstance.getId(), "test");

  HistoricActivityInstanceQuery query = historyService.createHistoricActivityInstanceQuery().canceled();

  assertEquals(3, query.count());

  List<HistoricActivityInstance> instances = query.list();

  for (HistoricActivityInstance instance : instances) {
    if (!instance.getActivityId().equals("subprocess") && !instance.getActivityId().equals("userTask1") && !instance.getActivityId().equals("userTask2")) {
      fail("Unexpected instance with activity id " + instance.getActivityId() + " found.");
    }
  }

  assertProcessEnded(processInstance.getId());
}
 
Example #19
Source File: HistoricActivityInstanceStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testEndTerminateEventCancelWithSubprocess() {
  ProcessInstance processInstance = startProcess();
  runtimeService.correlateMessage("continue");
  assertProcessEnded(processInstance.getId());

  List<HistoricActivityInstance> allInstances = getAllActivityInstances();

  assertIsCanceledActivityInstances(allInstances, "subprocess", 1);
  assertNonCompletingActivityInstance(allInstances, "subprocess");

  assertIsCanceledActivityInstances(allInstances, "userTask", 1);
  assertNonCompletingActivityInstance(allInstances, "userTask");

  assertNonCanceledActivityInstance(allInstances, "terminateEnd");
  assertIsCompletingActivityInstances(allInstances, "terminateEnd", 1);

}
 
Example #20
Source File: InterruptingEventSubProcessCompensationSenarioTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Does not work because in PvmAtomicOperationActivityInstanceEnd we don't correctly
 * detect that the compensation throw event has no dedicated scope execution, so we restore
 * activity instance IDs wrongly before firing the history listener.
 */
@Ignore
@Test
@ScenarioUnderTest("init.throwCompensate.2")
public void testInitThrowCompensateCompletionHistory() {
  // given
  ProcessInstance processInstance = rule.processInstance();
  Task undoTask = rule.taskQuery().singleResult();

  // when
  rule.getTaskService().complete(undoTask.getId());
  Task afterCompensateTask = rule.taskQuery().singleResult();
  rule.getTaskService().complete(afterCompensateTask.getId());

  // then the historic throw compensate instance has an end time
  HistoricActivityInstance throwCompensateInstance = rule.getHistoryService()
    .createHistoricActivityInstanceQuery()
    .processInstanceId(processInstance.getId())
    .activityId("throwCompensate")
    .singleResult();

  Assert.assertNotNull(throwCompensateInstance.getEndTime());
}
 
Example #21
Source File: GetCompletedHistoricActivityInstancesForOptimizeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void fetchOnlyCompletedActivities() {
   // given
  BpmnModelInstance simpleDefinition = Bpmn.createExecutableProcess("process")
    .startEvent("startEvent")
    .userTask()
    .endEvent()
    .done();
  testHelper.deploy(simpleDefinition);
  engineRule.getRuntimeService().startProcessInstanceByKey("process");

  // when
  List<HistoricActivityInstance> completedHistoricActivityInstances =
    optimizeService.getCompletedHistoricActivityInstances(pastDate(), null, 10);

  // then
  assertThat(completedHistoricActivityInstances.size(), is(1));
  assertThat(completedHistoricActivityInstances.get(0).getActivityId(), is("startEvent"));
}
 
Example #22
Source File: MultiInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/bpmn/multiinstance/MultiInstanceTest.testSequentialScriptTasks.bpmn20.xml"})
public void testSequentialScriptTasksHistory() {
  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("sum", 0);
  vars.put("nrOfLoops", 7);
  runtimeService.startProcessInstanceByKey("miSequentialScriptTask", vars);

  // Validate history
  if (processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
    List<HistoricActivityInstance> historicInstances = historyService.createHistoricActivityInstanceQuery().activityType("scriptTask").orderByActivityId().asc().list();
    assertEquals(7, historicInstances.size());
    for (int i=0; i<7; i++) {
      HistoricActivityInstance hai = historicInstances.get(i);
      assertEquals("scriptTask", hai.getActivityType());
      assertNotNull(hai.getStartTime());
      assertNotNull(hai.getEndTime());
    }
  }
}
 
Example #23
Source File: HistoricActivityInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/history/HistoricActivityInstanceTest.testHistoricActivityInstanceProperties.bpmn20.xml"})
public void testAssigneeSavedWhenTaskSaved() {
  // given
  HistoricActivityInstanceQuery query = historyService
      .createHistoricActivityInstanceQuery()
      .activityId("theTask");

  runtimeService.startProcessInstanceByKey("taskAssigneeProcess");
  HistoricActivityInstance historicActivityInstance = query.singleResult();

  Task task = taskService.createTaskQuery().singleResult();

  // assume
  assertEquals("kermit", historicActivityInstance.getAssignee());

  // when
  task.setAssignee("gonzo");
  taskService.saveTask(task);

  // then
  historicActivityInstance = query.singleResult();
  assertEquals("gonzo", historicActivityInstance.getAssignee());
}
 
Example #24
Source File: ProcessEngineRestServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void createHistoricActivityInstanceMock() {
  List<HistoricActivityInstance> activities = new ArrayList<HistoricActivityInstance>();
  HistoricActivityInstance mockInstance = MockProvider.createMockHistoricActivityInstance();
  activities.add(mockInstance);

  HistoricActivityInstanceQuery mockHistoricActivityInstanceQuery = mock(HistoricActivityInstanceQuery.class);
  when(mockHistoricActivityInstanceQuery.list()).thenReturn(activities);
  when(mockHistoryService.createHistoricActivityInstanceQuery()).thenReturn(mockHistoricActivityInstanceQuery);
}
 
Example #25
Source File: HistoricActivityInstanceStateTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testSingleEndActivity() {
  startProcess();

  List<HistoricActivityInstance> allInstances = getAllActivityInstances();

  assertNonCompletingActivityInstance(allInstances, "start", 1);
  assertNonCanceledActivityInstance(allInstances, "start");

  assertIsCompletingActivityInstances(allInstances, "end", 1);
  assertNonCanceledActivityInstance(allInstances, "end");
}
 
Example #26
Source File: HistoricActivityInstanceRestServiceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnfinishedHistoricActivityQuery() {
  List<HistoricActivityInstance> mockedHistoricActivityInstances = MockProvider.createMockRunningHistoricActivityInstances();
  HistoricActivityInstanceQuery mockedhistoricActivityInstanceQuery = mock(HistoricActivityInstanceQuery.class);
  when(mockedhistoricActivityInstanceQuery.list()).thenReturn(mockedHistoricActivityInstances);
  when(processEngine.getHistoryService().createHistoricActivityInstanceQuery()).thenReturn(mockedhistoricActivityInstanceQuery);

  Response response = given()
      .queryParam("unfinished", true)
    .then()
      .expect()
        .statusCode(Status.OK.getStatusCode())
      .when()
        .get(HISTORIC_ACTIVITY_INSTANCE_RESOURCE_URL);

  InOrder inOrder = inOrder(mockedhistoricActivityInstanceQuery);
  inOrder.verify(mockedhistoricActivityInstanceQuery).unfinished();
  inOrder.verify(mockedhistoricActivityInstanceQuery).list();

  String content = response.asString();
  List<String> instances = from(content).getList("");
  Assert.assertEquals("There should be one activity instance returned.", 1, instances.size());
  Assert.assertNotNull("The returned activity instance should not be null.", instances.get(0));

  String returnedProcessDefinitionId = from(content).getString("[0].processDefinitionId");
  String returnedActivityEndTime = from(content).getString("[0].endTime");

  Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID, returnedProcessDefinitionId);
  Assert.assertNull(returnedActivityEndTime);
}
 
Example #27
Source File: BatchSetRemovalTimeHierarchicalTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSetRemovalTime_ActivityInstance() {
  // given
  testRule.process().call().userTask().deploy().start();

  HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery()
    .activityName("userTask")
    .singleResult();

  // assume
  assertThat(historicActivityInstance.getRemovalTime()).isNull();

  testRule.updateHistoryTimeToLive("rootProcess", 5);

  HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().rootProcessInstances();

  // when
  testRule.syncExec(
    historyService.setRemovalTimeToHistoricProcessInstances()
      .calculatedRemovalTime()
      .byQuery(query)
      .hierarchical()
      .executeAsync()
  );

  historicActivityInstance = historyService.createHistoricActivityInstanceQuery()
    .activityName("userTask")
    .singleResult();

  // then
  assertThat(historicActivityInstance.getRemovalTime()).isEqualTo(addDays(CURRENT_DATE, 5));
}
 
Example #28
Source File: MultiTenancyHistoricActivityInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldQuerySortingDesc() {
  // when
  List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery()
      .orderByTenantId()
      .desc()
      .list();

  // then
  assertThat(historicActivityInstances.size()).isEqualTo(6);
  verifySorting(historicActivityInstances, inverted(historicActivityInstanceByTenantId()));
}
 
Example #29
Source File: HistoricActivityInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/engine/test/history/calledProcess.bpmn20.xml",
    "org/camunda/bpm/engine/test/history/HistoricActivityInstanceTest.testCallSimpleSubProcess.bpmn20.xml" })
public void testHistoricActivityInstanceCalledProcessId() {
  runtimeService.startProcessInstanceByKey("callSimpleSubProcess");

  HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("callSubProcess").singleResult();

  HistoricProcessInstance oldInstance = historyService.createHistoricProcessInstanceQuery().processDefinitionKey("calledProcess").singleResult();

  assertEquals(oldInstance.getId(), historicActivityInstance.getCalledProcessInstanceId());
}
 
Example #30
Source File: MultiTenancyHistoricActivityInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldQuerySortingAsc() {
  // when
  List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery()
      .orderByTenantId()
      .asc()
      .list();

  // then
  assertThat(historicActivityInstances.size()).isEqualTo(6);
  verifySorting(historicActivityInstances, historicActivityInstanceByTenantId());
}