// Create a table model
TestTableModel innerModel = new TestTableModel(rowList);
CachedTableModel<List<Object>> tableModel = new CachedTableModel<List<Object>>(innerModel);
assertEquals(rowList.size(), tableModel.getRowCount());
Request lastRequest = null;
// Send a request
Request request1 = new Request(10, 5);
TestCallback<List<Object>> callback1 = new TestCallback<List<Object>>(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);
TestCallback<List<Object>> callback2 = new TestCallback<List<Object>>(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);
TestCallback<List<Object>> callback3 = new TestCallback<List<Object>>(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);
TestCallback<List<Object>> callback4 = new TestCallback<List<Object>>(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);
TestCallback<List<Object>> callback5 = new TestCallback<List<Object>>(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);
TestCallback<List<Object>> callback6 = new TestCallback<List<Object>>(35, 5, null);
tableModel.requestRows(request6, callback6);
assertTrue(callback6.isExecuted());
assertEquals(lastRequest, innerModel.getLastRequest());
}