Add nested XML to integration tests

This commit is contained in:
Dave Syer
2011-01-14 09:40:40 +00:00
parent 72dac03008
commit 9c187e0e3a
4 changed files with 43 additions and 22 deletions

View File

@@ -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<Trade> reader = new StaxEventItemReader<Trade>();
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<Trade> results = new ArrayList<Trade>();
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<Trade> results = new ArrayList<Trade>();
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;
}
}

View File

@@ -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

View File

@@ -3,6 +3,12 @@
xmlns:tns="urn:org.springframework.batch.io.oxm.domain" xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="records">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="1"><xs:element name="trades"/></xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="trades">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element name="trade" type="tns:trade"/></xs:choice>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<records>
<trades>
<trade>
<customer>Customer1</customer>
<isin>XYZ0001</isin>
<price>11.39</price>
<quantity>5</quantity>
</trade>
<trade>
<customer>Customer2</customer>
<isin>XYZ0002</isin>
<price>72.99</price>
<quantity>2</quantity>
</trade>
<trade>
<customer>Customer3</customer>
<isin>XYZ0003</isin>
<price>99.99</price>
<quantity>9</quantity>
</trade>
</trades>
</records>