public class XpathExpectationsHelper extends Object
Constructor and Description |
---|
XpathExpectationsHelper(String expression,
Map<String,String> namespaces,
Object... args)
XpathExpectationsHelper constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
assertBoolean(byte[] content,
String encoding,
boolean expectedValue)
Apply the XPath expression and assert the resulting content as a Boolean.
|
void |
assertNode(byte[] content,
String encoding,
Matcher<? super Node> matcher)
Parse the content, evaluate the XPath expression as a
Node ,
and assert it with the given Matcher<Node> . |
void |
assertNodeCount(byte[] content,
String encoding,
int expectedCount)
Apply the XPath expression and assert the resulting content as an integer.
|
void |
assertNodeCount(byte[] content,
String encoding,
Matcher<Integer> matcher)
Apply the XPath expression and assert the resulting content with the
given Hamcrest matcher.
|
void |
assertNodeList(byte[] content,
String encoding,
Matcher<? super NodeList> matcher)
Parse the content, evaluate the XPath expression as a
NodeList ,
and assert it with the given Matcher<NodeList> . |
void |
assertNumber(byte[] content,
String encoding,
Double expectedValue)
Apply the XPath expression and assert the resulting content as a Double.
|
void |
assertNumber(byte[] content,
String encoding,
Matcher<? super Double> matcher)
Apply the XPath expression and assert the resulting content with the
given Hamcrest matcher.
|
void |
assertString(byte[] content,
String encoding,
Matcher<? super String> matcher)
Apply the XPath expression and assert the resulting content with the
given Hamcrest matcher.
|
void |
assertString(byte[] content,
String encoding,
String expectedValue)
Apply the XPath expression and assert the resulting content as a String.
|
void |
doesNotExist(byte[] content,
String encoding)
Apply the XPath expression and assert the resulting content does not exist.
|
<T> T |
evaluateXpath(byte[] content,
String encoding,
Class<T> targetClass)
Evaluate the XPath and return the resulting value.
|
protected <T> T |
evaluateXpath(Document document,
QName evaluationType,
Class<T> expectedClass)
Apply the XPath expression to given document.
|
void |
exists(byte[] content,
String encoding)
Apply the XPath expression and assert the resulting content exists.
|
protected XPathExpression |
getXpathExpression()
Return the compiled XPath expression.
|
protected Document |
parseXmlByteArray(byte[] xml,
String encoding)
Parse the given XML content to a
Document . |
public XpathExpectationsHelper(String expression, @Nullable Map<String,String> namespaces, Object... args) throws XPathExpressionException
expression
- the XPath expressionnamespaces
- the XML namespaces referenced in the XPath expression, or null
args
- arguments to parameterize the XPath expression with using the
formatting specifiers defined in String.format(String, Object...)
XPathExpressionException
- if expression compilation failedprotected XPathExpression getXpathExpression()
public void assertNode(byte[] content, @Nullable String encoding, Matcher<? super Node> matcher) throws Exception
Node
,
and assert it with the given Matcher<Node>
.Exception
public void assertNodeList(byte[] content, @Nullable String encoding, Matcher<? super NodeList> matcher) throws Exception
NodeList
,
and assert it with the given Matcher<NodeList>
.Exception
public void exists(byte[] content, @Nullable String encoding) throws Exception
Exception
- if content parsing or expression evaluation failspublic void doesNotExist(byte[] content, @Nullable String encoding) throws Exception
Exception
- if content parsing or expression evaluation failspublic void assertNodeCount(byte[] content, @Nullable String encoding, Matcher<Integer> matcher) throws Exception
Exception
- if content parsing or expression evaluation failspublic void assertNodeCount(byte[] content, @Nullable String encoding, int expectedCount) throws Exception
Exception
- if content parsing or expression evaluation failspublic void assertString(byte[] content, @Nullable String encoding, Matcher<? super String> matcher) throws Exception
Exception
- if content parsing or expression evaluation failspublic void assertString(byte[] content, @Nullable String encoding, String expectedValue) throws Exception
Exception
- if content parsing or expression evaluation failspublic void assertNumber(byte[] content, @Nullable String encoding, Matcher<? super Double> matcher) throws Exception
Exception
- if content parsing or expression evaluation failspublic void assertNumber(byte[] content, @Nullable String encoding, Double expectedValue) throws Exception
Exception
- if content parsing or expression evaluation failspublic void assertBoolean(byte[] content, @Nullable String encoding, boolean expectedValue) throws Exception
Exception
- if content parsing or expression evaluation fails@Nullable public <T> T evaluateXpath(byte[] content, @Nullable String encoding, Class<T> targetClass) throws Exception
content
- the content to evaluate againstencoding
- the encoding to use (optionally)targetClass
- the target class, one of Number, String, Boolean,
org.w3c.Node, or NodeListException
- if content parsing or expression evaluation failsprotected Document parseXmlByteArray(byte[] xml, @Nullable String encoding) throws Exception
Document
.xml
- the content to parseencoding
- optional content encoding, if provided as metadata (e.g. in HTTP headers)Exception
@Nullable protected <T> T evaluateXpath(Document document, QName evaluationType, Class<T> expectedClass) throws XPathExpressionException
XPathExpressionException
- if expression evaluation failed