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 ResultMatcher
booleanValue(Boolean value)
Evaluate the XPath and assert theBoolean
value found.ResultMatcher
doesNotExist()
Evaluate the XPath and assert that content doesn't exist.ResultMatcher
exists()
Evaluate the XPath and assert that content exists.ResultMatcher
node(Matcher<? super Node> matcher)
ResultMatcher
nodeCount(int expectedCount)
Evaluate the XPath and assert the number of nodes found.ResultMatcher
nodeCount(Matcher<Integer> matcher)
Evaluate the XPath and assert the number of nodes found with the given HamcrestMatcher
.ResultMatcher
nodeList(Matcher<? super NodeList> matcher)
ResultMatcher
number(Double expectedValue)
Evaluate the XPath and assert theDouble
value found.ResultMatcher
number(Matcher<? super Double> matcher)
ResultMatcher
string(String expectedValue)
Apply the XPath and assert theString
value found.ResultMatcher
string(Matcher<? super String> matcher)
Constructor Detail
XpathResultMatchers
protected XpathResultMatchers(String expression, @Nullable 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
- the XML namespaces referenced in the XPath expression, ornull
args
- 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)
nodeList
public ResultMatcher nodeList(Matcher<? super NodeList> matcher)
- Since:
- 5.2.2
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 theString
value found.
number
public ResultMatcher number(Matcher<? super Double> matcher)
number
public ResultMatcher number(Double expectedValue)
Evaluate the XPath and assert theDouble
value found.
booleanValue
public ResultMatcher booleanValue(Boolean value)
Evaluate the XPath and assert theBoolean
value found.