public void testQueryByAssigneeExcludeSubtasksOrderedAndPaginated() throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
// gonzo has 2 root tasks and 3+2 subtasks assigned
// include subtasks
TaskQuery query = taskService.createTaskQuery().taskAssignee("gonzo").orderByTaskCreateTime().asc();
assertEquals(7, query.count());
assertEquals(1, query.listPage(0, 1).size());
assertEquals(sdf.parse("01/02/2008 02:02:02.000"), query.listPage(0, 1).get(0).getCreateTime());
assertEquals(1, query.listPage(1, 1).size());
assertEquals(sdf.parse("05/02/2008 02:02:02.000"), query.listPage(1, 1).get(0).getCreateTime());
assertEquals(2, query.listPage(0, 2).size());
assertEquals(sdf.parse("01/02/2008 02:02:02.000"), query.listPage(0, 2).get(0).getCreateTime());
assertEquals(sdf.parse("05/02/2008 02:02:02.000"), query.listPage(0, 2).get(1).getCreateTime());
// exclude subtasks
query = taskService.createTaskQuery().taskAssignee("gonzo").excludeSubtasks().orderByTaskCreateTime().desc();
assertEquals(2, query.count());
assertEquals(1, query.listPage(1, 1).size());
assertEquals(sdf.parse("01/02/2008 02:02:02.000"), query.listPage(1, 1).get(0).getCreateTime());
assertEquals(1, query.listPage(0, 1).size());
assertEquals(sdf.parse("05/02/2008 02:02:02.000"), query.listPage(0, 1).get(0).getCreateTime());
// kermit has no root tasks and no subtasks assigned
// include subtasks
query = taskService.createTaskQuery().taskAssignee("kermit").orderByTaskCreateTime().asc();
assertEquals(0, query.count());
assertEquals(0, query.listPage(0, 2).size());
assertNull(query.singleResult());
// exclude subtasks
query = taskService.createTaskQuery().taskAssignee("kermit").excludeSubtasks().orderByTaskCreateTime().desc();
assertEquals(0, query.count());
assertEquals(0, query.listPage(0, 2).size());
assertNull(query.singleResult());
}