Search in sources :

Example 16 with XPath

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

the class XpathQueryHelperTest method resolveSingleNode_Missing_AllowEmptyTrue.

@Test
public void resolveSingleNode_Missing_AllowEmptyTrue() throws Exception {
    DocumentBuilderFactoryBuilder builder = DocumentBuilderFactoryBuilder.newInstance();
    Document doc = XmlHelper.createDocument(XpathQueryCase.XML, builder);
    XPath xpathToUse = XPath.newXPathInstance(builder, null);
    assertNull(XpathQueryHelper.resolveSingleNode(doc, xpathToUse, "//@MissingAttribute", true));
}
Also used : XPath(com.adaptris.util.text.xml.XPath) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 17 with XPath

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

the class XpathQueryHelperTest method testResolveSingleTextItem_Missing_AllowEmptyFalse.

@Test(expected = CoreException.class)
public void testResolveSingleTextItem_Missing_AllowEmptyFalse() throws Exception {
    DocumentBuilderFactoryBuilder builder = DocumentBuilderFactoryBuilder.newInstance();
    Document doc = XmlHelper.createDocument(XpathQueryCase.XML, builder);
    XPath xpathToUse = XPath.newXPathInstance(builder, null);
    XpathQueryHelper.resolveSingleTextItem(doc, xpathToUse, "//@MissingAttribute", false);
}
Also used : XPath(com.adaptris.util.text.xml.XPath) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 18 with XPath

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

the class ConfiguredXpathQueryTest method testResolveXpath_NamespaceWithNamespaceContext.

// Invalid test
// Namedspaced document with non-namespace xpath never matches with SAXON
// public void testResolveXpath_NamespaceNoNamespaceContext() throws Exception {
// ConfiguredXpathQuery query = init(create(), "count(/schematron-output/failed-assert)");
// Document doc = XmlHelper.createDocument(XML_WITH_NAMESPACE);
// AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_WITH_NAMESPACE, "UTF-8");
// 
// MetadataElement result = query.resolveXpath(doc, null, query.createXpathQuery(msg));
// assertEquals("2", result.getValue());
// }
@Test
public void testResolveXpath_NamespaceWithNamespaceContext() throws Exception {
    ConfiguredXpathQuery query = init(create(), "count(/svrl:schematron-output/svrl:failed-assert)");
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_WITH_NAMESPACE);
    StaticNamespaceContext ctx = new StaticNamespaceContext();
    Document doc = XmlHelper.createDocument(XML_WITH_NAMESPACE, ctx);
    MetadataElement result = query.resolveXpath(doc, new XPath(ctx), query.createXpathQuery(msg));
    assertEquals("2", 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 19 with XPath

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

the class ConfiguredXpathQueryTest method testResolveXpath_Attribute.

@Test
public void testResolveXpath_Attribute() throws Exception {
    ConfiguredXpathQuery query = init(create(), "//@att");
    Document doc = XmlHelper.createDocument(XML);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML);
    MetadataElement result = query.resolveXpath(doc, new XPath(), query.createXpathQuery(msg));
}
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 20 with XPath

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

the class ConfiguredXpathQueryTest method testResolveXpath_EmptyResults_Allowed.

@Test
public void testResolveXpath_EmptyResults_Allowed() throws Exception {
    ConfiguredXpathQuery query = init(create(), "//@MissingAttribute");
    query.setAllowEmptyResults(Boolean.TRUE);
    Document doc = XmlHelper.createDocument(XML);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML);
    MetadataElement result = query.resolveXpath(doc, new XPath(), query.createXpathQuery(msg));
    assertEquals("", 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)

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