@Deployment( resources = { "org/camunda/bpm/engine/test/history/HistoricTaskInstanceTest.testHistoricTaskInstance.bpmn20.xml" }) public void testHistoricTaskInstanceQueryByFollowUpDate() throws Exception { Calendar otherDate = Calendar.getInstance(); runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest"); // do not find any task instances with follow up date assertEquals(0, taskService.createTaskQuery().followUpDate(otherDate.getTime()).count()); Task task = taskService.createTaskQuery().singleResult(); // set follow-up date on task Date followUpDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/02/2003 01:12:13"); task.setFollowUpDate(followUpDate); taskService.saveTask(task); // test that follow-up date was written to historic database assertEquals( followUpDate, historyService .createHistoricTaskInstanceQuery() .taskId(task.getId()) .singleResult() .getFollowUpDate()); assertEquals( 1, historyService.createHistoricTaskInstanceQuery().taskFollowUpDate(followUpDate).count()); otherDate.setTime(followUpDate); otherDate.add(Calendar.YEAR, 1); assertEquals( 0, historyService .createHistoricTaskInstanceQuery() .taskFollowUpDate(otherDate.getTime()) .count()); assertEquals( 1, historyService .createHistoricTaskInstanceQuery() .taskFollowUpBefore(otherDate.getTime()) .count()); assertEquals( 0, historyService .createHistoricTaskInstanceQuery() .taskFollowUpAfter(otherDate.getTime()) .count()); assertEquals( 0, historyService .createHistoricTaskInstanceQuery() .taskFollowUpAfter(otherDate.getTime()) .taskFollowUpDate(followUpDate) .count()); otherDate.add(Calendar.YEAR, -2); assertEquals( 1, historyService .createHistoricTaskInstanceQuery() .taskFollowUpAfter(otherDate.getTime()) .count()); assertEquals( 0, historyService .createHistoricTaskInstanceQuery() .taskFollowUpBefore(otherDate.getTime()) .count()); assertEquals( followUpDate, historyService .createHistoricTaskInstanceQuery() .taskId(task.getId()) .singleResult() .getFollowUpDate()); assertEquals( 0, historyService .createHistoricTaskInstanceQuery() .taskFollowUpBefore(otherDate.getTime()) .taskFollowUpDate(followUpDate) .count()); taskService.complete(task.getId()); assertEquals( followUpDate, historyService .createHistoricTaskInstanceQuery() .taskId(task.getId()) .singleResult() .getFollowUpDate()); assertEquals( 1, historyService.createHistoricTaskInstanceQuery().taskFollowUpDate(followUpDate).count()); }