To undertake unit testing with Smooks, follow the example below:
public class MyMessageTransformTest
{
@Test
public void test_transform() throws IOException, SAXException
{
Smooks smooks = new Smooks(
getClass().getResourceAsStream("smooks-config.xml") );
try {
Source source = new StreamSource(
getClass().getResourceAsStream("input-message.xml" ) );
StringResult result = new StringResult();
smooks.filterSource(source, result);
// compare the expected xml with the transformation result.
XMLUnit.setIgnoreWhitespace( true );
XMLAssert.assertXMLEqual(
new InputStreamReader(
getClass().getResourceAsStream("expected.xml")),
new StringReader(result.getResult()));
} finally {
smooks.close();
}
}
}
public class MyMessageTransformTest
{
@Test
public void test_transform() throws IOException, SAXException
{
Smooks smooks = new Smooks(
getClass().getResourceAsStream("smooks-config.xml") );
try {
Source source = new StreamSource(
getClass().getResourceAsStream("input-message.xml" ) );
StringResult result = new StringResult();
smooks.filterSource(source, result);
// compare the expected xml with the transformation result.
XMLUnit.setIgnoreWhitespace( true );
XMLAssert.assertXMLEqual(
new InputStreamReader(
getClass().getResourceAsStream("expected.xml")),
new StringReader(result.getResult()));
} finally {
smooks.close();
}
}
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.
Making open source more inclusive
Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.
About Red Hat
We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.