Search in sources :

Example 26 with XmlUtils

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

the class MergeResultSetIntoPayloadTest method testXpathStatementParam_NodeDoesNotExist.

@Test
public void testXpathStatementParam_NodeDoesNotExist() throws Exception {
    createDatabase();
    List<AdapterTypeVersion> dbItems = generate(10);
    AdapterTypeVersion entry = dbItems.get(0);
    populateDatabase(dbItems, false);
    JdbcDataQueryService s = createXmlService();
    // /root/NonExistentNode, doesn't actually exist at this point.
    s.setResultSetTranslator(new MergeResultSetIntoXmlPayload(new InsertNode("/root/NonExistentNode")));
    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);
    assertNotNull("/root/document doesn't exist", xu.getSingleNode("/root/document"));
    assertNotNull("/root/NonExistentNode/Results/Row doesn't exist", xu.getSingleNode("/root/NonExistentNode/Results/Row"));
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) InsertNode(com.adaptris.util.text.xml.InsertNode) Test(org.junit.Test)

Example 27 with XmlUtils

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

the class SplittingXmlPayloadTranslatorTest method testXpathStatementParamWithLowerCase.

@Test
public void testXpathStatementParamWithLowerCase() throws Exception {
    createDatabase();
    List<AdapterTypeVersion> dbItems = generate(10);
    AdapterTypeVersion entry = dbItems.get(0);
    populateDatabase(dbItems, false);
    JdbcDataQueryService s = createXmlService();
    SplittingXmlPayloadTranslator t = createPayloadTranslator();
    t.setColumnNameStyle(ResultSetTranslatorImp.ColumnStyle.LowerCase);
    s.setResultSetTranslator(t);
    AdaptrisMessage msg = createMessage(entry);
    execute(s, msg);
    assertTrue(msg.headersContainsKey(ADAPTER_ID_KEY));
    assertFalse(msg.headersContainsKey(JdbcDataQueryService.class.getCanonicalName()));
    AdaptrisMessage outputMessage = producer.getMessages().get(0);
    XmlUtils xu = XmlHelper.createXmlUtils(outputMessage);
    log.warn(msg.getContent());
    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 28 with XmlUtils

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

the class SplittingXmlPayloadTranslatorTest 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(createPayloadTranslator());
    AdaptrisMessage msg = createMessage(entry);
    execute(s, msg);
    assertTrue(msg.headersContainsKey(ADAPTER_ID_KEY));
    assertFalse(msg.headersContainsKey(JdbcDataQueryService.class.getCanonicalName()));
    AdaptrisMessage outputMessage = producer.getMessages().get(0);
    XmlUtils xu = XmlHelper.createXmlUtils(outputMessage);
    assertNull("Xpath /Results/OriginalMessage", xu.getSingleNode("/Results/OriginalMessage"));
    assertNotNull("/Results/Row missing.", xu.getSingleNode("/Results/Row"));
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 29 with XmlUtils

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

the class SplittingXmlPayloadTranslatorTest method testMultipleResultMessages_CopyMetadata.

@Test
public void testMultipleResultMessages_CopyMetadata() throws Exception {
    createDatabase();
    List<AdapterTypeVersion> dbItems = generate(11);
    AdapterTypeVersion entry = dbItems.get(0);
    populateDatabase(dbItems, false);
    JdbcDataQueryService s = createMultiService();
    SplittingXmlPayloadTranslator translator = createPayloadTranslator().withMaxRowsPerMessage(2).withCopyMetadata(true).withMessageFactory(new DefaultMessageFactory());
    s.setResultSetTranslator(translator);
    AdaptrisMessage msg = createMessage(entry);
    execute(s, msg);
    assertTrue(msg.headersContainsKey(ADAPTER_ID_KEY));
    assertFalse(msg.headersContainsKey(JdbcDataQueryService.class.getCanonicalName()));
    List<AdaptrisMessage> outputMessages = producer.getMessages();
    assertEquals(6, outputMessages.size());
    int count = 0;
    for (AdaptrisMessage outputMessage : outputMessages) {
        XmlUtils xu = XmlHelper.createXmlUtils(outputMessage);
        assertNull("Xpath /Results/OriginalMessage", xu.getSingleNode("/Results/OriginalMessage"));
        assertEquals("/Results/Row", count < 5 ? 2 : 1, xu.getNodeList("/Results/Row").getLength());
        assertTrue(outputMessage.headersContainsKey(ADAPTER_ID_KEY));
        count++;
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 30 with XmlUtils

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

the class SplittingXmlPayloadTranslatorTest method testXpathStatementParam.

@Test
public void testXpathStatementParam() throws Exception {
    createDatabase();
    List<AdapterTypeVersion> dbItems = generate(10);
    AdapterTypeVersion entry = dbItems.get(0);
    populateDatabase(dbItems, false);
    JdbcDataQueryService s = createXmlService();
    s.setResultSetTranslator(createPayloadTranslator());
    AdaptrisMessage msg = createMessage(entry);
    execute(s, msg);
    assertTrue(msg.headersContainsKey(ADAPTER_ID_KEY));
    assertFalse(msg.headersContainsKey(JdbcDataQueryService.class.getCanonicalName()));
    AdaptrisMessage outputMessage = producer.getMessages().get(0);
    XmlUtils xu = XmlHelper.createXmlUtils(outputMessage);
    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)

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