Search in sources :

Example 1 with XmlUtils

use of com.adaptris.util.XmlUtils in project interlok by adaptris.

the class StoredProcedureProducerTest method resolveXPath.

private String resolveXPath(AdaptrisMessage message, String xpath) throws XPathExpressionException, IOException {
    XmlUtils xmlUtility = new XmlUtils();
    xmlUtility.setSource(message.getInputStream());
    String textItem = new XPath().selectSingleTextItem(xmlUtility.getCurrentDoc(), xpath);
    if (isEmpty(textItem)) {
        return null;
    } else {
        return textItem;
    }
}
Also used : XPath(com.adaptris.util.text.xml.XPath) XmlUtils(com.adaptris.util.XmlUtils)

Example 2 with XmlUtils

use of com.adaptris.util.XmlUtils in project interlok by adaptris.

the class XmlNotificationSerializerTest method testSerialize.

@Test
public void testSerialize() throws Exception {
    String myName = testName.getMethodName();
    Notification n = new Notification(myName, myName, 1, myName);
    n.setUserData(new Object());
    XmlNotificationSerializer serializer = new XmlNotificationSerializer();
    AdaptrisMessage msg = serializer.serialize(n, AdaptrisMessageFactory.getDefaultInstance().newMessage());
    XmlUtils utils = XmlHelper.createXmlUtils(msg, null, null);
    assertNotNull(msg.getObjectHeaders().get(NotificationSerializer.OBJ_METADATA_USERDATA));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Message"));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Type"));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Source"));
    assertEquals("1", utils.getSingleTextItem("/Notification/SequenceNumber"));
    assertNotNull(utils.getSingleTextItem("/Notification/Timestamp"));
    assertEquals("UTF-8", msg.getContentEncoding());
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Notification(javax.management.Notification) Test(org.junit.Test)

Example 3 with XmlUtils

use of com.adaptris.util.XmlUtils in project interlok by adaptris.

the class XmlNotificationSerializerTest method testSerialize_NoUserData.

@Test
public void testSerialize_NoUserData() throws Exception {
    String myName = testName.getMethodName();
    Notification n = new Notification(myName, myName, 1, myName);
    XmlNotificationSerializer serializer = new XmlNotificationSerializer();
    AdaptrisMessage msg = serializer.serialize(n, AdaptrisMessageFactory.getDefaultInstance().newMessage());
    XmlUtils utils = XmlHelper.createXmlUtils(msg, null, null);
    assertNull(msg.getObjectHeaders().get(NotificationSerializer.OBJ_METADATA_USERDATA));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Message"));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Type"));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Source"));
    assertEquals("1", utils.getSingleTextItem("/Notification/SequenceNumber"));
    assertNotNull(utils.getSingleTextItem("/Notification/Timestamp"));
    assertEquals("UTF-8", msg.getContentEncoding());
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Notification(javax.management.Notification) Test(org.junit.Test)

Example 4 with XmlUtils

use of com.adaptris.util.XmlUtils in project interlok by adaptris.

the class XmlNotificationSerializerTest method testSerialize_WithContentEncoding.

@Test
public void testSerialize_WithContentEncoding() throws Exception {
    String myName = testName.getMethodName();
    Notification n = new Notification(myName, myName, 1, myName);
    n.setUserData(new Object());
    XmlNotificationSerializer serializer = new XmlNotificationSerializer();
    serializer.setOutputMessageEncoding("ISO-8859-1");
    AdaptrisMessage msg = serializer.serialize(n, AdaptrisMessageFactory.getDefaultInstance().newMessage());
    XmlUtils utils = XmlHelper.createXmlUtils(msg, null, null);
    assertNotNull(msg.getObjectHeaders().get(NotificationSerializer.OBJ_METADATA_USERDATA));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Message"));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Type"));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Source"));
    assertEquals("1", utils.getSingleTextItem("/Notification/SequenceNumber"));
    assertNotNull(utils.getSingleTextItem("/Notification/Timestamp"));
    assertEquals("ISO-8859-1", msg.getContentEncoding());
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Notification(javax.management.Notification) Test(org.junit.Test)

Example 5 with XmlUtils

use of com.adaptris.util.XmlUtils in project interlok by adaptris.

the class XmlNotificationSerializerTest method testSerialize_WithContentEncoding_FromMessage.

@Test
public void testSerialize_WithContentEncoding_FromMessage() throws Exception {
    String myName = testName.getMethodName();
    Notification n = new Notification(myName, myName, 1, myName);
    n.setUserData(new Object());
    XmlNotificationSerializer serializer = new XmlNotificationSerializer();
    AdaptrisMessageFactory factory = new DefaultMessageFactory();
    factory.setDefaultCharEncoding("ISO-8859-1");
    AdaptrisMessage msg = serializer.serialize(n, factory.newMessage());
    XmlUtils utils = XmlHelper.createXmlUtils(msg, null, null);
    assertNotNull(msg.getObjectHeaders().get(NotificationSerializer.OBJ_METADATA_USERDATA));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Message"));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Type"));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Source"));
    assertEquals("1", utils.getSingleTextItem("/Notification/SequenceNumber"));
    assertNotNull(utils.getSingleTextItem("/Notification/Timestamp"));
    assertEquals("ISO-8859-1", msg.getContentEncoding());
}
Also used : AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Notification(javax.management.Notification) Test(org.junit.Test)

Aggregations

XmlUtils (com.adaptris.util.XmlUtils)41 Test (org.junit.Test)32 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)23 Document (org.w3c.dom.Document)13 InsertNode (com.adaptris.util.text.xml.InsertNode)8 CoreException (com.adaptris.core.CoreException)7 ServiceException (com.adaptris.core.ServiceException)4 Notification (javax.management.Notification)4 NamespaceContext (javax.xml.namespace.NamespaceContext)3 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)2 DocumentBuilderFactoryBuilder (com.adaptris.core.util.DocumentBuilderFactoryBuilder)2 ReplaceNode (com.adaptris.util.text.xml.ReplaceNode)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 AdaptrisMessageFactory (com.adaptris.core.AdaptrisMessageFactory)1 Service (com.adaptris.core.Service)1 ServiceImp (com.adaptris.core.ServiceImp)1 ServiceList (com.adaptris.core.ServiceList)1