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
Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.
Hacer que el código abierto sea más inclusivo
Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.
Acerca de Red Hat
Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.