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.
|
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
- 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
protected 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 failedpublic 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