assertNull(result);
}
/** Test pagination when filtering is not involved, for StringIdEntity. */
@Test public void testPaginationNoFilteringString() {
Pagination pagination;
PaginatedResults<StringIdEntity> results;
// These entities by default do not have values that get caught by the filter
List<StringIdEntity> entities = createTestEntitiesString(19);
StringIdEntityDao dao = createStringIdEntityDao();
for (StringIdEntity entity : entities) {
dao.insertTestEntity(entity);
}
// The fetch (with no pagination) retrieves everything
results = dao.retrieveTestEntities();
assertFound(results, "entity1", "entity2", "entity3", "entity4", "entity5",
"entity6", "entity7", "entity8", "entity9", "entity10",
"entity11", "entity12", "entity13", "entity14", "entity15",
"entity16", "entity17", "entity18", "entity19");
assertNull(results.getPagination());
// We'll set up pagination at 5 items per page, which will get us 4 pages
pagination = new Pagination(5);
assertPagination(pagination, 1, false, false, false, false, 0, 0);
// The fetch retrieves page 1, and we know there are at least 2 pages
results = dao.retrieveTestEntities(pagination);
assertFound(results, "entity1", "entity2", "entity3", "entity4", "entity5");
assertNotSame(pagination, results.getPagination());
assertPagination(results.getPagination(), 1, true, false, true, false, 2, 5);
// page(5) doesn't exist yet, so we get the largest known page, page 2
pagination = results.getPagination();
results = dao.retrieveTestEntities(pagination.page(5));
assertFound(results, "entity6", "entity7", "entity8", "entity9", "entity10");
assertNotSame(pagination, results.getPagination());
assertPagination(results.getPagination(), 2, true, true, true, false, 3, 10);
// next() retrieves page 3, and we know there are at least 4 pages
pagination = results.getPagination();
results = dao.retrieveTestEntities(pagination.next());
assertFound(results, "entity11", "entity12", "entity13", "entity14", "entity15");
assertNotSame(pagination, results.getPagination());
assertPagination(results.getPagination(), 3, true, true, true, false, 4, 15);
// next() retrieves page 4, and we now know that there are 4 pages total
pagination = results.getPagination();
results = dao.retrieveTestEntities(pagination.next());
assertFound(results, "entity16", "entity17", "entity18", "entity19");
assertNotSame(pagination, results.getPagination());
assertPagination(results.getPagination(), 4, true, true, false, true, 4, 19);
// page(2) exists, so we get back to page 2
pagination = results.getPagination();
results = dao.retrieveTestEntities(pagination.page(2));
assertFound(results, "entity6", "entity7", "entity8", "entity9", "entity10");
assertNotSame(pagination, results.getPagination());
assertPagination(results.getPagination(), 2, true, true, true, true, 4, 19);
// previous() brings us to page 1
pagination = results.getPagination();
results = dao.retrieveTestEntities(pagination.previous());
assertFound(results, "entity1", "entity2", "entity3", "entity4", "entity5");
assertNotSame(pagination, results.getPagination());
assertPagination(results.getPagination(), 1, true, false, true, true, 4, 19);
// previous() again doesn't exist, so we get page 1 again
pagination = results.getPagination();
results = dao.retrieveTestEntities(pagination.previous());
assertFound(results, "entity1", "entity2", "entity3", "entity4", "entity5");
assertNotSame(pagination, results.getPagination());
assertPagination(results.getPagination(), 1, true, false, true, true, 4, 19);
// next() gets us page 2
pagination = results.getPagination();
results = dao.retrieveTestEntities(pagination.next());
assertFound(results, "entity6", "entity7", "entity8", "entity9", "entity10");
assertNotSame(pagination, results.getPagination());
assertPagination(results.getPagination(), 2, true, true, true, true, 4, 19);
// page(0) doesn't exist, so we get page 1
pagination = results.getPagination();
results = dao.retrieveTestEntities(pagination.page(0));
assertFound(results, "entity1", "entity2", "entity3", "entity4", "entity5");
assertNotSame(pagination, results.getPagination());
assertPagination(results.getPagination(), 1, true, false, true, true, 4, 19);
// page(5) doesn't exist, so we get the largest known page
pagination = results.getPagination();
results = dao.retrieveTestEntities(pagination.page(5));
assertFound(results, "entity16", "entity17", "entity18", "entity19");
assertNotSame(pagination, results.getPagination());
assertPagination(results.getPagination(), 4, true, true, false, true, 4, 19);
// page(-1) doesn't exist, so we get page 1
pagination = results.getPagination();
results = dao.retrieveTestEntities(pagination.page(-1));
assertFound(results, "entity1", "entity2", "entity3", "entity4", "entity5");
assertNotSame(pagination, results.getPagination());
assertPagination(results.getPagination(), 1, true, false, true, true, 4, 19);
}