From 8af93004991af15b0d030e864cfa9d6c3a3de4b4 Mon Sep 17 00:00:00 2001 From: lucasward Date: Wed, 26 Sep 2007 00:37:32 +0000 Subject: [PATCH] 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 --- samples/20070122.testStream.xmlFileStep.xml | 2 +- samples/pom.xml | 6 ++ .../data/staxJob/output/expected-output.xml | 57 +++++++++++++++++++ .../jobs/beanWrapperMapperSampleJob.xml | 18 +++--- .../resources/jobs/fixedLengthImportJob.xml | 4 +- .../main/resources/jobs/multilineOrderJob.xml | 20 +++---- .../src/main/resources/jobs/tradeJobIo.xml | 2 +- .../sample/XmlStaxJobFunctionalTests.java | 25 ++++---- 8 files changed, 96 insertions(+), 38 deletions(-) create mode 100644 samples/src/main/resources/data/staxJob/output/expected-output.xml diff --git a/samples/20070122.testStream.xmlFileStep.xml b/samples/20070122.testStream.xmlFileStep.xml index 13e91dde8..e698f4395 100644 --- a/samples/20070122.testStream.xmlFileStep.xml +++ b/samples/20070122.testStream.xmlFileStep.xml @@ -1 +1 @@ -Gladys Kravitz
Anytown, PA
3400
2003-01-07 14:16:00.0 GMTBurnham's Celestial Handbook, Vol 15.021.792Burnham's Celestial Handbook, Vol 25.019.892
John Smith
Chicago, IL
4600
2003-01-07 14:16:02.0 GMTXmlBeans in Action3.041.291JSR-1731.011.995Teach Yourself XML in 21 days1.035.491
Peter Newman
Cleveland, OH
2300
2003-01-07 14:16:35.0 GMTJava 62.012.793
\ No newline at end of file +Gladys Kravitz
Anytown, PA
3400
2003-01-07 08:16:00.0 CSTBurnham's Celestial Handbook, Vol 15.021.792Burnham's Celestial Handbook, Vol 25.019.892
John Smith
Chicago, IL
4600
2003-01-07 08:16:02.0 CSTXmlBeans in Action3.041.291JSR-1731.011.995Teach Yourself XML in 21 days1.035.491
Peter Newman
Cleveland, OH
2300
2003-01-07 08:16:35.0 CSTJava 62.012.793
\ No newline at end of file diff --git a/samples/pom.xml b/samples/pom.xml index b212a6bad..97418b073 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -125,6 +125,12 @@ stax test + + xmlunit + xmlunit + test + 1.1 + diff --git a/samples/src/main/resources/data/staxJob/output/expected-output.xml b/samples/src/main/resources/data/staxJob/output/expected-output.xml new file mode 100644 index 000000000..d36896f18 --- /dev/null +++ b/samples/src/main/resources/data/staxJob/output/expected-output.xml @@ -0,0 +1,57 @@ + + + + XYZ0001 + 5 + 11.39 + Customer1 + + + XYZ0002 + 2 + 72.99 + Customer2c + + + XYZ0003 + 9 + 99.99 + Customer3 + + + XYZ0001 + 5 + 11.39 + Customer1 + + + XYZ0002 + 2 + 72.99 + Customer2c + + + XYZ0003 + 9 + 99.99 + Customer3 + + + XYZ0001 + 5 + 11.39 + Customer1 + + + XYZ0002 + 2 + 72.99 + Customer2c + + + XYZ0003 + 9 + 99.99 + Customer3 + + \ No newline at end of file diff --git a/samples/src/main/resources/jobs/beanWrapperMapperSampleJob.xml b/samples/src/main/resources/jobs/beanWrapperMapperSampleJob.xml index 2f94269ca..093337e45 100644 --- a/samples/src/main/resources/jobs/beanWrapperMapperSampleJob.xml +++ b/samples/src/main/resources/jobs/beanWrapperMapperSampleJob.xml @@ -10,7 +10,7 @@ - + @@ -51,7 +51,7 @@ - + @@ -64,7 +64,7 @@ - + @@ -78,13 +78,13 @@ - + - + @@ -114,16 +114,16 @@ - + - + - + @@ -136,5 +136,5 @@ - + diff --git a/samples/src/main/resources/jobs/fixedLengthImportJob.xml b/samples/src/main/resources/jobs/fixedLengthImportJob.xml index 95c3b4640..ca8be559b 100644 --- a/samples/src/main/resources/jobs/fixedLengthImportJob.xml +++ b/samples/src/main/resources/jobs/fixedLengthImportJob.xml @@ -14,7 +14,7 @@ - + @@ -95,5 +95,5 @@ - + \ No newline at end of file diff --git a/samples/src/main/resources/jobs/multilineOrderJob.xml b/samples/src/main/resources/jobs/multilineOrderJob.xml index 980d0143f..c5f39c412 100644 --- a/samples/src/main/resources/jobs/multilineOrderJob.xml +++ b/samples/src/main/resources/jobs/multilineOrderJob.xml @@ -1,7 +1,7 @@ @@ -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 @@ - + - + \ No newline at end of file diff --git a/samples/src/main/resources/jobs/tradeJobIo.xml b/samples/src/main/resources/jobs/tradeJobIo.xml index fcd756623..7a588260d 100644 --- a/samples/src/main/resources/jobs/tradeJobIo.xml +++ b/samples/src/main/resources/jobs/tradeJobIo.xml @@ -1,7 +1,7 @@ diff --git a/samples/src/test/java/org/springframework/batch/sample/XmlStaxJobFunctionalTests.java b/samples/src/test/java/org/springframework/batch/sample/XmlStaxJobFunctionalTests.java index 4ebed8258..9b2f2e1cf 100644 --- a/samples/src/test/java/org/springframework/batch/sample/XmlStaxJobFunctionalTests.java +++ b/samples/src/test/java/org/springframework/batch/sample/XmlStaxJobFunctionalTests.java @@ -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)); } }