Unit Testing XML independent of physical XML file

Posted by RAbraham on Stack Overflow See other posts from Stack Overflow or by RAbraham
Published on 2010-06-10T20:51:46Z Indexed on 2010/06/10 21:23 UTC
Read the original article Hit count: 481

Filed under:
|
|

Hi,

My question is:

In JUnit, How do I setup xml data for my System Under Test(SUT) without making the SUT read from an XML file physically stored on the file system

Background:

I am given a XML file which contains rules for creation of an invoice. My job is to convert these rules from XMl to Java Objects e.g. If there is a tag as below in my XML file which indicates that after a period of 30 days, the transaction cannot be invoiced

<ExpirationDay>30</ExpirationDay> 

this converts to a Java class , say ExpirationDateInvoicingRule

I have a class InvoiceConfiguration which should take the XML file and create the *InvoicingRule objects. I am thinking of using StAX to parse the XML document within InvoiceConfiguration

Problem:

I want to unit test InvoiceConfiguration. But I dont want InvoiceConfiguration to read from an xml file physically on the file system . I want my unit test to be independent of any physical stored xml file. I want to create a xml representation in memory. But a StAX parser only takes FileReader( or I can play with the File Object)

© Stack Overflow or respective owner

Related posts about Xml

Related posts about junit