@Test public void testNext2() throws Exception{ //one row batch BatchResults batchResults = getBatchResults(createBatch(1, 1), true); assertTrue(batchResults.next()); List<Integer> expectedResult = new ArrayList<Integer>(); expectedResult.add(new Integer(1)); assertEquals(batchResults.getCurrentRow(), expectedResult); assertFalse(batchResults.next()); }
@Test public void testNext3() throws Exception{ //one row batch, multiple batches BatchResults batchResults = getBatchResults(createBatch(1, 1), false); assertTrue(batchResults.next()); assertTrue(batchResults.next()); List<Integer> expectedResult = new ArrayList<Integer>(); expectedResult.add(new Integer(2)); assertEquals(batchResults.getCurrentRow(), expectedResult); }
@Test public void testNext4() throws Exception{ BatchResults batchResults = getBatchResults(createBatch(1, 10), false); int i; for(i=0; i<10; i++) { assertTrue(batchResults.next()); List<Integer> expectedResult = new ArrayList<Integer>(); expectedResult.add(new Integer(i+1)); assertEquals(batchResults.getCurrentRow(), expectedResult); } while(batchResults.next()) { List<Integer> expectedResult = new ArrayList<Integer>(); expectedResult.add(new Integer((i++)+1)); assertEquals(batchResults.getCurrentRow(), expectedResult); } assertFalse(batchResults.next()); }
@Test public void testPrevious3() throws Exception{ //one row batch, multiple batches BatchResults batchResults = getBatchResults(createBatch(1, 1), false); assertFalse(batchResults.previous()); assertTrue(batchResults.next()); assertFalse(batchResults.previous()); while(batchResults.next()) { } assertTrue(batchResults.previous()); while(batchResults.previous()) { } batchResults.next(); batchResults.next(); batchResults.next(); batchResults.previous(); List<Integer> expectedResult = new ArrayList<Integer>(); expectedResult.add(new Integer(2)); assertEquals(expectedResult, batchResults.getCurrentRow()); }
@Test public void testPrevious2() throws Exception{ //one row batch BatchResults batchResults = getBatchResults(createBatch(1, 1), true); assertTrue(batchResults.next()); assertFalse(batchResults.previous()); List<Integer> expectedResult = new ArrayList<Integer>(); expectedResult.add(new Integer(1)); while(batchResults.next()) { } assertTrue(batchResults.previous()); assertEquals(batchResults.getCurrentRow(), expectedResult); }
@Test public void testGetCurrentRow2() throws Exception{ BatchResults batchResults = getBatchResults(createBatch(1, 10), false); assertNull(batchResults.getCurrentRow()); batchResults.next(); List<Integer> expectedResult = new ArrayList<Integer>(); expectedResult.add(new Integer(1)); assertEquals(batchResults.getCurrentRow(), expectedResult); }
@Test public void testPrevious4() throws Exception{ BatchResults batchResults = getBatchResults(createBatch(1, 10), false); int i; for(i=0; i<=10; i++) { assertTrue(batchResults.next()); } for(i=10; i>0; i--) { batchResults.previous(); List<Integer> expectedResult = new ArrayList<Integer>(); expectedResult.add(new Integer(i)); assertEquals(batchResults.getCurrentRow(), expectedResult); } }
@Test public void testCurrentRowNumber() throws Exception { BatchResults batchResults = getBatchResults(createBatch(1, 1), true); assertEquals(0, batchResults.getCurrentRowNumber()); batchResults.next(); assertEquals(1, batchResults.getCurrentRowNumber()); batchResults.next(); assertEquals(2, batchResults.getCurrentRowNumber()); assertFalse(batchResults.next()); assertEquals(2, batchResults.getCurrentRowNumber()); }
@Test public void testNext1() throws Exception{ //empty batch BatchResults batchResults = getBatchResults(createEmptyBatch(), true); assertFalse(batchResults.next()); }
@Test public void testHasPrevious2() throws Exception{ //one row batch BatchResults batchResults = getBatchResults(createBatch(1, 1), true); assertFalse(batchResults.hasPrevious()); batchResults.next(); assertFalse(batchResults.hasPrevious()); batchResults.next(); assertTrue(batchResults.hasPrevious()); }
@Test public void testGetCurrentRow1() throws Exception{ //empty batch BatchResults batchResults = getBatchResults(createEmptyBatch(), true); assertNull(batchResults.getCurrentRow()); batchResults.next(); assertNull(batchResults.getCurrentRow()); }
@Test(expected=SQLException.class) public void testSetException() throws Exception { BatchResults batchResults = getBatchResults(createBatch(1, 1), false); MockBatchFetcher batchFetcher = new MockBatchFetcher(); batchResults.setBatchFetcher(batchFetcher); batchFetcher.throwException(); batchResults.next(); batchResults.hasNext(); }
@Test public void testBatching() throws Exception { BatchResults batchResults = getBatchResults(createBatch(1, 10), false); MockBatchFetcher batchFetcher = new MockBatchFetcher(60); batchResults.setBatchFetcher(batchFetcher); for(int i=0; i<45; i++) { assertTrue(batchResults.next()); } for(int i=0; i<44; i++) { assertTrue(batchResults.previous()); assertEquals(new Integer(44 - i), batchResults.getCurrentRow().get(0)); } // verify batch calls checkResults(new int[] { // going forwards - end > begin 11, 21, 31, 41, // going backwards - begin > end // last 3 batches were saved, only need the first 2 again 20, 10, }, batchFetcher.batchCalls); assertTrue(batchResults.absolute(50)); assertEquals(new Integer(50), batchResults.getCurrentRow().get(0)); }