OPEN - issue BATCH-116: Create XML input/output source which will work directly with StAX parser
http://opensource.atlassian.com/projects/spring/browse/BATCH-116 Added additional code coverage to infrastructure, validation to samples jobs, and integration tests for castor and xstream
This commit is contained in:
@@ -1 +1 @@
|
||||
<?xml version='1.0' encoding='utf-8'?><purchaseOrders xsi:schemaLocation="http://adsj.accenture.com/purchaseorders purchaseorders.xsd" xmlns="http://adsj.accenture.com/purchaseorders" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><order><customer><name>Gladys Kravitz</name><address>Anytown, PA</address><age>34</age><moo>0</moo><poo>0</poo></customer><date>2003-01-07 14:16:00.0 GMT</date><lineItems><lineItem><description>Burnham's Celestial Handbook, Vol 1</description><perUnitOunces>5.0</perUnitOunces><price>21.79</price><quantity>2</quantity></lineItem><lineItem><description>Burnham's Celestial Handbook, Vol 2</description><perUnitOunces>5.0</perUnitOunces><price>19.89</price><quantity>2</quantity></lineItem></lineItems></order><order><customer><name>John Smith</name><address>Chicago, IL</address><age>46</age><moo>0</moo><poo>0</poo></customer><date>2003-01-07 14:16:02.0 GMT</date><lineItems><lineItem><description>XmlBeans in Action</description><perUnitOunces>3.0</perUnitOunces><price>41.29</price><quantity>1</quantity></lineItem><lineItem><description>JSR-173</description><perUnitOunces>1.0</perUnitOunces><price>11.99</price><quantity>5</quantity></lineItem><lineItem><description>Teach Yourself XML in 21 days</description><perUnitOunces>1.0</perUnitOunces><price>35.49</price><quantity>1</quantity></lineItem></lineItems></order><order><customer><name>Peter Newman</name><address>Cleveland, OH</address><age>23</age><moo>0</moo><poo>0</poo></customer><date>2003-01-07 14:16:35.0 GMT</date><lineItems><lineItem><description>Java 6</description><perUnitOunces>2.0</perUnitOunces><price>12.79</price><quantity>3</quantity></lineItem></lineItems></order></purchaseOrders>
|
||||
<?xml version='1.0' encoding='utf-8'?><purchaseOrders xsi:schemaLocation="http://adsj.accenture.com/purchaseorders purchaseorders.xsd" xmlns="http://adsj.accenture.com/purchaseorders" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><order><customer><name>Gladys Kravitz</name><address>Anytown, PA</address><age>34</age><moo>0</moo><poo>0</poo></customer><date>2003-01-07 08:16:00.0 CST</date><lineItems><lineItem><description>Burnham's Celestial Handbook, Vol 1</description><perUnitOunces>5.0</perUnitOunces><price>21.79</price><quantity>2</quantity></lineItem><lineItem><description>Burnham's Celestial Handbook, Vol 2</description><perUnitOunces>5.0</perUnitOunces><price>19.89</price><quantity>2</quantity></lineItem></lineItems></order><order><customer><name>John Smith</name><address>Chicago, IL</address><age>46</age><moo>0</moo><poo>0</poo></customer><date>2003-01-07 08:16:02.0 CST</date><lineItems><lineItem><description>XmlBeans in Action</description><perUnitOunces>3.0</perUnitOunces><price>41.29</price><quantity>1</quantity></lineItem><lineItem><description>JSR-173</description><perUnitOunces>1.0</perUnitOunces><price>11.99</price><quantity>5</quantity></lineItem><lineItem><description>Teach Yourself XML in 21 days</description><perUnitOunces>1.0</perUnitOunces><price>35.49</price><quantity>1</quantity></lineItem></lineItems></order><order><customer><name>Peter Newman</name><address>Cleveland, OH</address><age>23</age><moo>0</moo><poo>0</poo></customer><date>2003-01-07 08:16:35.0 CST</date><lineItems><lineItem><description>Java 6</description><perUnitOunces>2.0</perUnitOunces><price>12.79</price><quantity>3</quantity></lineItem></lineItems></order></purchaseOrders>
|
||||
@@ -125,6 +125,12 @@
|
||||
<artifactId>stax</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xmlunit</groupId>
|
||||
<artifactId>xmlunit</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<trades>
|
||||
<trade>
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0001</isin>
|
||||
<quantity>5</quantity>
|
||||
<price>11.39</price>
|
||||
<customer>Customer1</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0002</isin>
|
||||
<quantity>2</quantity>
|
||||
<price>72.99</price>
|
||||
<customer>Customer2c</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>XYZ0003</isin>
|
||||
<quantity>9</quantity>
|
||||
<price>99.99</price>
|
||||
<customer>Customer3</customer>
|
||||
</trade>
|
||||
</trades>
|
||||
@@ -10,7 +10,7 @@
|
||||
<bean class="org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor">
|
||||
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="jobConfiguration" parent="simpleJob">
|
||||
<property name="steps">
|
||||
<list>
|
||||
@@ -51,7 +51,7 @@
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
@@ -64,7 +64,7 @@
|
||||
<property name="resource" ref="fileLocator" />
|
||||
<property name="tokenizer" ref="fixedFileDescriptor" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="fileInputTemplate2" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource"
|
||||
scope="step">
|
||||
<aop:scoped-proxy />
|
||||
@@ -78,13 +78,13 @@
|
||||
<property name="names" value="ISIN,Quantity,price, CUSTOMER" />
|
||||
<property name="lengths" value="12, 3, 5, 9" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="fixedFileDescriptor2"
|
||||
class="org.springframework.batch.io.file.support.transform.FixedLengthTokenizer">
|
||||
<property name="names" value="Title, FirstName, LastName, Age, Address.AddrLine1, children[0].name, children[1].name" />
|
||||
<property name="lengths" value="5, 15, 20, 5, 10, 10, 10" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="fixedValidator" class="org.springframework.batch.item.validator.SpringValidator">
|
||||
<property name="validator">
|
||||
<bean id="tradeValidator" class="org.springmodules.validation.valang.ValangValidator">
|
||||
@@ -114,16 +114,16 @@
|
||||
<constructor-arg type="java.lang.String"
|
||||
value="data/beanWrapperMapperSampleJob/input/20070122.teststream.ImportTradeDataStep.txt" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="fileLocator2" class="org.springframework.core.io.ClassPathResource">
|
||||
<constructor-arg type="java.lang.String"
|
||||
value="data/beanWrapperMapperSampleJob/input/20070122.teststream.ImportPersonDataStep.txt" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="fieldSetMapper" class="org.springframework.batch.io.file.support.mapping.BeanWrapperFieldSetMapper">
|
||||
<property name="prototypeBeanName" value="trade"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="fieldSetMapper2" class="org.springframework.batch.io.file.support.mapping.BeanWrapperFieldSetMapper">
|
||||
<property name="prototypeBeanName" value="person"/>
|
||||
</bean>
|
||||
@@ -136,5 +136,5 @@
|
||||
|
||||
<!-- register the step scope with the application context -->
|
||||
<bean class="org.springframework.batch.execution.scope.StepScope" />
|
||||
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<bean id="jobConfiguration" parent="simpleJob">
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="tasklet">
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
<property name="itemProvider">
|
||||
@@ -95,5 +95,5 @@
|
||||
|
||||
<!-- register the step scope with the application context -->
|
||||
<bean class="org.springframework.batch.execution.scope.StepScope" />
|
||||
|
||||
|
||||
</beans>
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
@@ -69,13 +69,13 @@
|
||||
{ orderId : ? > 0 AND ? <= 9999999999 : 'Incorrect order ID' : 'error.order.id' }
|
||||
{ orderDate : isFutureDate(?) = FALSE : 'Future date is not allowed' : 'error.order.date.future' }
|
||||
{ totalLines : ? = size(lineItems) : 'Bad count of order lines' : 'error.order.lines.badcount'}
|
||||
|
||||
|
||||
{ customer.registered : customer.businessCustomer = FALSE OR ? = TRUE : 'Business customer must be registered' : 'error.customer.registration'}
|
||||
{ customer.companyName : customer.businessCustomer = FALSE OR ? HAS TEXT : 'Company name for business customer is mandatory' : 'error.customer.companyname'}
|
||||
{ customer.firstName : customer.businessCustomer = TRUE OR ? HAS TEXT : 'Firstname for non-business customer is mandatory' : 'error.customer.firstname'}
|
||||
{ customer.lastName : customer.businessCustomer = TRUE OR ? HAS TEXT : 'Lastname name for non-business customer is mandatory' : 'error.customer.lastname'}
|
||||
{ customer.registrationId : customer.registered = FALSE OR (? > 0 AND ? < 99999999) : 'Incorrect registration ID' : 'error.customer.registrationid'}
|
||||
|
||||
|
||||
{ billingAddress.addressee : ? HAS NO TEXT OR length(?) <= 60 : 'Maximum length for Addressee is 60 characters' : 'error.baddress.addresse.length'}
|
||||
{ billingAddress.addrLine1 : ? HAS TEXT AND length(?) <= 50 : 'Address line1 is mandatory and maximum length for address line1 is 50 characters' : 'error.baddress.addrline1.length'}
|
||||
{ billingAddress.addrLine2 : ? HAS NO TEXT OR length(?) <= 50 : 'Maximum length for address line2 is 50 characters' : 'error.baddress.addrline2.length'}
|
||||
@@ -83,8 +83,8 @@
|
||||
{ billingAddress.zipCode : ? HAS TEXT AND length(?) <= 50 : 'Zipcode is mandatory and maximum length for zipcode is 5 characters' : 'error.baddress.zipcode.length'}
|
||||
{ billingAddress.zipCode : match('[0-9]{5}',?) = TRUE : 'ZipCode must contain exactly 5 digits' : 'error.baddress.zipcode.format'}
|
||||
{ billingAddress.state : (? HAS NO TEXT AND billingAddress.country != 'United States') OR (? HAS TEXT AND length(?) <= 2) : 'Maximum length for state is 2 characters' : 'error.baddress.state.length'}
|
||||
{ billingAddress.country : ? HAS TEXT AND length(?) <= 50 : 'Country is mandatory and maximum length for country is 50 characters' : 'error.baddress.country.length'}
|
||||
|
||||
{ billingAddress.country : ? HAS TEXT AND length(?) <= 50 : 'Country is mandatory and maximum length for country is 50 characters' : 'error.baddress.country.length'}
|
||||
|
||||
{ shippingAddress.addressee : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 60) : 'Addressee is mandatory and maximum length for addressee is 60 characters' : 'error.saddress.addresse.length'}
|
||||
{ shippingAddress.addrLine1 : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 50) : 'Address line1 is mandatory and maximum length for address line1 is 50 characters' : 'error.baddress.addrline1.length'}
|
||||
{ shippingAddress.addrLine2 : shippingAddress IS NULL OR (? HAS NO TEXT OR length(?) <= 50) : 'Maximum length for address line2 is 50 characters' : 'error.baddress.addrline2.length'}
|
||||
@@ -93,14 +93,14 @@
|
||||
{ shippingAddress.zipCode : shippingAddress IS NULL OR (match('[0-9]{5}',?) = TRUE) : 'Zipcode must contain exactly 5 digits' : 'error.baddress.zipcode.format'}
|
||||
{ shippingAddress.state : shippingAddress IS NULL OR ((? HAS NO TEXT AND billingAddress.country != 'United States') OR (? HAS TEXT AND length(?) <= 2)) : 'Maximum length for state is 2 characters' : 'error.baddress.state.length'}
|
||||
{ shippingAddress.country : shippingAddress IS NULL OR (? HAS TEXT AND length(?) <= 50) : 'Country is mandatory and maximum length for country is 50 characters' : 'error.baddress.country.length'}
|
||||
|
||||
|
||||
{ billing.paymentId : ? IN 'VISA','AMEX','ECMC','DCIN','PAYP' : 'Invalid payment type' : 'error.billing.type' }
|
||||
{ billing.paymentDesc : match('[A-Z]{4}-[0-9]{10,11}',?) = TRUE : 'Invalid format of payment description' : 'error.billing.desc' }
|
||||
|
||||
|
||||
{ shipping.shipperId : ? IN 'FEDX', 'UPS', 'DHL', 'DPD' : 'Invalid shipper ID' : 'error.shipping.shipper'}
|
||||
{ shipping.shippingTypeId : ? IN 'STD', 'EXP', 'AMS', 'AME' : 'Invalid shipping type' : 'error.shipping.type' }
|
||||
{ shipping.shippingInfo : ? HAS NO TEXT OR length(?) <= 100 : 'Maximum length for additional shipping info is 100 characters' }
|
||||
|
||||
|
||||
{ lineItems : validateTotalItemsCount(totalItems,?) = TRUE : 'Bad count of total line items' : 'error.lineitems.badcount' }
|
||||
{ lineItems : validateIds(?) = TRUE : 'One or more invalid item IDs' : 'error.lineitems.id' }
|
||||
{ lineItems : validatePrices(?) = TRUE : 'One or more invalid item prices' : 'error.lineitems.price' }
|
||||
@@ -147,10 +147,10 @@
|
||||
<bean id="fileOutputLocator" class="org.springframework.core.io.FileSystemResource">
|
||||
<constructor-arg type="java.lang.String" value="20070122.teststream.multilineOrderStep.TEMP.txt" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean parent="customEditorConfigurer"/>
|
||||
|
||||
<!-- register the step scope with the application context -->
|
||||
<bean class="org.springframework.batch.execution.scope.StepScope" />
|
||||
|
||||
|
||||
</beans>
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
@@ -16,10 +16,17 @@
|
||||
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import org.springframework.batch.sample.AbstractLifecycleSpringContextTests;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLAssert;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
|
||||
|
||||
public class XmlStaxJobFunctionalTests extends AbstractLifecycleSpringContextTests {
|
||||
|
||||
private static final String OUTPUT_FILE = "20070918.testStream.xmlFileStep.output.xml";
|
||||
private static final String EXPECTED_OUTPUT_FILE = "src/main/resources/data/staxJob/output/expected-output.xml";
|
||||
|
||||
// @Override
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[]{"jobs/xmlStaxJob.xml"};
|
||||
@@ -30,21 +37,9 @@ public class XmlStaxJobFunctionalTests extends AbstractLifecycleSpringContextTes
|
||||
*/
|
||||
protected void validatePostConditions() throws Exception {
|
||||
applicationContext.close(); //make sure the output file is closed
|
||||
|
||||
/* TODO compare DOM to the expected output -> does not work as expected yet, fails on correct output
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document expectedOutput = builder.parse(
|
||||
new File("src/main/resources/data/staxJob/input/20070918.testStream.xmlFileStep.output.xml"));
|
||||
|
||||
Document actualOutput = builder.parse(
|
||||
new File("20070918.testStream.xmlFileStep.output.xml"));
|
||||
|
||||
expectedOutput.normalize();
|
||||
actualOutput.normalize();
|
||||
|
||||
assertTrue(expectedOutput.isEqualNode(actualOutput));
|
||||
*/
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
XMLAssert.assertXMLEqual(new FileReader(EXPECTED_OUTPUT_FILE), new FileReader(OUTPUT_FILE));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user