Search in sources :

Example 51 with XPath

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

the class MetadataXpathQueryTest method testResolveXpath_EmptyResults_NotAllowed.

@Test
public void testResolveXpath_EmptyResults_NotAllowed() throws Exception {
    MetadataXpathQuery query = init(create());
    Document doc = XmlHelper.createDocument(XML);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML);
    msg.addMetadata("xpathMetadataKey", "//@MissingAttribute");
    try {
        MetadataElement result = query.resolveXpath(doc, new XPath(), query.createXpathQuery(msg));
        fail();
    } catch (CoreException expected) {
    }
}
Also used : XPath(com.adaptris.util.text.xml.XPath) CoreException(com.adaptris.core.CoreException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 52 with XPath

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

the class MultiItemConfiguredXpathQueryTest method testResolveXpath_EmptyResults_Allowed_EmptyValues.

@Test
public void testResolveXpath_EmptyResults_Allowed_EmptyValues() throws Exception {
    MultiItemConfiguredXpathQuery query = init(create(), XPATH_EMPTY_NODES);
    query.setAllowEmptyResults(Boolean.TRUE);
    Document doc = XmlHelper.createDocument(XML_WITH_EMPTY_NODES);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_WITH_EMPTY_NODES);
    MetadataElement result = query.resolveXpath(doc, new XPath(), query.createXpathQuery(msg));
    assertEquals("|||91/01|91/01|91/01", result.getValue());
}
Also used : XPath(com.adaptris.util.text.xml.XPath) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 53 with XPath

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

the class MultiItemConfiguredXpathQueryTest method testResolveNodesAsString.

@Test
public void testResolveNodesAsString() throws Exception {
    MultiItemConfiguredXpathQuery query = new MultiItemConfiguredXpathQuery("result", "//PXREF1[string-length(text()) > 0]", "");
    query.setAsXmlString(true);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_WITH_EMPTY_NODES);
    MetadataElement result = query.resolveXpath(XmlHelper.createDocument(msg.getContent()), new XPath(), query.createXpathQuery(msg));
    assertEquals("<PXREF1>91/01</PXREF1>\n" + "<PXREF1>91/01</PXREF1>\n" + "<PXREF1>91/01</PXREF1>", result.getValue().strip());
}
Also used : XPath(com.adaptris.util.text.xml.XPath) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 54 with XPath

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

the class MultiItemMetadataXpathQueryTest method testResolveXpath_EmptyResults_NotAllowed.

@Test
public void testResolveXpath_EmptyResults_NotAllowed() throws Exception {
    MultiItemMetadataXpathQuery query = init(create());
    Document doc = XmlHelper.createDocument(XML);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML);
    msg.addMetadata("xpathMetadataKey", "//@MissingAttribute");
    try {
        MetadataElement result = query.resolveXpath(doc, new XPath(), query.createXpathQuery(msg));
        fail();
    } catch (CoreException expected) {
    }
}
Also used : XPath(com.adaptris.util.text.xml.XPath) CoreException(com.adaptris.core.CoreException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 55 with XPath

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

the class MultiItemMetadataXpathQueryTest method testResolveNodesAsString.

@Test
public void testResolveNodesAsString() throws Exception {
    MultiItemMetadataXpathQuery query = new MultiItemMetadataXpathQuery("result", "xpathMetadataKey", "");
    query.setAsXmlString(true);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(MultiItemConfiguredXpathQueryTest.XML_WITH_EMPTY_NODES);
    msg.addMetadata("xpathMetadataKey", "//PXREF1[string-length(text()) > 0]");
    MetadataElement result = query.resolveXpath(XmlHelper.createDocument(msg.getContent()), new XPath(), query.createXpathQuery(msg));
    assertEquals("<PXREF1>91/01</PXREF1>\n" + "<PXREF1>91/01</PXREF1>\n" + "<PXREF1>91/01</PXREF1>", result.getValue().strip());
}
Also used : XPath(com.adaptris.util.text.xml.XPath) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Aggregations

XPath (com.adaptris.util.text.xml.XPath)75 Document (org.w3c.dom.Document)64 Test (org.junit.Test)63 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)45 MetadataElement (com.adaptris.core.MetadataElement)23 DocumentBuilderFactoryBuilder (com.adaptris.core.util.DocumentBuilderFactoryBuilder)21 CoreException (com.adaptris.core.CoreException)12 Node (org.w3c.dom.Node)11 SimpleNamespaceContext (com.adaptris.util.text.xml.SimpleNamespaceContext)9 NamespaceContext (javax.xml.namespace.NamespaceContext)9 ServiceException (com.adaptris.core.ServiceException)7 InsertNode (com.adaptris.util.text.xml.InsertNode)6 NodeList (org.w3c.dom.NodeList)6 NullService (com.adaptris.core.NullService)5 PooledSplitJoinService (com.adaptris.core.services.splitter.PooledSplitJoinService)5 XpathMessageSplitter (com.adaptris.core.services.splitter.XpathMessageSplitter)5 TimeInterval (com.adaptris.util.TimeInterval)5 XmlHelper.createDocument (com.adaptris.core.util.XmlHelper.createDocument)3 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)2 MultiPayloadAdaptrisMessage (com.adaptris.core.MultiPayloadAdaptrisMessage)2