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));
}
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);
}
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());
}
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));
}
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());
}
Aggregations