@Override protected void pointToEmptyInput(ItemReader<Foo> tested) throws Exception { MultiResourceItemReader<Foo> multiReader = (MultiResourceItemReader<Foo>) tested; multiReader.close(); multiReader.setResources(new Resource[] { new ByteArrayResource("".getBytes()) }); multiReader.open(new ExecutionContext()); } }
@Override protected void pointToEmptyInput(ItemReader<Foo> tested) throws Exception { MultiResourceItemReader<Foo> multiReader = (MultiResourceItemReader<Foo>) tested; multiReader.close(); multiReader.setResources(new Resource[] { new ByteArrayResource("<foos />" .getBytes()) }); multiReader.open(new ExecutionContext()); }
@Override protected void pointToEmptyInput(ItemReader<Foo> tested) throws Exception { MultiResourceItemReader<Foo> multiReader = (MultiResourceItemReader<Foo>) tested; multiReader.close(); multiReader.setResources(new Resource[] { new ByteArrayResource("" .getBytes()) }); multiReader.open(new ExecutionContext()); }
/** * Missing resource is OK. */ @Test public void testNonExistentResources() throws Exception { tested.setResources(new Resource[] { new FileSystemResource("no/such/file.txt") }); itemReader.setStrict(false); tested.open(new ExecutionContext()); assertNull(tested.read()); tested.close(); }
/** * Directory resource behaves as if it was empty. */ @Test public void testDirectoryResources() throws Exception { FileSystemResource resource = new FileSystemResource("build/data"); resource.getFile().mkdirs(); assertTrue(resource.getFile().isDirectory()); tested.setResources(new Resource[] { resource }); itemReader.setStrict(false); tested.open(new ExecutionContext()); assertNull(tested.read()); tested.close(); }
/** * Empty resource list is OK. */ @Test public void testNoResourcesFound() throws Exception { tested.setResources(new Resource[] {}); tested.open(new ExecutionContext()); assertNull(tested.read()); tested.close(); }
/** * E.g. when using the reader in the processing phase reading might not have been attempted at all before the job * crashed (BATCH-1798). */ @Test public void testRestartAfterFailureWithoutRead() throws Exception { // save reader state without calling read tested.open(ctx); tested.update(ctx); tested.close(); // restart should work OK tested.open(ctx); assertEquals("1", tested.read()); }
@Test public void testRestartWhenStateNotSaved() throws Exception { tested.setSaveState(false); tested.open(ctx); assertEquals("1", tested.read()); tested.update(ctx); assertEquals("2", tested.read()); assertEquals("3", tested.read()); tested.close(); tested.open(ctx); assertEquals("1", tested.read()); }
/** * Test {@link org.springframework.batch.item.ItemStream} lifecycle symmetry */ @Test public void testNonExistentResourcesItemStreamLifecycle() throws Exception { ItemStreamReaderImpl delegate = new ItemStreamReaderImpl(); tested.setDelegate(delegate); tested.setResources(new Resource[] { }); itemReader.setStrict(false); tested.open(new ExecutionContext()); assertNull(tested.read()); assertFalse(delegate.openCalled); assertFalse(delegate.closeCalled); assertFalse(delegate.updateCalled); tested.close(); }
/** * Read input from start to end. */ @Test public void testRead() throws Exception { tested.open(ctx); assertValueAndResource(r1, "1"); assertValueAndResource(r1, "2"); assertValueAndResource(r1, "3"); assertValueAndResource(r2, "4"); assertValueAndResource(r2, "5"); assertValueAndResource(r4, "6"); assertValueAndResource(r5, "7"); assertValueAndResource(r5, "8"); assertEquals(null, tested.read()); tested.close(); }
/** * Read input from start to end. */ @Test public void testRead() throws Exception { tested.open(ctx); assertEquals("1", tested.read()); assertEquals("2", tested.read()); assertEquals("3", tested.read()); assertEquals("4", tested.read()); assertEquals("5", tested.read()); assertEquals("6", tested.read()); assertEquals("7", tested.read()); assertEquals("8", tested.read()); assertEquals(null, tested.read()); tested.close(); }
/** * Restore from saved state. */ @Test public void testRestart() throws Exception { tested.open(ctx); assertEquals("1", tested.read()); assertEquals("2", tested.read()); assertEquals("3", tested.read()); assertEquals("4", tested.read()); tested.update(ctx); assertEquals("5", tested.read()); assertEquals("6", tested.read()); tested.close(); tested.open(ctx); assertEquals("5", tested.read()); assertEquals("6", tested.read()); assertEquals("7", tested.read()); assertEquals("8", tested.read()); assertEquals(null, tested.read()); }
@Test public void testGetCurrentResource() throws Exception { tested.open(ctx); assertEquals("1", tested.read()); assertSame(r1, tested.getCurrentResource()); assertEquals("2", tested.read()); assertSame(r1, tested.getCurrentResource()); assertEquals("3", tested.read()); assertSame(r1, tested.getCurrentResource()); assertEquals("4", tested.read()); assertSame(r2, tested.getCurrentResource()); assertEquals("5", tested.read()); assertSame(r2, tested.getCurrentResource()); assertEquals("6", tested.read()); assertSame(r4, tested.getCurrentResource()); assertEquals("7", tested.read()); assertSame(r5, tested.getCurrentResource()); assertEquals("8", tested.read()); assertSame(r5, tested.getCurrentResource()); assertEquals(null, tested.read()); assertSame(null, tested.getCurrentResource()); tested.close(); }