Search in sources :

Example 11 with HistoricCaseInstance

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

the class HistoricCaseInstanceTest method testCreateUser.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/emptyStageCase.cmmn" })
public void testCreateUser() {
    String userId = "test";
    identityService.setAuthenticatedUserId(userId);
    String caseInstanceId = createCaseInstance().getId();
    HistoricCaseInstance historicCaseInstance = queryHistoricCaseInstance(caseInstanceId);
    assertEquals(userId, historicCaseInstance.getCreateUserId());
    assertCount(1, historicQuery().createdBy(userId));
    identityService.setAuthenticatedUserId(null);
}
Also used : HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 12 with HistoricCaseInstance

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

the class HistoricCaseInstanceTest method testCaseInstanceStates.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/emptyStageWithManualActivationCase.cmmn" })
public void testCaseInstanceStates() {
    String caseInstanceId = createCaseInstance().getId();
    HistoricCaseInstance historicCaseInstance = queryHistoricCaseInstance(caseInstanceId);
    assertTrue(historicCaseInstance.isActive());
    assertCount(1, historicQuery().active());
    assertCount(1, historicQuery().notClosed());
    // start empty stage to complete case instance
    String stageExecutionId = queryCaseExecutionByActivityId("PI_Stage_1").getId();
    manualStart(stageExecutionId);
    historicCaseInstance = queryHistoricCaseInstance(caseInstanceId);
    assertTrue(historicCaseInstance.isCompleted());
    assertCount(1, historicQuery().completed());
    assertCount(1, historicQuery().notClosed());
    // reactive and terminate case instance
    reactivate(caseInstanceId);
    terminate(caseInstanceId);
    historicCaseInstance = queryHistoricCaseInstance(caseInstanceId);
    assertTrue(historicCaseInstance.isTerminated());
    assertCount(1, historicQuery().terminated());
    assertCount(1, historicQuery().notClosed());
    // reactive and suspend case instance
    reactivate(caseInstanceId);
    suspend(caseInstanceId);
    historicCaseInstance = queryHistoricCaseInstance(caseInstanceId);
    // not public API
    assertTrue(((HistoricCaseInstanceEntity) historicCaseInstance).isSuspended());
    // assertCount(1, historicQuery().suspended());
    assertCount(1, historicQuery().notClosed());
    // close case instance
    close(caseInstanceId);
    historicCaseInstance = queryHistoricCaseInstance(caseInstanceId);
    assertTrue(historicCaseInstance.isClosed());
    assertCount(1, historicQuery().closed());
    assertCount(0, historicQuery().notClosed());
}
Also used : HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 13 with HistoricCaseInstance

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

the class HistoricCaseInstanceTest method testHistoricCaseInstanceDates.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/emptyStageWithManualActivationCase.cmmn" })
public void testHistoricCaseInstanceDates() {
    // create test dates
    long duration = 72 * 3600 * 1000;
    Date created = ClockUtil.getCurrentTime();
    Date closed = new Date(created.getTime() + duration);
    // create instance
    ClockUtil.setCurrentTime(created);
    String caseInstanceId = createCaseInstance().getId();
    terminate(caseInstanceId);
    // close instance
    ClockUtil.setCurrentTime(closed);
    close(caseInstanceId);
    HistoricCaseInstance historicCaseInstance = queryHistoricCaseInstance(caseInstanceId);
    // read historic dates ignoring milliseconds
    Date createTime = historicCaseInstance.getCreateTime();
    Date closeTime = historicCaseInstance.getCloseTime();
    Long durationInMillis = historicCaseInstance.getDurationInMillis();
    assertDateSimilar(created, createTime);
    assertDateSimilar(closed, closeTime);
    // test that duration is as expected with a maximal difference of one second
    assertTrue(durationInMillis >= duration);
    assertTrue(durationInMillis < duration + 1000);
    // test queries
    Date beforeCreate = new Date(created.getTime() - 3600 * 1000);
    Date afterClose = new Date(closed.getTime() + 3600 * 1000);
    assertCount(1, historicQuery().createdAfter(beforeCreate));
    assertCount(0, historicQuery().createdAfter(closed));
    assertCount(0, historicQuery().createdBefore(beforeCreate));
    assertCount(1, historicQuery().createdBefore(closed));
    assertCount(0, historicQuery().createdBefore(beforeCreate).createdAfter(closed));
    assertCount(1, historicQuery().closedAfter(created));
    assertCount(0, historicQuery().closedAfter(afterClose));
    assertCount(0, historicQuery().closedBefore(created));
    assertCount(1, historicQuery().closedBefore(afterClose));
    assertCount(0, historicQuery().closedBefore(created).closedAfter(afterClose));
    assertCount(1, historicQuery().closedBefore(afterClose).closedAfter(created));
}
Also used : HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 14 with HistoricCaseInstance

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

the class HistoricCaseInstanceTest method testRetrieveCaseDefinitionName.

@Deployment(resources = "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn")
public void testRetrieveCaseDefinitionName() {
    // given
    String id = createCaseInstance("oneTaskCase").getId();
    // when
    HistoricCaseInstance caseInstance = historyService.createHistoricCaseInstanceQuery().caseInstanceId(id).singleResult();
    // then
    assertEquals("One Task Case", caseInstance.getCaseDefinitionName());
}
Also used : HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 15 with HistoricCaseInstance

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

the class HistoricCaseInstanceTest method queryHistoricCaseInstance.

protected HistoricCaseInstance queryHistoricCaseInstance(String caseInstanceId) {
    HistoricCaseInstance historicCaseInstance = historicQuery().caseInstanceId(caseInstanceId).singleResult();
    assertNotNull(historicCaseInstance);
    return historicCaseInstance;
}
Also used : HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance)

Aggregations

HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)30 Deployment (org.camunda.bpm.engine.test.Deployment)14 HistoricCaseInstanceQuery (org.camunda.bpm.engine.history.HistoricCaseInstanceQuery)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 HistoricDecisionInstance (org.camunda.bpm.engine.history.HistoricDecisionInstance)3 HistoricIncident (org.camunda.bpm.engine.history.HistoricIncident)3 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)3 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)3 HistoricIncidentEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity)3 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)3 After (org.junit.After)3 Response (com.jayway.restassured.response.Response)2 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)2 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 InOrder (org.mockito.InOrder)2 HashMap (java.util.HashMap)1 HistoryService (org.camunda.bpm.engine.HistoryService)1