Skip to content

Instantly share code, notes, and snippets.

@tfennelly
Created October 13, 2011 10:26
Show Gist options
  • Save tfennelly/1283922 to your computer and use it in GitHub Desktop.
Save tfennelly/1283922 to your computer and use it in GitHub Desktop.
public class TransformTest {
@Test
public void test_read_write_request() throws IOException, SAXException {
XMLBinding requestBinding = new XMLBinding().add("/smooks/PolicyQuoteCalculationConfigSmooksRequest.xml").intiailize();
// Read....
Policy policy = requestBinding.fromXML(REQUEST, Policy.class);
// Write....
String writeResult = requestBinding.toXML(policy);
// Assert they're the same...
XMLUnit.setIgnoreWhitespace(true);
XMLAssert.assertEquals(REQUEST, writeResult);
}
@Test
public void test_read_write_reply() throws IOException, SAXException {
XMLBinding replyBinding = new XMLBinding().add("/smooks/PolicyQuoteCalculationConfigSmooksReply.xml").intiailize();
// Read....
Policy policy = replyBinding.fromXML(REPLY, Policy.class);
// Write....
String writeResult = replyBinding.toXML(policy);
// Assert they're the same...
XMLUnit.setIgnoreWhitespace(true);
XMLAssert.assertEquals(REPLY, writeResult);
}
@Test
public void test_read_request_write_reply() throws IOException, SAXException {
XMLBinding requestBinding = new XMLBinding().add("/smooks/PolicyQuoteCalculationConfigSmooksRequest.xml").intiailize();
XMLBinding replyBinding = new XMLBinding().add("/smooks/PolicyQuoteCalculationConfigSmooksReply.xml").intiailize();
// Read....
Policy policy = requestBinding.fromXML(REQUEST, Policy.class);
// Write....
String writeResult = replyBinding.toXML(policy);
// Assert they're the same...
XMLUnit.setIgnoreWhitespace(true);
XMLAssert.assertEquals(REPLY, writeResult);
}
private static final String REQUEST = "<?xml version=\"1.0\"?>\n" +
"<pol:policyQuote xmlns:pol=\"http://www.example.org/policyQuote\">\n" +
" <pol:calculatePolicyQuote>\n" +
" <pol:requestDate>2009-01-01</pol:requestDate>\n" +
" <pol:policyQuoteInfo>\n" +
" <pol:policyType>AUTO</pol:policyType>\n" +
" <pol:vehicleYear>2004</pol:vehicleYear>\n" +
" <pol:driverName>Bill Smith</pol:driverName>\n" +
" <pol:ssn>012345678</pol:ssn>\n" +
" <pol:dlNumber>987654321</pol:dlNumber>\n" +
" <pol:age>30</pol:age>\n" +
" <pol:numberOfAccidents>1</pol:numberOfAccidents>\n" +
" <pol:numberOfTickets>2</pol:numberOfTickets>\n" +
" <pol:creditScore>500</pol:creditScore>\n" +
" </pol:policyQuoteInfo>\n" +
" </pol:calculatePolicyQuote>\n" +
"</pol:policyQuote>";
private static final String REPLY = "<?xml version=\"1.0\"?>\n" +
"<pol:policyQuoteReply xmlns:pol=\"http://www.example.org/policyQuote\">\n" +
" <pol:calculatePolicyQuote>\n" +
" <pol:requestDate>2009-01-01</pol:requestDate>\n" +
" <pol:policyQuoteInfo>\n" +
" <pol:policyType>AUTO</pol:policyType>\n" +
" <pol:vehicleYear>2004</pol:vehicleYear>\n" +
" <pol:driverName>Bill Smith</pol:driverName>\n" +
" <pol:ssn>012345678</pol:ssn>\n" +
" <pol:dlNumber>987654321</pol:dlNumber>\n" +
" <pol:age>30</pol:age>\n" +
" <pol:numberOfAccidents>1</pol:numberOfAccidents>\n" +
" <pol:numberOfTickets>2</pol:numberOfTickets>\n" +
" <pol:creditScore>500</pol:creditScore>\n" +
" </pol:policyQuoteInfo>\n" +
" </pol:calculatePolicyQuote>\n" +
"</pol:policyQuoteReply>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment