@Deployment(resources={"org/activiti/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();
  processEngineConfiguration.getClock().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());
  List<Task> tasks=taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
  assertEquals(1,tasks.size());
  Date twentyFiveSecsAfterNoon=new Date(noon.getTime() + 25 * 1000);
  processEngineConfiguration.getClock().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());
  assertEquals(0,historyService.createHistoricProcessInstanceQuery().unfinished().count());
  assertEquals(1,historyService.createHistoricProcessInstanceQuery().finished().count());
}
