ConfiguredXpathNodeQuery extends ConfiguredXpathQueryImpl implements XpathObjectQuery { @Override public Node resolveXpath(Document doc, XPath xpath, String expression) throws Exception { return XpathQueryHelper.resolveSingleNode(doc, xpath, expression, allowEmptyResults()); } ConfiguredXpathNodeQuery();  ConfiguredXpathNodeQuery(String metadataKey, String xpath); @Override Node resolveXpath(Document doc, XPath xpath, String expression);  }
@Test public void testResolveXpath_EmptyResults_NotAllowed() throws Exception { ConfiguredXpathNodeQuery query = init(create(), " Document doc = XmlHelper.createDocument(XML); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML); try { Node result = query.resolveXpath(doc, new XPath(), query.createXpathQuery(msg)); fail(); } catch (CoreException expected) { } }
@Test public void testResolveXpath_EmptyResults_Allowed() throws Exception { ConfiguredXpathNodeQuery query = init(create(), " query.setAllowEmptyResults(Boolean.TRUE); Document doc = XmlHelper.createDocument(XML); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML); Node result = query.resolveXpath(doc, new XPath(), query.createXpathQuery(msg)); assertNull(result); }
@Test public void testResolveXpath_Attribute() throws Exception { ConfiguredXpathNodeQuery query = init(create(), " Document doc = XmlHelper.createDocument(XML); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML); Node result = query.resolveXpath(doc, new XPath(), query.createXpathQuery(msg)); assertNotNull(result); }
@Test public void testResolveXpath_NamespaceWithNamespaceContext() throws Exception { ConfiguredXpathNodeQuery query = init(create(), "/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); Node result = query.resolveXpath(doc, new XPath(ctx), query.createXpathQuery(msg)); assertNotNull(result); }