// Create a table model
TestTableModel innerModel = new TestTableModel(rowList);
CachedTableModel<Integer> tableModel = new CachedTableModel<Integer>(
innerModel);
assertEquals(rowList.size(), tableModel.getRowCount());
Request lastRequest = null;
// Send a request
Request request1 = new Request(10, 5);
CacheTestCallback callback1 = new CacheTestCallback(10, 5, null);
tableModel.requestRows(request1, callback1);
assertTrue(callback1.isExecuted());
lastRequest = innerModel.getLastRequest();
assertEquals(10, lastRequest.getStartRow());
assertEquals(5, lastRequest.getNumRows());
// Send a request for the same data
Request request2 = new Request(10, 5);
CacheTestCallback callback2 = new CacheTestCallback(10, 5, null);
tableModel.requestRows(request2, callback2);
assertTrue(callback2.isExecuted());
assertEquals(lastRequest, innerModel.getLastRequest());
// Send a request with pre and post caching, but we already have the data
tableModel.setPreCachedRowCount(10);
tableModel.setPostCachedRowCount(10);
Request request3 = new Request(10, 5);
CacheTestCallback callback3 = new CacheTestCallback(10, 5, null);
tableModel.requestRows(request3, callback3);
assertTrue(callback3.isExecuted());
assertEquals(lastRequest, innerModel.getLastRequest());
// Send a request with pre and post caching, but we do not have the data
Request request4 = new Request(25, 5);
CacheTestCallback callback4 = new CacheTestCallback(25, 5, null);
tableModel.requestRows(request4, callback4);
assertTrue(callback4.isExecuted());
assertNotSame(lastRequest, innerModel.getLastRequest());
lastRequest = innerModel.getLastRequest();
assertEquals(15, lastRequest.getStartRow());
assertEquals(25, lastRequest.getNumRows());
// Verify that rows were pre cached
Request request5 = new Request(15, 5);
CacheTestCallback callback5 = new CacheTestCallback(15, 5, null);
tableModel.requestRows(request5, callback5);
assertTrue(callback5.isExecuted());
assertEquals(lastRequest, innerModel.getLastRequest());
// Verify that rows were post cached
Request request6 = new Request(35, 5);
CacheTestCallback callback6 = new CacheTestCallback(35, 5, null);
tableModel.requestRows(request6, callback6);
assertTrue(callback6.isExecuted());
assertEquals(lastRequest, innerModel.getLastRequest());
}