org.hamcrest.xml
Class HasXPath
java.lang.Object
org.hamcrest.BaseMatcher<T>
org.hamcrest.TypeSafeDiagnosingMatcher<org.w3c.dom.Node>
org.hamcrest.xml.HasXPath
- All Implemented Interfaces:
- org.hamcrest.Matcher<org.w3c.dom.Node>, org.hamcrest.SelfDescribing
public class HasXPath
- extends org.hamcrest.TypeSafeDiagnosingMatcher<org.w3c.dom.Node>
Applies a Matcher to a given XML Node in an existing XML Node tree, specified by an XPath expression.
- Author:
- Joe Walnes, Steve Freeman
Constructor Summary |
HasXPath(java.lang.String xPathExpression,
org.hamcrest.Matcher<java.lang.String> valueMatcher)
|
HasXPath(java.lang.String xPathExpression,
javax.xml.namespace.NamespaceContext namespaceContext,
org.hamcrest.Matcher<java.lang.String> valueMatcher)
|
Method Summary |
void |
describeTo(org.hamcrest.Description description)
|
static org.hamcrest.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 org.hamcrest.Matcher<org.w3c.dom.Node> |
hasXPath(java.lang.String xPath,
org.hamcrest.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 org.hamcrest.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 org.hamcrest.Matcher<org.w3c.dom.Node> |
hasXPath(java.lang.String xPath,
javax.xml.namespace.NamespaceContext namespaceContext,
org.hamcrest.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,
org.hamcrest.Description mismatch)
|
Methods inherited from class org.hamcrest.TypeSafeDiagnosingMatcher |
describeMismatch, matches |
Methods inherited from class org.hamcrest.BaseMatcher |
_dont_implement_Matcher___instead_extend_BaseMatcher_, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
NO_NAMESPACE_CONTEXT
public static final javax.xml.namespace.NamespaceContext NO_NAMESPACE_CONTEXT
HasXPath
public HasXPath(java.lang.String xPathExpression,
org.hamcrest.Matcher<java.lang.String> valueMatcher)
- Parameters:
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.
HasXPath
public HasXPath(java.lang.String xPathExpression,
javax.xml.namespace.NamespaceContext namespaceContext,
org.hamcrest.Matcher<java.lang.String> valueMatcher)
- Parameters:
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.
matchesSafely
public boolean matchesSafely(org.w3c.dom.Node item,
org.hamcrest.Description mismatch)
- Specified by:
matchesSafely
in class org.hamcrest.TypeSafeDiagnosingMatcher<org.w3c.dom.Node>
describeTo
public void describeTo(org.hamcrest.Description description)
hasXPath
public static org.hamcrest.Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath,
org.hamcrest.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
.
For example:
assertThat(xml, hasXPath("/root/something[2]/cheese", equalTo("Cheddar")))
- Parameters:
xPath
- the target xpathvalueMatcher
- matcher for the value at the specified xpath
hasXPath
public static org.hamcrest.Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath,
javax.xml.namespace.NamespaceContext namespaceContext,
org.hamcrest.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
.
For example:
assertThat(xml, hasXPath("/root/something[2]/cheese", myNs, equalTo("Cheddar")))
- Parameters:
xPath
- the target xpathnamespaceContext
- the namespace for matching nodesvalueMatcher
- matcher for the value at the specified xpath
hasXPath
public static org.hamcrest.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.
For example:
assertThat(xml, hasXPath("/root/something[2]/cheese"))
- Parameters:
xPath
- the target xpath
hasXPath
public static org.hamcrest.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.
For example:
assertThat(xml, hasXPath("/root/something[2]/cheese", myNs))
- Parameters:
xPath
- the target xpathnamespaceContext
- the namespace for matching nodes