public class XpathExpectationsHelper
extends java.lang.Object
Constructor and Description |
---|
XpathExpectationsHelper(java.lang.String expression,
java.util.Map<java.lang.String,java.lang.String> namespaces,
java.lang.Object... args)
XpathExpectationsHelper constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
assertBoolean(byte[] content,
java.lang.String encoding,
boolean expectedValue)
Apply the XPath expression and assert the resulting content as a Boolean.
|
void |
assertNode(byte[] content,
java.lang.String encoding,
org.hamcrest.Matcher<? super org.w3c.dom.Node> matcher)
Parse the content, evaluate the XPath expression as a
Node ,
and assert it with the given Matcher<Node> . |
void |
assertNodeCount(byte[] content,
java.lang.String encoding,
int expectedCount)
Apply the XPath expression and assert the resulting content as an integer.
|
void |
assertNodeCount(byte[] content,
java.lang.String encoding,
org.hamcrest.Matcher<java.lang.Integer> matcher)
Apply the XPath expression and assert the resulting content with the
given Hamcrest matcher.
|
void |
assertNumber(byte[] content,
java.lang.String encoding,
java.lang.Double expectedValue)
Apply the XPath expression and assert the resulting content as a Double.
|
void |
assertNumber(byte[] content,
java.lang.String encoding,
org.hamcrest.Matcher<? super java.lang.Double> matcher)
Apply the XPath expression and assert the resulting content with the
given Hamcrest matcher.
|
void |
assertString(byte[] content,
java.lang.String encoding,
org.hamcrest.Matcher<? super java.lang.String> matcher)
Apply the XPath expression and assert the resulting content with the
given Hamcrest matcher.
|
void |
assertString(byte[] content,
java.lang.String encoding,
java.lang.String expectedValue)
Apply the XPath expression and assert the resulting content as a String.
|
void |
doesNotExist(byte[] content,
java.lang.String encoding)
Apply the XPath expression and assert the resulting content does not exist.
|
<T> T |
evaluateXpath(byte[] content,
java.lang.String encoding,
java.lang.Class<T> targetClass)
Evaluate the XPath and return the resulting value.
|
protected <T> T |
evaluateXpath(org.w3c.dom.Document document,
QName evaluationType,
java.lang.Class<T> expectedClass)
Apply the XPath expression to given document.
|
void |
exists(byte[] content,
java.lang.String encoding)
Apply the XPath expression and assert the resulting content exists.
|
protected javax.xml.xpath.XPathExpression |
getXpathExpression()
Return the compiled XPath expression.
|
protected org.w3c.dom.Document |
parseXmlByteArray(byte[] xml,
java.lang.String encoding)
Parse the given XML content to a
Document . |
public XpathExpectationsHelper(java.lang.String expression, @Nullable java.util.Map<java.lang.String,java.lang.String> namespaces, java.lang.Object... args) throws javax.xml.xpath.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...)
javax.xml.xpath.XPathExpressionException
- if expression compilation failedprotected javax.xml.xpath.XPathExpression getXpathExpression()
public void assertNode(byte[] content, @Nullable java.lang.String encoding, org.hamcrest.Matcher<? super org.w3c.dom.Node> matcher) throws java.lang.Exception
Node
,
and assert it with the given Matcher<Node>
.java.lang.Exception
public void exists(byte[] content, @Nullable java.lang.String encoding) throws java.lang.Exception
java.lang.Exception
- if content parsing or expression evaluation failspublic void doesNotExist(byte[] content, @Nullable java.lang.String encoding) throws java.lang.Exception
java.lang.Exception
- if content parsing or expression evaluation failspublic void assertNodeCount(byte[] content, @Nullable java.lang.String encoding, org.hamcrest.Matcher<java.lang.Integer> matcher) throws java.lang.Exception
java.lang.Exception
- if content parsing or expression evaluation failspublic void assertNodeCount(byte[] content, @Nullable java.lang.String encoding, int expectedCount) throws java.lang.Exception
java.lang.Exception
- if content parsing or expression evaluation failspublic void assertString(byte[] content, @Nullable java.lang.String encoding, org.hamcrest.Matcher<? super java.lang.String> matcher) throws java.lang.Exception
java.lang.Exception
- if content parsing or expression evaluation failspublic void assertString(byte[] content, @Nullable java.lang.String encoding, java.lang.String expectedValue) throws java.lang.Exception
java.lang.Exception
- if content parsing or expression evaluation failspublic void assertNumber(byte[] content, @Nullable java.lang.String encoding, org.hamcrest.Matcher<? super java.lang.Double> matcher) throws java.lang.Exception
java.lang.Exception
- if content parsing or expression evaluation failspublic void assertNumber(byte[] content, @Nullable java.lang.String encoding, java.lang.Double expectedValue) throws java.lang.Exception
java.lang.Exception
- if content parsing or expression evaluation failspublic void assertBoolean(byte[] content, @Nullable java.lang.String encoding, boolean expectedValue) throws java.lang.Exception
java.lang.Exception
- if content parsing or expression evaluation fails@Nullable public <T> T evaluateXpath(byte[] content, @Nullable java.lang.String encoding, java.lang.Class<T> targetClass) throws java.lang.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 NodeListjava.lang.Exception
- if content parsing or expression evaluation failsprotected org.w3c.dom.Document parseXmlByteArray(byte[] xml, @Nullable java.lang.String encoding) throws java.lang.Exception
Document
.xml
- the content to parseencoding
- optional content encoding, if provided as metadata (e.g. in HTTP headers)java.lang.Exception
@Nullable protected <T> T evaluateXpath(org.w3c.dom.Document document, QName evaluationType, java.lang.Class<T> expectedClass) throws javax.xml.xpath.XPathExpressionException
javax.xml.xpath.XPathExpressionException
- if expression evaluation failed