类 XpathExpectationsHelper
- java.lang.Object
- org.springframework.test.util.XpathExpectationsHelper
public class XpathExpectationsHelper extends Object
A helper class for applying assertions via XPath expressions.- 从以下版本开始:
- 3.2
- 作者:
- Rossen Stoyanchev
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidassertBoolean(byte[] content, String encoding, boolean expectedValue)Apply the XPath expression and assert the resulting content as a Boolean.voidassertNode(byte[] content, String encoding, Matcher<? super Node> matcher)Parse the content, evaluate the XPath expression as aNode, and assert it with the givenMatcher<Node>.voidassertNodeCount(byte[] content, String encoding, int expectedCount)Apply the XPath expression and assert the resulting content as an integer.voidassertNodeCount(byte[] content, String encoding, Matcher<Integer> matcher)Apply the XPath expression and assert the resulting content with the given Hamcrest matcher.voidassertNumber(byte[] content, String encoding, Double expectedValue)Apply the XPath expression and assert the resulting content as a Double.voidassertNumber(byte[] content, String encoding, Matcher<? super Double> matcher)Apply the XPath expression and assert the resulting content with the given Hamcrest matcher.voidassertString(byte[] content, String encoding, String expectedValue)Apply the XPath expression and assert the resulting content as a String.voidassertString(byte[] content, String encoding, Matcher<? super String> matcher)Apply the XPath expression and assert the resulting content with the given Hamcrest matcher.voiddoesNotExist(byte[] content, String encoding)Apply the XPath expression and assert the resulting content does not exist.protected <T> TevaluateXpath(Document document, QName evaluationType, Class<T> expectedClass)Apply the XPath expression to given document.voidexists(byte[] content, String encoding)Apply the XPath expression and assert the resulting content exists.protected XPathExpressiongetXpathExpression()Return the compiled XPath expression.protected DocumentparseXmlByteArray(byte[] xml, String encoding)Parse the given XML content to aDocument.
构造器详细资料
XpathExpectationsHelper
public XpathExpectationsHelper(String expression, Map<String,String> namespaces, Object... args) throws XPathExpressionException
XpathExpectationsHelper constructor.- 参数:
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...)- 抛出:
XPathExpressionException- if expression compilation failed
方法详细资料
getXpathExpression
protected XPathExpression getXpathExpression()
Return the compiled XPath expression.
assertNode
public void assertNode(byte[] content, String encoding, Matcher<? super Node> matcher) throws Exception
Parse the content, evaluate the XPath expression as aNode, and assert it with the givenMatcher<Node>.- 抛出:
Exception
parseXmlByteArray
protected Document parseXmlByteArray(byte[] xml, String encoding) throws Exception
Parse the given XML content to aDocument.- 参数:
xml- the content to parseencoding- optional content encoding, if provided as metadata (e.g. in HTTP headers)- 返回:
- the parsed document
- 抛出:
Exception
evaluateXpath
protected <T> T evaluateXpath(Document document, QName evaluationType, Class<T> expectedClass) throws XPathExpressionException
Apply the XPath expression to given document.- 抛出:
XPathExpressionException- if expression evaluation failed
exists
public void exists(byte[] content, String encoding) throws Exception
Apply the XPath expression and assert the resulting content exists.- 抛出:
Exception- if content parsing or expression evaluation fails
doesNotExist
public void doesNotExist(byte[] content, String encoding) throws Exception
Apply the XPath expression and assert the resulting content does not exist.- 抛出:
Exception- if content parsing or expression evaluation fails
assertNodeCount
public void assertNodeCount(byte[] content, String encoding, Matcher<Integer> matcher) throws Exception
Apply the XPath expression and assert the resulting content with the given Hamcrest matcher.- 抛出:
Exception- if content parsing or expression evaluation fails
assertNodeCount
public void assertNodeCount(byte[] content, String encoding, int expectedCount) throws Exception
Apply the XPath expression and assert the resulting content as an integer.- 抛出:
Exception- if content parsing or expression evaluation fails
assertString
public void assertString(byte[] content, String encoding, Matcher<? super String> matcher) throws Exception
Apply the XPath expression and assert the resulting content with the given Hamcrest matcher.- 抛出:
Exception- if content parsing or expression evaluation fails
assertString
public void assertString(byte[] content, String encoding, String expectedValue) throws Exception
Apply the XPath expression and assert the resulting content as a String.- 抛出:
Exception- if content parsing or expression evaluation fails
assertNumber
public void assertNumber(byte[] content, String encoding, Matcher<? super Double> matcher) throws Exception
Apply the XPath expression and assert the resulting content with the given Hamcrest matcher.- 抛出:
Exception- if content parsing or expression evaluation fails
assertNumber
public void assertNumber(byte[] content, String encoding, Double expectedValue) throws Exception
Apply the XPath expression and assert the resulting content as a Double.- 抛出:
Exception- if content parsing or expression evaluation fails
assertBoolean
public void assertBoolean(byte[] content, String encoding, boolean expectedValue) throws Exception
Apply the XPath expression and assert the resulting content as a Boolean.- 抛出:
Exception- if content parsing or expression evaluation fails