use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class HistoricProcessInstanceTest method testHistoricProcInstExecutedActivityWithTwoProcInsts.
@Test
public void testHistoricProcInstExecutedActivityWithTwoProcInsts() {
// given
BpmnModelInstance model = Bpmn.createExecutableProcess("proc").startEvent().endEvent().done();
deployment(model);
Calendar now = Calendar.getInstance();
Calendar hourBeforeNow = (Calendar) now.clone();
hourBeforeNow.add(Calendar.HOUR, -1);
ClockUtil.setCurrentTime(hourBeforeNow.getTime());
runtimeService.startProcessInstanceByKey("proc");
ClockUtil.setCurrentTime(now.getTime());
runtimeService.startProcessInstanceByKey("proc");
// when query execute activity between now and an hour ago
List<HistoricProcessInstance> list = historyService.createHistoricProcessInstanceQuery().executedActivityAfter(hourBeforeNow.getTime()).executedActivityBefore(now.getTime()).list();
// then two historic process instance have to be returned
assertEquals(2, list.size());
// when query execute activity after an half hour before now
Calendar halfHour = (Calendar) now.clone();
halfHour.add(Calendar.MINUTE, -30);
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().executedActivityAfter(halfHour.getTime()).singleResult();
// then only the latest historic process instance is returned
assertNotNull(historicProcessInstance);
}
use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class HistoricProcessInstanceTest method testQueryByCaseInstanceId.
@Deployment(resources = { "org/camunda/bpm/engine/test/history/HistoricProcessInstanceTest.testQueryByCaseInstanceId.cmmn", "org/camunda/bpm/engine/test/history/HistoricProcessInstanceTest.testQueryByCaseInstanceId.bpmn20.xml" })
public void testQueryByCaseInstanceId() {
// given
String caseInstanceId = caseService.withCaseDefinitionByKey("case").create().getId();
// then
HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery();
query.caseInstanceId(caseInstanceId);
assertEquals(1, query.count());
assertEquals(1, query.list().size());
HistoricProcessInstance historicProcessInstance = query.singleResult();
assertNotNull(historicProcessInstance);
assertNull(historicProcessInstance.getEndTime());
assertEquals(caseInstanceId, historicProcessInstance.getCaseInstanceId());
// complete existing user task -> completes the process instance
String taskId = taskService.createTaskQuery().caseInstanceId(caseInstanceId).singleResult().getId();
taskService.complete(taskId);
// the completed historic process instance is still associated with the
// case instance id
assertEquals(1, query.count());
assertEquals(1, query.list().size());
historicProcessInstance = query.singleResult();
assertNotNull(historicProcessInstance);
assertNotNull(historicProcessInstance.getEndTime());
assertEquals(caseInstanceId, historicProcessInstance.getCaseInstanceId());
}
use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class HistoricProcessInstanceTest method testHistoricDataCreatedForProcessExecution.
@Deployment(resources = { "org/camunda/bpm/engine/test/history/oneTaskProcess.bpmn20.xml" })
public void testHistoricDataCreatedForProcessExecution() {
Calendar calendar = new GregorianCalendar();
calendar.set(Calendar.YEAR, 2010);
calendar.set(Calendar.MONTH, 8);
calendar.set(Calendar.DAY_OF_MONTH, 30);
calendar.set(Calendar.HOUR_OF_DAY, 12);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
Date noon = calendar.getTime();
ClockUtil.setCurrentTime(noon);
final ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", "myBusinessKey");
assertEquals(1, historyService.createHistoricProcessInstanceQuery().unfinished().count());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().finished().count());
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(historicProcessInstance);
assertEquals(processInstance.getId(), historicProcessInstance.getId());
assertEquals(processInstance.getBusinessKey(), historicProcessInstance.getBusinessKey());
assertEquals(processInstance.getProcessDefinitionId(), historicProcessInstance.getProcessDefinitionId());
assertEquals(noon, historicProcessInstance.getStartTime());
assertNull(historicProcessInstance.getEndTime());
assertNull(historicProcessInstance.getDurationInMillis());
assertNull(historicProcessInstance.getCaseInstanceId());
List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
assertEquals(1, tasks.size());
// in this test scenario we assume that 25 seconds after the process start, the
// user completes the task (yes! he must be almost as fast as me)
Date twentyFiveSecsAfterNoon = new Date(noon.getTime() + 25 * 1000);
ClockUtil.setCurrentTime(twentyFiveSecsAfterNoon);
taskService.complete(tasks.get(0).getId());
historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(historicProcessInstance);
assertEquals(processInstance.getId(), historicProcessInstance.getId());
assertEquals(processInstance.getProcessDefinitionId(), historicProcessInstance.getProcessDefinitionId());
assertEquals(noon, historicProcessInstance.getStartTime());
assertEquals(twentyFiveSecsAfterNoon, historicProcessInstance.getEndTime());
assertEquals(new Long(25 * 1000), historicProcessInstance.getDurationInMillis());
assertTrue(((HistoricProcessInstanceEventEntity) historicProcessInstance).getDurationRaw() >= 25000);
assertNull(historicProcessInstance.getCaseInstanceId());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().unfinished().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().finished().count());
runtimeService.startProcessInstanceByKey("oneTaskProcess", "myBusinessKey");
assertEquals(1, historyService.createHistoricProcessInstanceQuery().finished().count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().unfinished().count());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().finished().unfinished().count());
}
use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class HistoricProcessInstanceTest method testDeleteProcessInstanceHistoryCreated.
@Deployment(resources = { "org/camunda/bpm/engine/test/history/oneTaskProcess.bpmn20.xml" })
public void testDeleteProcessInstanceHistoryCreated() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertNotNull(processInstance);
// delete process instance should not delete the history
runtimeService.deleteProcessInstance(processInstance.getId(), "cancel");
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(historicProcessInstance.getEndTime());
}
use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class HistoricProcessInstanceTest method testQueryByExecutedActivityIdInAndProcessDefinitionKey.
@Test
public void testQueryByExecutedActivityIdInAndProcessDefinitionKey() {
// given
deployment(ProcessModels.ONE_TASK_PROCESS);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process");
Task task = taskService.createTaskQuery().singleResult();
taskService.complete(task.getId());
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processDefinitionKey("Process").executedActivityIdIn("userTask").singleResult();
// then
assertNotNull(historicProcessInstance);
assertEquals(processInstance.getId(), historicProcessInstance.getId());
}
Aggregations