Search in sources :

Example 11 with XmlUtils

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

the class SplittingXmlPayloadTranslatorTest method testMultipleResultMessages.

@Test
public void testMultipleResultMessages() throws Exception {
    createDatabase();
    List<AdapterTypeVersion> dbItems = generate(11);
    AdapterTypeVersion entry = dbItems.get(0);
    populateDatabase(dbItems, false);
    JdbcDataQueryService s = createMultiService();
    SplittingXmlPayloadTranslator translator = createPayloadTranslator().withMaxRowsPerMessage(2);
    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());
        assertFalse(outputMessage.headersContainsKey(ADAPTER_ID_KEY));
        count++;
    }
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 12 with XmlUtils

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

the class XmlHelperTest method testCreateDocument.

@Test
public void testCreateDocument() throws Exception {
    Document d = XmlHelper.createDocument(EXAMPLE_XML);
    assertNotNull(d);
    XmlUtils xu = new XmlUtils();
    xu.setSource(d);
    assertEquals("text body", xu.getSingleTextItem("/document/content"));
    assertNotNull(createDocument(EXAMPLE_XML, DocumentBuilderFactoryBuilderTest.createNamespaceContext()));
    assertNotNull(createDocument(EXAMPLE_XML, (NamespaceContext) null));
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) NamespaceContext(javax.xml.namespace.NamespaceContext) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 13 with XmlUtils

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

the class ReplaceNodeTest method testReplaceNode.

@Test
public void testReplaceNode() throws Exception {
    ReplaceNode rn = new ReplaceNode(XPATH_ROOT_NODE);
    Document original = XmlHelper.createDocument(ORIGINAL);
    Document newDoc = XmlHelper.createDocument(REPLACEMENT);
    Document merged = rn.merge(original, newDoc);
    XmlUtils xml = new XmlUtils();
    xml.setSource(merged);
    assertNotNull(xml.getSingleTextItem(XPATH_ROOT_NODE));
    assertNotSame(DATA_A, xml.getSingleTextItem(XPATH_ROOT_NODE));
    assertEquals(DATA_B, xml.getSingleTextItem(XPATH_ROOT_NODE));
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 14 with XmlUtils

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

the class InsertNodeTest method testInsertNode.

@Test
public void testInsertNode() throws Exception {
    InsertNode rn = new InsertNode(XPATH_ROOT);
    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(XPATH_NEW_NODE));
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 15 with XmlUtils

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

the class SharedComponentConfigurationChecker method performConfigCheck.

@Override
public ConfigurationCheckReport performConfigCheck(ConfigurationCheckReport report, BootstrapProperties bootProperties) {
    try {
        String xml = CachingConfigLoader.loadInterlokConfig(bootProperties);
        try (InputStream in = IOUtils.toInputStream(xml, Charset.defaultCharset())) {
            XmlUtils xmlUtils = new XmlUtils();
            xmlUtils.setSource(in);
            Set<String> availableComponents = evaluate(xmlUtils, xpathAvailableComponents);
            Set<String> referencedComponents = evaluate(xmlUtils, xpathReferencedComponents);
            // **********************************
            // Check all shared components are used.
            availableComponents.forEach(component -> {
                if (!referencedComponents.contains(component)) {
                    report.getWarnings().add("Shared " + componentType + " unused: " + component);
                }
            });
            // **********************************
            // Check all referenced components exist.
            referencedComponents.forEach(component -> {
                if (!availableComponents.contains(component)) {
                    report.getFailureExceptions().add(new ConfigurationException("Shared " + componentType + " does not exist in shared components: " + component));
                }
            });
        }
    } catch (Exception ex) {
        report.getFailureExceptions().add(ex);
    }
    return report;
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) InputStream(java.io.InputStream)

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