Red Hat Training

A Red Hat training course is available for Red Hat Fuse

Chapter 10. Testing

10.1. Unit Testing

Note
Since JBoss Fuse 6.3, the Smooks component for SwitchYard is deprecated and will be removed in a future release of JBoss Fuse.
  • 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();
            }
        }
    }
    
    The test case above uses a piece of software called XMLUnit (see http://xmlunit.sourceforge.net for more information.)
    Note
    The following Maven dependency was needed for the above test:
    <dependency>
        <groupId>xmlunit</groupId>
        <artifactId>xmlunit</artifactId>
        <version>1.1</version>
    </dependency>