Search in sources :

Example 1 with ReplaceNode

use of com.adaptris.util.text.xml.ReplaceNode in project interlok by adaptris.

the class ExceptionReportServiceTest method testNoObjectMetadata.

@Test
public void testNoObjectMetadata() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
    ExceptionReportService service = new ExceptionReportService(new ExceptionAsXml().withExceptionGenerator(new SimpleExceptionReport()).withDocumentMerge(new ReplaceNode(XPATH_ORIGINAL_NODE)));
    execute(service, msg);
    assertEquals(XML_PAYLOAD, msg.getContent());
    XmlUtils xml = XmlHelper.createXmlUtils(msg);
    assertEquals(RAW_DATA, xml.getSingleTextItem(XPATH_ORIGINAL_NODE));
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ReplaceNode(com.adaptris.util.text.xml.ReplaceNode) Test(org.junit.Test)

Example 2 with ReplaceNode

use of com.adaptris.util.text.xml.ReplaceNode in project interlok by adaptris.

the class ExceptionReportServiceTest method testNonXml.

@Test
public void testNonXml() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(RAW_DATA);
    msg.addObjectHeader(CoreConstants.OBJ_METADATA_EXCEPTION, new Exception("This is the exception"));
    ExceptionReportService service = new ExceptionReportService(new ExceptionAsXml().withExceptionGenerator(new SimpleExceptionReport()).withDocumentMerge(new ReplaceNode(XPATH_ORIGINAL_NODE)));
    try {
        execute(service, msg);
        fail("success with non-xml payload");
    } catch (ServiceException expected) {
        ;
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ReplaceNode(com.adaptris.util.text.xml.ReplaceNode) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException) Test(org.junit.Test)

Example 3 with ReplaceNode

use of com.adaptris.util.text.xml.ReplaceNode in project interlok by adaptris.

the class ExceptionReportServiceTest method testReplaceNode.

@Test
public void testReplaceNode() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
    msg.addObjectHeader(CoreConstants.OBJ_METADATA_EXCEPTION, new Exception("This is the exception"));
    ExceptionReportService service = new ExceptionReportService(new ExceptionAsXml().withExceptionGenerator(new SimpleExceptionReport()).withDocumentMerge(new ReplaceNode(XPATH_ORIGINAL_NODE)).withDocumentFactoryConfig(DocumentBuilderFactoryBuilder.newInstance()));
    execute(service, msg);
    assertNotSame(XML_PAYLOAD, msg.getContent());
    XmlUtils xml = XmlHelper.createXmlUtils(msg);
    assertNotSame(RAW_DATA, xml.getSingleNode(XPATH_ORIGINAL_NODE));
    assertEquals("UTF-8", msg.getContentEncoding());
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ReplaceNode(com.adaptris.util.text.xml.ReplaceNode) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException) Test(org.junit.Test)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)3 ReplaceNode (com.adaptris.util.text.xml.ReplaceNode)3 Test (org.junit.Test)3 CoreException (com.adaptris.core.CoreException)2 ServiceException (com.adaptris.core.ServiceException)2 XmlUtils (com.adaptris.util.XmlUtils)2