diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventReaderItemReaderTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventReaderItemReaderTests.java index 2cd27be39..60694c7dc 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventReaderItemReaderTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventReaderItemReaderTests.java @@ -10,10 +10,8 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.springframework.batch.item.ExecutionContext; -import org.springframework.batch.item.xml.StaxEventItemReader; import org.springframework.batch.item.xml.domain.Trade; import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; import org.springframework.oxm.Unmarshaller; import org.springframework.util.ClassUtils; @@ -21,33 +19,36 @@ public abstract class AbstractStaxEventReaderItemReaderTests { protected StaxEventItemReader reader = new StaxEventItemReader(); - protected Resource resource = new ClassPathResource(ClassUtils - .addResourcePathToPackagePath(getClass(), "input.xml")); - @Before public void setUp() throws Exception { - - reader.setResource(resource); - reader.setFragmentRootElementName("trade"); - reader.setUnmarshaller(getUnmarshaller()); - reader.afterPropertiesSet(); - - reader.open(new ExecutionContext()); - } @Test public void testRead() throws Exception { + reader.setResource(new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(), "input.xml"))); + reader.open(new ExecutionContext()); Trade result; List results = new ArrayList(); while ((result = reader.read()) != null) { results.add(result); } checkResults(results); + } + @Test + public void testReadNested() throws Exception { + reader.setResource(new ClassPathResource(ClassUtils + .addResourcePathToPackagePath(getClass(), "input-nested.xml"))); + reader.open(new ExecutionContext()); + Trade result; + List results = new ArrayList(); + while ((result = reader.read()) != null) { + results.add(result); + } + checkResults(results); } /** @@ -85,7 +86,4 @@ public abstract class AbstractStaxEventReaderItemReaderTests { reader.close(); } - public void setResource(Resource resource) { - this.resource = resource; - } } diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceUnmarshallingTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceUnmarshallingTests.java index da3de3c03..420009be9 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceUnmarshallingTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceUnmarshallingTests.java @@ -31,17 +31,11 @@ public class Jaxb2NamespaceUnmarshallingTests { @Before public void setUp() throws Exception { - reader.setResource(resource); - reader.setFragmentRootElementName("{urn:org.springframework.batch.io.oxm.domain}trade"); - reader.setUnmarshaller(getUnmarshaller()); - reader.afterPropertiesSet(); - reader.open(new ExecutionContext()); - } @Test diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/domain/trade.xsd b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/domain/trade.xsd index 902fbba34..49241340a 100644 --- a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/domain/trade.xsd +++ b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/domain/trade.xsd @@ -3,6 +3,12 @@ xmlns:tns="urn:org.springframework.batch.io.oxm.domain" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> + + + + + + diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/input-nested.xml b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/input-nested.xml new file mode 100644 index 000000000..86c0ce2a9 --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/xml/input-nested.xml @@ -0,0 +1,23 @@ + + + + + Customer1 + XYZ0001 + 11.39 + 5 + + + Customer2 + XYZ0002 + 72.99 + 2 + + + Customer3 + XYZ0003 + 99.99 + 9 + + +