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)))));
}
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);
}
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;
}
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);
}
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));
}
Aggregations