org.xmlunit.xpath.XPathEngine Java Examples
The following examples show how to use
org.xmlunit.xpath.XPathEngine.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElementSelectors.java From xmlunit with Apache License 2.0 | 6 votes |
/** * Selects two elements as matching if the child elements selected * via XPath match using the given childSelector. * * <p>The xpath expression should yield elements. Two elements * match if a DefaultNodeMatcher applied to the selected children * finds matching pairs for all children.</p> * * @param xpath XPath expression applied in the context of the * elements to chose from that selects the children to compare. * @param prefix2Uri maps from prefix to namespace URI. * @param childSelector ElementSelector to apply to the selected children. */ public static ElementSelector byXPath(final String xpath, Map<String, String> prefix2Uri, ElementSelector childSelector) { final XPathEngine engine = new JAXPXPathEngine(); if (prefix2Uri != null) { engine.setNamespaceContext(prefix2Uri); } final NodeMatcher nm = new DefaultNodeMatcher(childSelector); return new ElementSelector() { @Override public boolean canBeCompared(Element controlElement, Element testElement) { Iterable<Node> controlChildren = engine.selectNodes(xpath, controlElement); int expected = Linqy.count(controlChildren); int matched = Linqy.count(nm.match(controlChildren, engine.selectNodes(xpath, testElement))); return expected == matched; } }; }
Example #2
Source File: SmtpConfigurationTest.java From james-project with Apache License 2.0 | 5 votes |
@Test public void defaultSmtpConfigurationShouldNotHaveAuthorizedNetwork() throws IOException { String xmlFile = SmtpConfiguration.DEFAULT.serializeAsXml(); Source source = Input.fromString(xmlFile).build(); XPathEngine xpath = new JAXPXPathEngine(); Iterable<Node> allMatches = xpath.selectNodes("/smtpservers/smtpserver/authorizedAddresses", source); Assertions.assertThat(allMatches).isEmpty(); }