Search in sources :

Example 36 with XmlUtils

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

the class XmlPayloadTranslatorTest method testPreserveOriginal.

@Test
public void testPreserveOriginal() throws Exception {
    createDatabase();
    List<AdapterTypeVersion> dbItems = generate(10);
    AdapterTypeVersion entry = dbItems.get(0);
    populateDatabase(dbItems, false);
    JdbcDataQueryService s = createMetadataService();
    XmlPayloadTranslator t = new XmlPayloadTranslator();
    t.setPreserveOriginalMessage(true);
    s.setResultSetTranslator(t);
    AdaptrisMessage msg = createMessage(entry);
    execute(s, msg);
    assertTrue(ADAPTER_ID_KEY + " exists", msg.containsKey(ADAPTER_ID_KEY));
    XmlUtils xu = XmlHelper.createXmlUtils(msg);
    assertNotNull("Xpath /Results/OriginalMessage", xu.getSingleNode("/Results/OriginalMessage"));
    assertNotNull("/Results/Row", xu.getSingleNode("/Results/Row"));
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 37 with XmlUtils

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

the class XmlPayloadTranslatorTest method testMetadataStatementParam.

@Test
public void testMetadataStatementParam() throws Exception {
    createDatabase();
    List<AdapterTypeVersion> dbItems = generate(10);
    AdapterTypeVersion entry = dbItems.get(0);
    populateDatabase(dbItems, false);
    JdbcDataQueryService s = createMetadataService();
    s.setResultSetTranslator(new XmlPayloadTranslator());
    AdaptrisMessage msg = createMessage(entry);
    execute(s, msg);
    assertTrue(ADAPTER_ID_KEY + " exists", msg.containsKey(ADAPTER_ID_KEY));
    assertNotSame(XML_PAYLOAD_PREFIX + entry.getUniqueId() + XML_PAYLOAD_SUFFIX, msg.getContent());
    assertFalse(msg.containsKey(JdbcDataQueryService.class.getCanonicalName()));
    XmlUtils xu = XmlHelper.createXmlUtils(msg);
    assertNull("Xpath /Results/OriginalMessage", xu.getSingleNode("/Results/OriginalMessage"));
    assertNotNull("/Results/Row", xu.getSingleNode("/Results/Row"));
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 38 with XmlUtils

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

the class XmlPayloadTranslatorTest method testContainsRowCount.

@Test
public void testContainsRowCount() throws Exception {
    createDatabase();
    List<AdapterTypeVersion> dbItems = generate(10);
    AdapterTypeVersion entry = dbItems.get(0);
    populateDatabase(dbItems, false);
    JdbcDataQueryService s = createMetadataService();
    XmlPayloadTranslator t = new XmlPayloadTranslator();
    t.setResultCountMetadataItem(getName());
    s.setResultSetTranslator(t);
    AdaptrisMessage msg = createMessage(entry);
    execute(s, msg);
    assertTrue(ADAPTER_ID_KEY + " exists", msg.containsKey(ADAPTER_ID_KEY));
    XmlUtils xu = XmlHelper.createXmlUtils(msg);
    assertNull("Xpath /Results/OriginalMessage", xu.getSingleNode("/Results/OriginalMessage"));
    assertNotNull("/Results/Row", xu.getSingleNode("/Results/Row"));
    assertTrue(msg.containsKey(getName()));
    assertEquals("1", msg.getMetadataValue(getName()));
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 39 with XmlUtils

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

the class XmlNotificationSerializer method serialize.

@Override
public AdaptrisMessage serialize(Notification n, AdaptrisMessage msg) throws CoreException, IOException {
    try {
        XmlUtils xmlBuilder = new XmlUtils();
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        Element root = doc.createElement(XML_ROOT_ELEMENT);
        doc.appendChild(root);
        xmlBuilder.setSource(doc);
        for (NotificationElement e : NotificationElement.values()) {
            xmlBuilder.setNodeValue(e.xpathToNode(), e.getValue(n));
        }
        try (OutputStream out = msg.getOutputStream()) {
            String encoding = XmlHelper.getXmlEncoding(msg, getOutputMessageEncoding());
            xmlBuilder.writeDocument(out, encoding);
            msg.setContentEncoding(encoding);
        }
        if (n.getUserData() != null) {
            msg.getObjectHeaders().put(OBJ_METADATA_USERDATA, n.getUserData());
        }
    } catch (Exception e) {
        throw ExceptionHelper.wrapCoreException(e);
    }
    return msg;
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) Element(org.w3c.dom.Element) OutputStream(java.io.OutputStream) Document(org.w3c.dom.Document) CoreException(com.adaptris.core.CoreException) IOException(java.io.IOException)

Example 40 with XmlUtils

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

the class InsertNodeTest method testInsertNode_NodeDoesNotExist.

@Test
public void testInsertNode_NodeDoesNotExist() throws Exception {
    InsertNode rn = new InsertNode("/Root/AnotherNode");
    rn.setXmlDocumentFactoryConfig(DocumentBuilderFactoryBuilder.newInstance());
    Document merged = rn.merge(XmlHelper.createDocument(ORIGINAL), XmlHelper.createDocument(REPLACEMENT));
    XmlUtils xml = new XmlUtils();
    xml.setSource(merged);
    assertNotNull(xml.getSingleTextItem(XPATH_ORIGINAL_NODE));
    assertEquals(DATA_A, xml.getSingleTextItem(XPATH_ORIGINAL_NODE));
    assertEquals(DATA_B, xml.getSingleTextItem("/Root/AnotherNode/NewNode"));
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) Document(org.w3c.dom.Document) 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