org.apache.commons.latka.validators
Class XPathValidator
java.lang.Object
org.apache.commons.latka.validators.BaseValidator
org.apache.commons.latka.validators.BaseConditionalValidator
org.apache.commons.latka.validators.XPathValidator
- All Implemented Interfaces:
- Validator
public class XPathValidator
- extends BaseConditionalValidator
An XPath validator.
Use is of the form:
<xpath select="..." [ value="..." ] [ cond="true | false" ] />
Where :
select
is an XPath expression, designed to match a node in
the XML body of the response.
value
is an option value which the string value of the
selected node should match.
cond
is an optional boolean value, indicating
whether the test logic is to be inverted. Defaults to
true
.
If the user has specified a value
, then the XPath
expression is expected to evaluate to a text or attribute node (or other
textual 'leaf' nodes), in which case the selected value must match that
specified.
If no value is specified, then the XPath expression will be used to check for
the existence of a node.
If the XPath expression evaluates to a boolean condition (eg
<xpath select="foo/bar='baz'"/>), then the condition will be evaluated and will
result in the test passing or failing. Equivalently, an expression may be
specified, and value
used to require a specific value (eg
<xpath select="/foo/bar" value="baz"/>).
Finally, setting cond="false"
negates the sense of the
test, allowing one to test for the nonexistence or
inequality of nodes and values.
- Since:
- 6 January, 2001
- Version:
- $Id: XPathValidator.java 155424 2005-02-26 13:09:29Z dirkv $
- Author:
- Jeff Turner, dIon Gillard
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
_select
protected String _select
_value
protected String _value
_lastSelected
protected Object _lastSelected
XPathValidator
public XPathValidator()
XPathValidator
public XPathValidator(String label)
XPathValidator
public XPathValidator(String label,
String select,
boolean cond,
String value)
setSelect
public void setSelect(String select)
setValue
public void setValue(String value)
assertTrue
public boolean assertTrue(Response response)
throws ValidationException
- Description copied from class:
BaseConditionalValidator
- Return true or false, depending on whether or not
the test conditions were met. This
is regardless of the value of getCondition(),
which is handled elsewhere.
Note: this method
should _only_ throw ValidationExceptions under
exceptional circumstances (e.g. invalid regular
expressions, IOExceptions, etc). A successful test
should only return true or false.
- Specified by:
assertTrue
in class BaseConditionalValidator
- Parameters:
response
- HTTP response
- Returns:
- true if the test conditions were met, false otherwise
- Throws:
ValidationException
- when a validation fails
generateBareExceptionMessage
public String generateBareExceptionMessage()
- Description copied from class:
BaseConditionalValidator
- The BASE exception message for a subclass of
BaseConditionalValidator. Expect that the String
"EXPECTED" or "DID NOT EXPECT" will be prepended to
this message, depending on the value of getCondition().
For example, if you are validator attempts to match
regular expression x, this methods should
generate something like " TO MATCH REGULAR EXPRESSION
x.".
- Specified by:
generateBareExceptionMessage
in class BaseConditionalValidator
- Returns:
- bare exception message, to which will be prepended
"EXPECTED" or "DID NOT EXPECT"
Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.