Add nested XML to integration tests
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user