reader.setCurrentItemCount(this.currentItemCount); reader.setSaveState(this.saveState); reader.setStrict(this.strict);
@Test public void testDirectoryResource() throws Exception { FileSystemResource resource = new FileSystemResource("build/data"); resource.getFile().mkdirs(); assertTrue(resource.getFile().isDirectory()); reader.setResource(resource); reader.afterPropertiesSet(); reader.setStrict(false); reader.open(executionContext); assertNull(reader.read()); }
/** * In strict mode, resource must exist at the time reader is opened. */ @Test(expected = ItemStreamException.class) public void testStrictness() throws Exception { Resource resource = new NonExistentResource(); reader.setResource(resource); reader.setStrict(true); reader.afterPropertiesSet(); reader.open(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(); }
@Test public void testNonExistentResource() throws Exception { Resource resource = new NonExistentResource(); reader.setResource(resource); // afterPropertiesSet should only throw an exception if the Resource is // null reader.afterPropertiesSet(); reader.setStrict(false); reader.open(executionContext); assertNull(reader.read()); reader.close(); }
/** * 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(); }
reader.setCurrentItemCount(this.currentItemCount); reader.setSaveState(this.saveState); reader.setStrict(this.strict);