Search in sources :

Example 26 with HistoricCaseActivityInstance

use of org.camunda.bpm.engine.history.HistoricCaseActivityInstance in project camunda-bpm-platform by camunda.

the class HistoricCaseActivityInstanceTest method testQuerySorting.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn", "org/camunda/bpm/engine/test/api/cmmn/twoTaskCase.cmmn" })
public void testQuerySorting() {
    String taskId1 = "PI_HumanTask_1";
    String taskId2 = "PI_HumanTask_2";
    String oneTaskCaseId = createCaseInstanceByKey("oneTaskCase").getId();
    String twoTaskCaseId = createCaseInstanceByKey("twoTaskCase").getId();
    CaseExecution task1 = caseService.createCaseExecutionQuery().caseInstanceId(oneTaskCaseId).activityId(taskId1).singleResult();
    CaseExecution task2 = caseService.createCaseExecutionQuery().caseInstanceId(twoTaskCaseId).activityId(taskId1).singleResult();
    CaseExecution task3 = caseService.createCaseExecutionQuery().caseInstanceId(twoTaskCaseId).activityId(taskId2).singleResult();
    // sort by historic case activity instance ids
    assertQuerySorting("id", historicQuery().orderByHistoricCaseActivityInstanceId(), task1.getId(), task2.getId(), task3.getId());
    // sort by case instance ids
    assertQuerySorting("caseInstanceId", historicQuery().orderByCaseInstanceId(), oneTaskCaseId, twoTaskCaseId, twoTaskCaseId);
    // sort by case execution ids
    assertQuerySorting("caseExecutionId", historicQuery().orderByCaseExecutionId(), task1.getId(), task2.getId(), task3.getId());
    // sort by case activity ids
    assertQuerySorting("caseActivityId", historicQuery().orderByCaseActivityId(), taskId1, taskId1, taskId2);
    // sort by case activity names
    assertQuerySorting("caseActivityName", historicQuery().orderByCaseActivityName(), "A HumanTask", "A HumanTask", "Another HumanTask");
    // sort by case definition ids
    assertQuerySorting("caseDefinitionId", historicQuery().orderByCaseDefinitionId(), task1.getCaseDefinitionId(), task2.getCaseDefinitionId(), task3.getCaseDefinitionId());
    // manually start tasks to be able to complete them
    manualStart(task2.getId());
    manualStart(task3.getId());
    // complete tasks to set end time and duration
    for (Task task : taskService.createTaskQuery().list()) {
        taskService.complete(task.getId());
    }
    HistoricCaseActivityInstanceQuery query = historyService.createHistoricCaseActivityInstanceQuery();
    HistoricCaseActivityInstance historicTask1 = query.caseInstanceId(oneTaskCaseId).caseActivityId(taskId1).singleResult();
    HistoricCaseActivityInstance historicTask2 = query.caseInstanceId(twoTaskCaseId).caseActivityId(taskId1).singleResult();
    HistoricCaseActivityInstance historicTask3 = query.caseInstanceId(twoTaskCaseId).caseActivityId(taskId2).singleResult();
    // sort by create times
    assertQuerySorting("createTime", historicQuery().orderByHistoricCaseActivityInstanceCreateTime(), historicTask1.getCreateTime(), historicTask2.getCreateTime(), historicTask3.getCreateTime());
    // sort by end times
    assertQuerySorting("endTime", historicQuery().orderByHistoricCaseActivityInstanceEndTime(), historicTask1.getEndTime(), historicTask2.getEndTime(), historicTask3.getEndTime());
    // sort by durations times
    assertQuerySorting("durationInMillis", historicQuery().orderByHistoricCaseActivityInstanceDuration(), historicTask1.getDurationInMillis(), historicTask2.getDurationInMillis(), historicTask3.getDurationInMillis());
}
Also used : Task(org.camunda.bpm.engine.task.Task) CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) HistoricCaseActivityInstance(org.camunda.bpm.engine.history.HistoricCaseActivityInstance) HistoricCaseActivityInstanceQuery(org.camunda.bpm.engine.history.HistoricCaseActivityInstanceQuery) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 27 with HistoricCaseActivityInstance

use of org.camunda.bpm.engine.history.HistoricCaseActivityInstance in project camunda-bpm-platform by camunda.

the class HistoricCaseActivityInstanceTest method assertHistoricEndTime.

protected void assertHistoricEndTime(String activityId, Date expectedEndTime) {
    HistoricCaseActivityInstance historicActivityInstance = queryHistoricActivityCaseInstance(activityId);
    Date actualEndTime = historicActivityInstance.getEndTime();
    assertSimilarDate(expectedEndTime, actualEndTime);
}
Also used : HistoricCaseActivityInstance(org.camunda.bpm.engine.history.HistoricCaseActivityInstance) Date(java.util.Date)

Example 28 with HistoricCaseActivityInstance

use of org.camunda.bpm.engine.history.HistoricCaseActivityInstance in project camunda-bpm-platform by camunda.

the class HistoricCaseActivityInstanceTest method testMilestoneHistoricActivityInstanceIsTerminatedOnComplete.

@Deployment
public void testMilestoneHistoricActivityInstanceIsTerminatedOnComplete() {
    // given
    createCaseInstance();
    final String milestoneId = "PI_Milestone_1";
    CaseExecution caseMilestone = queryCaseExecutionByActivityId(milestoneId);
    assertTrue(caseMilestone.isAvailable());
    // when
    CaseExecution casePlanExecution = queryCaseExecutionByActivityId("CasePlanModel_1");
    complete(casePlanExecution.getId());
    // then make sure that the milestone is terminated
    HistoricCaseActivityInstance milestoneInstance = historyService.createHistoricCaseActivityInstanceQuery().caseActivityId(milestoneId).singleResult();
    assertTrue(milestoneInstance.isTerminated());
}
Also used : CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) HistoricCaseActivityInstance(org.camunda.bpm.engine.history.HistoricCaseActivityInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 29 with HistoricCaseActivityInstance

use of org.camunda.bpm.engine.history.HistoricCaseActivityInstance in project camunda-bpm-platform by camunda.

the class HistoricCaseActivityInstanceTest method testHistoricActivityInstancesAreMarkedTerminatedOnComplete.

@Deployment(resources = { "org/camunda/bpm/engine/test/history/HistoricCaseActivityInstanceTest.oneStageAndOneTaskCaseWithManualActivation.cmmn" })
public void testHistoricActivityInstancesAreMarkedTerminatedOnComplete() {
    // given
    createCaseInstance();
    CaseExecution humanTask = queryCaseExecutionByActivityId("PI_HumanTask_3");
    assertTrue(humanTask.isEnabled());
    CaseExecution stage = queryCaseExecutionByActivityId("PI_Stage_1");
    assertTrue(stage.isEnabled());
    // when
    CaseExecution casePlanExecution = queryCaseExecutionByActivityId("CasePlanModel_1");
    complete(casePlanExecution.getId());
    // then make sure all cases in the lower scope are marked as terminated in history
    HistoricCaseActivityInstance stageInstance = historyService.createHistoricCaseActivityInstanceQuery().caseActivityId("PI_Stage_1").singleResult();
    HistoricCaseActivityInstance taskInstance = historyService.createHistoricCaseActivityInstanceQuery().caseActivityId("PI_HumanTask_3").singleResult();
    assertTrue(stageInstance.isTerminated());
    assertTrue(taskInstance.isTerminated());
}
Also used : CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) HistoricCaseActivityInstance(org.camunda.bpm.engine.history.HistoricCaseActivityInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

HistoricCaseActivityInstance (org.camunda.bpm.engine.history.HistoricCaseActivityInstance)29 Deployment (org.camunda.bpm.engine.test.Deployment)17 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)11 HistoricCaseActivityInstanceQuery (org.camunda.bpm.engine.history.HistoricCaseActivityInstanceQuery)5 Test (org.junit.Test)5 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)3 Task (org.camunda.bpm.engine.task.Task)3 Date (java.util.Date)2 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)2 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)2 Response (com.jayway.restassured.response.Response)1 ArrayList (java.util.ArrayList)1 HistoryService (org.camunda.bpm.engine.HistoryService)1 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)1 HistoricCaseActivityInstanceDto (org.camunda.bpm.engine.rest.dto.history.HistoricCaseActivityInstanceDto)1 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)1 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 InOrder (org.mockito.InOrder)1