Search in sources :

Example 16 with HistoricCaseInstance

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

the class HistoricCaseInstanceTest method testQuerySorting.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn", "org/camunda/bpm/engine/test/api/cmmn/twoTaskCase.cmmn" })
@SuppressWarnings("unchecked")
public void testQuerySorting() {
    String oneCaseInstanceId = createCaseInstanceByKey("oneTaskCase", "oneBusinessKey").getId();
    String twoCaseInstanceId = createCaseInstanceByKey("twoTaskCase", "twoBusinessKey").getId();
    // terminate and close case instances => close time and duration is set
    terminate(oneCaseInstanceId);
    close(oneCaseInstanceId);
    // set time ahead to get different durations
    ClockUtil.setCurrentTime(DateTimeUtil.now().plusHours(1).toDate());
    terminate(twoCaseInstanceId);
    close(twoCaseInstanceId);
    HistoricCaseInstance oneCaseInstance = queryHistoricCaseInstance(oneCaseInstanceId);
    HistoricCaseInstance twoCaseInstance = queryHistoricCaseInstance(twoCaseInstanceId);
    // sort by case instance ids
    String property = "id";
    List<? extends Comparable> sortedList = Arrays.asList(oneCaseInstance.getId(), twoCaseInstance.getId());
    Collections.sort(sortedList);
    List<HistoricCaseInstance> instances = historicQuery().orderByCaseInstanceId().asc().list();
    assertEquals(2, instances.size());
    assertThat(instances, contains(hasProperty(property, equalTo(sortedList.get(0))), hasProperty(property, equalTo(sortedList.get(1)))));
    instances = historicQuery().orderByCaseInstanceId().desc().list();
    assertEquals(2, instances.size());
    assertThat(instances, contains(hasProperty(property, equalTo(sortedList.get(1))), hasProperty(property, equalTo(sortedList.get(0)))));
    // sort by case definition ids
    property = "caseDefinitionId";
    sortedList = Arrays.asList(oneCaseInstance.getCaseDefinitionId(), twoCaseInstance.getCaseDefinitionId());
    Collections.sort(sortedList);
    instances = historicQuery().orderByCaseDefinitionId().asc().list();
    assertEquals(2, instances.size());
    assertThat(instances, contains(hasProperty(property, equalTo(sortedList.get(0))), hasProperty(property, equalTo(sortedList.get(1)))));
    instances = historicQuery().orderByCaseDefinitionId().desc().list();
    assertEquals(2, instances.size());
    assertThat(instances, contains(hasProperty(property, equalTo(sortedList.get(1))), hasProperty(property, equalTo(sortedList.get(0)))));
    // sort by business keys
    property = "businessKey";
    sortedList = Arrays.asList(oneCaseInstance.getBusinessKey(), twoCaseInstance.getBusinessKey());
    Collections.sort(sortedList);
    instances = historicQuery().orderByCaseInstanceBusinessKey().asc().list();
    assertEquals(2, instances.size());
    assertThat(instances, contains(hasProperty(property, equalTo(sortedList.get(0))), hasProperty(property, equalTo(sortedList.get(1)))));
    instances = historicQuery().orderByCaseInstanceBusinessKey().desc().list();
    assertEquals(2, instances.size());
    assertThat(instances, contains(hasProperty(property, equalTo(sortedList.get(1))), hasProperty(property, equalTo(sortedList.get(0)))));
    // sort by create time
    property = "createTime";
    sortedList = Arrays.asList(oneCaseInstance.getCreateTime(), twoCaseInstance.getCreateTime());
    Collections.sort(sortedList);
    instances = historicQuery().orderByCaseInstanceCreateTime().asc().list();
    assertEquals(2, instances.size());
    assertThat(instances, contains(hasProperty(property, equalTo(sortedList.get(0))), hasProperty(property, equalTo(sortedList.get(1)))));
    instances = historicQuery().orderByCaseInstanceCreateTime().desc().list();
    assertEquals(2, instances.size());
    assertThat(instances, contains(hasProperty(property, equalTo(sortedList.get(1))), hasProperty(property, equalTo(sortedList.get(0)))));
    // sort by close time
    property = "closeTime";
    sortedList = Arrays.asList(oneCaseInstance.getCloseTime(), twoCaseInstance.getCloseTime());
    Collections.sort(sortedList);
    instances = historicQuery().orderByCaseInstanceCloseTime().asc().list();
    assertEquals(2, instances.size());
    assertThat(instances, contains(hasProperty(property, equalTo(sortedList.get(0))), hasProperty(property, equalTo(sortedList.get(1)))));
    instances = historicQuery().orderByCaseInstanceCloseTime().desc().list();
    assertEquals(2, instances.size());
    assertThat(instances, contains(hasProperty(property, equalTo(sortedList.get(1))), hasProperty(property, equalTo(sortedList.get(0)))));
    // sort by duration
    property = "durationInMillis";
    sortedList = Arrays.asList(oneCaseInstance.getDurationInMillis(), twoCaseInstance.getDurationInMillis());
    Collections.sort(sortedList);
    instances = historicQuery().orderByCaseInstanceDuration().asc().list();
    assertEquals(2, instances.size());
    assertThat(instances, contains(hasProperty(property, equalTo(sortedList.get(0))), hasProperty(property, equalTo(sortedList.get(1)))));
    instances = historicQuery().orderByCaseInstanceDuration().desc().list();
    assertEquals(2, instances.size());
    assertThat(instances, contains(hasProperty(property, equalTo(sortedList.get(1))), hasProperty(property, equalTo(sortedList.get(0)))));
}
Also used : HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 17 with HistoricCaseInstance

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

the class HistoricCaseInstanceRestServiceQueryTest method testCaseQueryNotClosedAsPost.

@Test
public void testCaseQueryNotClosedAsPost() {
    List<HistoricCaseInstance> mockedHistoricCaseInstances = MockProvider.createMockRunningHistoricCaseInstances();
    HistoricCaseInstanceQuery mockedHistoricCaseInstanceQuery = mock(HistoricCaseInstanceQuery.class);
    when(mockedHistoricCaseInstanceQuery.list()).thenReturn(mockedHistoricCaseInstances);
    when(processEngine.getHistoryService().createHistoricCaseInstanceQuery()).thenReturn(mockedHistoricCaseInstanceQuery);
    Map<String, Boolean> body = new HashMap<String, Boolean>();
    body.put("notClosed", true);
    Response response = given().contentType(POST_JSON_CONTENT_TYPE).body(body).then().expect().statusCode(Status.OK.getStatusCode()).when().post(HISTORIC_CASE_INSTANCE_RESOURCE_URL);
    InOrder inOrder = inOrder(mockedHistoricCaseInstanceQuery);
    inOrder.verify(mockedHistoricCaseInstanceQuery).notClosed();
    inOrder.verify(mockedHistoricCaseInstanceQuery).list();
    String content = response.asString();
    List<String> instances = from(content).getList("");
    Assert.assertEquals(1, instances.size());
    Assert.assertNotNull(instances.get(0));
    String returnedCaseInstanceId = from(content).getString("[0].id");
    String returnedCloseTime = from(content).getString("[0].closeTime");
    Assert.assertEquals(MockProvider.EXAMPLE_CASE_INSTANCE_ID, returnedCaseInstanceId);
    Assert.assertEquals(null, returnedCloseTime);
}
Also used : Response(com.jayway.restassured.response.Response) InOrder(org.mockito.InOrder) HashMap(java.util.HashMap) HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) Matchers.containsString(org.hamcrest.Matchers.containsString) HistoricCaseInstanceQuery(org.camunda.bpm.engine.history.HistoricCaseInstanceQuery) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 18 with HistoricCaseInstance

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

the class MockProvider method createMockHistoricCaseInstance.

public static HistoricCaseInstance createMockHistoricCaseInstance(String tenantId) {
    HistoricCaseInstance mock = mock(HistoricCaseInstance.class);
    when(mock.getId()).thenReturn(EXAMPLE_CASE_INSTANCE_ID);
    when(mock.getBusinessKey()).thenReturn(EXAMPLE_CASE_INSTANCE_BUSINESS_KEY);
    when(mock.getCaseDefinitionId()).thenReturn(EXAMPLE_CASE_DEFINITION_ID);
    when(mock.getCaseDefinitionKey()).thenReturn(EXAMPLE_CASE_DEFINITION_KEY);
    when(mock.getCaseDefinitionName()).thenReturn(EXAMPLE_CASE_DEFINITION_NAME);
    when(mock.getCreateTime()).thenReturn(DateTimeUtil.parseDate(EXAMPLE_HISTORIC_CASE_INSTANCE_CREATE_TIME));
    when(mock.getCloseTime()).thenReturn(DateTimeUtil.parseDate(EXAMPLE_HISTORIC_CASE_INSTANCE_CLOSE_TIME));
    when(mock.getDurationInMillis()).thenReturn(EXAMPLE_HISTORIC_CASE_INSTANCE_DURATION_MILLIS);
    when(mock.getCreateUserId()).thenReturn(EXAMPLE_HISTORIC_CASE_INSTANCE_CREATE_USER_ID);
    when(mock.getSuperCaseInstanceId()).thenReturn(EXAMPLE_HISTORIC_CASE_INSTANCE_SUPER_CASE_INSTANCE_ID);
    when(mock.getSuperProcessInstanceId()).thenReturn(EXAMPLE_HISTORIC_CASE_INSTANCE_SUPER_PROCESS_INSTANCE_ID);
    when(mock.getTenantId()).thenReturn(tenantId);
    when(mock.isActive()).thenReturn(EXAMPLE_HISTORIC_CASE_INSTANCE_IS_ACTIVE);
    when(mock.isCompleted()).thenReturn(EXAMPLE_HISTORIC_CASE_INSTANCE_IS_COMPLETED);
    when(mock.isTerminated()).thenReturn(EXAMPLE_HISTORIC_CASE_INSTANCE_IS_TERMINATED);
    when(mock.isClosed()).thenReturn(EXAMPLE_HISTORIC_CASE_INSTANCE_IS_CLOSED);
    return mock;
}
Also used : HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance)

Example 19 with HistoricCaseInstance

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

the class HistoricCaseInstanceResourceImpl method getHistoricCaseInstance.

public HistoricCaseInstanceDto getHistoricCaseInstance() {
    HistoryService historyService = engine.getHistoryService();
    HistoricCaseInstance instance = historyService.createHistoricCaseInstanceQuery().caseInstanceId(caseInstanceId).singleResult();
    if (instance == null) {
        throw new InvalidRequestException(Status.NOT_FOUND, "Historic case instance with id '" + caseInstanceId + "' does not exist");
    }
    return HistoricCaseInstanceDto.fromHistoricCaseInstance(instance);
}
Also used : HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) HistoryService(org.camunda.bpm.engine.HistoryService) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 20 with HistoricCaseInstance

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

the class MultiTenancyCaseInstanceCmdsTenantCheckTest method closeCaseInstanceDisabledTenantCheck.

@Test
public void closeCaseInstanceDisabledTenantCheck() {
    caseService.completeCaseExecution(caseInstanceId);
    identityService.setAuthentication("user", null, null);
    processEngineConfiguration.setTenantCheckEnabled(false);
    caseService.closeCaseInstance(caseInstanceId);
    identityService.clearAuthentication();
    HistoricCaseInstance historicCaseInstance = getHistoricCaseInstance();
    assertThat(historicCaseInstance, notNullValue());
    assertThat(historicCaseInstance.isClosed(), is(true));
}
Also used : HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) Test(org.junit.Test)

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