BATCH-734:Merged fixes into 1.1 branch.

This commit is contained in:
lucasward
2008-08-14 15:32:34 +00:00
parent 17e87e0f2c
commit 6cf8a58f26
10 changed files with 55 additions and 22 deletions

View File

@@ -206,7 +206,6 @@ public class FlatFileItemReader extends AbstractBufferedItemReaderItemStream imp
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(resource, "Input resource must not be null");
Assert.notNull(fieldSetMapper, "FieldSetMapper must not be null.");
}
@@ -223,6 +222,7 @@ public class FlatFileItemReader extends AbstractBufferedItemReaderItemStream imp
}
protected void doOpen() throws Exception {
Assert.notNull(resource, "Input Resource must not be null");
Assert.state(resource.exists(), "Resource must exist: [" + resource + "]");
log.debug("Opening flat file for reading: " + resource);

View File

@@ -109,7 +109,6 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception {
Assert.notNull(resource, "The resource must be set");
Assert.notNull(fieldSetCreator, "A FieldSetCreator must be provided.");
}
@@ -238,6 +237,8 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I
*/
public void open(ExecutionContext executionContext) throws ItemStreamException {
Assert.notNull(resource, "The resource must be set");
if(!getOutputState().isInitialized()){
doOpen(executionContext);
}

View File

@@ -16,7 +16,6 @@ import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.ResetFailedException;
import org.springframework.batch.item.UnexpectedInputException;
import org.springframework.batch.item.util.ExecutionContextUserSupport;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -34,8 +33,7 @@ import org.springframework.util.ClassUtils;
*
* @author Robert Kasanicky
*/
public class MultiResourceItemReader extends ExecutionContextUserSupport implements ItemReader, ItemStream,
InitializingBean {
public class MultiResourceItemReader extends ExecutionContextUserSupport implements ItemReader, ItemStream {
/**
* Unique object instance that marks resource boundaries in the item buffer
@@ -199,6 +197,9 @@ public class MultiResourceItemReader extends ExecutionContextUserSupport impleme
*/
public void open(ExecutionContext executionContext) throws ItemStreamException {
Assert.notEmpty(resources, "There must be at least one input resource");
Assert.notNull(delegate, "Delegate must not be null");
Arrays.sort(resources, comparator);
index.open(executionContext);
@@ -234,10 +235,6 @@ public class MultiResourceItemReader extends ExecutionContextUserSupport impleme
this.delegate = delegate;
}
public void afterPropertiesSet() throws Exception {
Assert.notEmpty(resources, "There must be at least one input resource");
}
/**
* Set the boolean indicating whether or not state should be saved in the
* provided {@link ExecutionContext} during the {@link ItemStream} call to

View File

@@ -79,7 +79,6 @@ public class StaxEventItemReader extends AbstractBufferedItemReaderItemStream im
* @throws IllegalStateException if the Resource does not exist.
*/
public void afterPropertiesSet() throws Exception {
Assert.notNull(resource, "The Resource must not be null.");
Assert.notNull(eventReaderDeserializer, "The FragmentDeserializer must not be null.");
Assert.hasLength(fragmentRootElementName, "The FragmentRootElementName must not be null");
}
@@ -135,6 +134,7 @@ public class StaxEventItemReader extends AbstractBufferedItemReaderItemStream im
}
protected void doOpen() throws Exception {
Assert.notNull(resource, "The Resource must not be null.");
Assert.state(resource.exists(), "Input resource does not exist: [" + resource + "]");
inputStream = resource.getInputStream();

View File

@@ -244,7 +244,6 @@ public class StaxEventItemWriter extends ExecutionContextUserSupport implements
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception {
Assert.notNull(resource);
Assert.notNull(serializer);
}
@@ -255,6 +254,8 @@ public class StaxEventItemWriter extends ExecutionContextUserSupport implements
*/
public void open(ExecutionContext executionContext) {
Assert.notNull(resource);
long startAtPosition = 0;
// if restart data is provided, restart from provided offset

View File

@@ -152,6 +152,26 @@ public class FlatFileItemReaderBasicTests extends TestCase {
assertTrue(contains(e.getMessage(), "open"));
}
}
public void testResourceUnavailableAfterPropertiesSet() throws Exception{
itemReader.setResource(null);
itemReader.afterPropertiesSet();
//no exception should be thrown
}
public void testNullResourceInOpen() throws Exception{
itemReader.setResource(null);
try{
itemReader.open(new ExecutionContext());
fail();
}
catch(Exception ex){
//expected
}
}
public void testCloseBeforeOpen() throws Exception {
itemReader = new FlatFileItemReader();

View File

@@ -43,7 +43,6 @@ public class MultiResourceItemReaderFlatFileTests extends
}
});
multiReader.afterPropertiesSet();
return multiReader;
}
@@ -53,7 +52,6 @@ public class MultiResourceItemReaderFlatFileTests extends
multiReader.close(new ExecutionContext());
multiReader.setResources(new Resource[] { new ByteArrayResource(""
.getBytes()) });
multiReader.afterPropertiesSet();
multiReader.open(new ExecutionContext());
}

View File

@@ -45,7 +45,6 @@ public class MultiResourceItemReaderIntegrationTests extends TestCase {
return 0; // do not change ordering
}});
tested.setResources(new Resource[] { r1, r2, r3, r4, r5 });
tested.afterPropertiesSet();
}
/**
@@ -182,5 +181,29 @@ public class MultiResourceItemReaderIntegrationTests extends TestCase {
return result == null ? null : ((FieldSet) result).readString(0);
}
public void testNullResourceInOpen() throws Exception{
tested.setResources(null);
try{
tested.open(new ExecutionContext());
fail();
}
catch(Exception ex){
//expected
}
}
public void testNullDelegateInOpen() throws Exception{
tested.setDelegate(null);
try{
tested.open(new ExecutionContext());
fail();
}
catch(Exception ex){
//expected
}
}
}

View File

@@ -56,7 +56,6 @@ public class MultiResourceItemReaderXmlTests extends CommonItemStreamItemReaderT
return 0; // preserve original ordering
}
});
multiReader.afterPropertiesSet();
return multiReader;
}
@@ -66,7 +65,6 @@ public class MultiResourceItemReaderXmlTests extends CommonItemStreamItemReaderT
multiReader.close(new ExecutionContext());
multiReader.setResources(new Resource[] { new ByteArrayResource("<foos />"
.getBytes()) });
multiReader.afterPropertiesSet();
multiReader.open(new ExecutionContext());
}

View File

@@ -51,12 +51,7 @@ public class StaxEventItemReaderTests extends TestCase {
public void testAfterPropertesSetException() throws Exception {
source.setResource(null);
try {
source.afterPropertiesSet();
fail();
} catch (IllegalArgumentException e) {
// expected;
}
source.afterPropertiesSet();
source = createNewInputSouce();
source.setFragmentRootElementName("");