Class XpathResultMatchers
- java.lang.Object
- org.springframework.test.web.servlet.result.XpathResultMatchers
public class XpathResultMatchers extends Object
Factory for assertions on the response content using XPath expressions.An instance of this class is typically accessed via
MockMvcResultMatchers.xpath(java.lang.String, java.lang.Object...).- Since:
- 3.2
- Author:
- Rossen Stoyanchev
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ResultMatcherbooleanValue(Boolean value)Evaluate the XPath and assert theBooleanvalue found.ResultMatcherdoesNotExist()Evaluate the XPath and assert that content doesn't exist.ResultMatcherexists()Evaluate the XPath and assert that content exists.ResultMatchernode(Matcher<? super Node> matcher)ResultMatchernodeCount(int expectedCount)Evaluate the XPath and assert the number of nodes found.ResultMatchernodeCount(Matcher<Integer> matcher)Evaluate the XPath and assert the number of nodes found with the given HamcrestMatcher.ResultMatchernumber(Double expectedValue)Evaluate the XPath and assert theDoublevalue found.ResultMatchernumber(Matcher<? super Double> matcher)ResultMatcherstring(String expectedValue)Apply the XPath and assert theStringvalue found.ResultMatcherstring(Matcher<? super String> matcher)
Constructor Detail
XpathResultMatchers
protected XpathResultMatchers(String expression, Map<String,String> namespaces, Object... args) throws XPathExpressionException
Protected constructor, not for direct instantiation. UseMockMvcResultMatchers.xpath(String, Object...)orMockMvcResultMatchers.xpath(String, Map, Object...).- Parameters:
expression- the XPath expressionnamespaces- XML namespaces referenced in the XPath expression, ornullargs- arguments to parameterize the XPath expression with using the formatting specifiers defined inString.format(String, Object...)- Throws:
XPathExpressionException
Method Detail
node
public ResultMatcher node(Matcher<? super Node> matcher)
exists
public ResultMatcher exists()
Evaluate the XPath and assert that content exists.
doesNotExist
public ResultMatcher doesNotExist()
Evaluate the XPath and assert that content doesn't exist.
nodeCount
public ResultMatcher nodeCount(Matcher<Integer> matcher)
Evaluate the XPath and assert the number of nodes found with the given HamcrestMatcher.
nodeCount
public ResultMatcher nodeCount(int expectedCount)
Evaluate the XPath and assert the number of nodes found.
string
public ResultMatcher string(Matcher<? super String> matcher)
string
public ResultMatcher string(String expectedValue)
Apply the XPath and assert theStringvalue found.
number
public ResultMatcher number(Matcher<? super Double> matcher)
number
public ResultMatcher number(Double expectedValue)
Evaluate the XPath and assert theDoublevalue found.
booleanValue
public ResultMatcher booleanValue(Boolean value)
Evaluate the XPath and assert theBooleanvalue found.