public class HasXPath extends TypeSafeDiagnosingMatcher<org.w3c.dom.Node>
Modifier and Type | Field and Description |
---|---|
private javax.xml.xpath.XPathExpression |
compiledXPath |
private javax.xml.namespace.QName |
evaluationMode |
static javax.xml.namespace.NamespaceContext |
NO_NAMESPACE_CONTEXT |
private static Condition.Step<java.lang.Object,java.lang.String> |
NODE_EXISTS |
private Matcher<java.lang.String> |
valueMatcher |
private static IsAnything<java.lang.String> |
WITH_ANY_CONTENT |
private java.lang.String |
xpathString |
Modifier | Constructor and Description |
---|---|
|
HasXPath(java.lang.String xPathExpression,
Matcher<java.lang.String> valueMatcher) |
|
HasXPath(java.lang.String xPathExpression,
javax.xml.namespace.NamespaceContext namespaceContext,
Matcher<java.lang.String> valueMatcher) |
private |
HasXPath(java.lang.String xPathExpression,
javax.xml.namespace.NamespaceContext namespaceContext,
Matcher<java.lang.String> valueMatcher,
javax.xml.namespace.QName mode) |
Modifier and Type | Method and Description |
---|---|
private static javax.xml.xpath.XPathExpression |
compiledXPath(java.lang.String xPathExpression,
javax.xml.namespace.NamespaceContext namespaceContext) |
void |
describeTo(Description description)
Generates a description of the object.
|
private Condition<java.lang.Object> |
evaluated(org.w3c.dom.Node item,
Description mismatch) |
static Matcher<org.w3c.dom.Node> |
hasXPath(java.lang.String xPath)
Creates a matcher of
Node s that matches when the examined node contains a node
at the specified xPath , with any content. |
static Matcher<org.w3c.dom.Node> |
hasXPath(java.lang.String xPath,
Matcher<java.lang.String> valueMatcher)
Creates a matcher of
Node s that matches when the examined node has a value at the
specified xPath that satisfies the specified valueMatcher . |
static Matcher<org.w3c.dom.Node> |
hasXPath(java.lang.String xPath,
javax.xml.namespace.NamespaceContext namespaceContext)
Creates a matcher of
Node s that matches when the examined node contains a node
at the specified xPath within the specified namespace context, with any content. |
static Matcher<org.w3c.dom.Node> |
hasXPath(java.lang.String xPath,
javax.xml.namespace.NamespaceContext namespaceContext,
Matcher<java.lang.String> valueMatcher)
Creates a matcher of
Node s that matches when the examined node has a value at the
specified xPath , within the specified namespaceContext , that satisfies
the specified valueMatcher . |
boolean |
matchesSafely(org.w3c.dom.Node item,
Description mismatch)
Subclasses should implement this.
|
private static Condition.Step<java.lang.Object,java.lang.String> |
nodeExists() |
describeMismatch, matches
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
public static final javax.xml.namespace.NamespaceContext NO_NAMESPACE_CONTEXT
private static final IsAnything<java.lang.String> WITH_ANY_CONTENT
private static final Condition.Step<java.lang.Object,java.lang.String> NODE_EXISTS
private final Matcher<java.lang.String> valueMatcher
private final javax.xml.xpath.XPathExpression compiledXPath
private final java.lang.String xpathString
private final javax.xml.namespace.QName evaluationMode
public HasXPath(java.lang.String xPathExpression, Matcher<java.lang.String> valueMatcher)
xPathExpression
- XPath expression.valueMatcher
- Matcher to use at given XPath.
May be null to specify that the XPath must exist but the value is irrelevant.public HasXPath(java.lang.String xPathExpression, javax.xml.namespace.NamespaceContext namespaceContext, Matcher<java.lang.String> valueMatcher)
xPathExpression
- XPath expression.namespaceContext
- Resolves XML namespace prefixes in the XPath expressionvalueMatcher
- Matcher to use at given XPath.
May be null to specify that the XPath must exist but the value is irrelevant.private HasXPath(java.lang.String xPathExpression, javax.xml.namespace.NamespaceContext namespaceContext, Matcher<java.lang.String> valueMatcher, javax.xml.namespace.QName mode)
public boolean matchesSafely(org.w3c.dom.Node item, Description mismatch)
TypeSafeDiagnosingMatcher
matchesSafely
in class TypeSafeDiagnosingMatcher<org.w3c.dom.Node>
public void describeTo(Description description)
SelfDescribing
description
- The description to be built or appended to.private Condition<java.lang.Object> evaluated(org.w3c.dom.Node item, Description mismatch)
private static Condition.Step<java.lang.Object,java.lang.String> nodeExists()
private static javax.xml.xpath.XPathExpression compiledXPath(java.lang.String xPathExpression, javax.xml.namespace.NamespaceContext namespaceContext)
public static Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath, Matcher<java.lang.String> valueMatcher)
Node
s that matches when the examined node has a value at the
specified xPath
that satisfies the specified valueMatcher
.
For example:
assertThat(xml, hasXPath("/root/something[2]/cheese", equalTo("Cheddar")))
xPath
- the target xpathvalueMatcher
- matcher for the value at the specified xpathpublic static Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath, javax.xml.namespace.NamespaceContext namespaceContext, Matcher<java.lang.String> valueMatcher)
Node
s that matches when the examined node has a value at the
specified xPath
, within the specified namespaceContext
, that satisfies
the specified valueMatcher
.
For example:
assertThat(xml, hasXPath("/root/something[2]/cheese", myNs, equalTo("Cheddar")))
xPath
- the target xpathnamespaceContext
- the namespace for matching nodesvalueMatcher
- matcher for the value at the specified xpathpublic static Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath)
Node
s that matches when the examined node contains a node
at the specified xPath
, with any content.
For example:
assertThat(xml, hasXPath("/root/something[2]/cheese"))
xPath
- the target xpathpublic static Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath, javax.xml.namespace.NamespaceContext namespaceContext)
Node
s that matches when the examined node contains a node
at the specified xPath
within the specified namespace context, with any content.
For example:
assertThat(xml, hasXPath("/root/something[2]/cheese", myNs))
xPath
- the target xpathnamespaceContext
- the namespace for matching nodes