org.apache.commons.latka.validators
Class XPathValidator

java.lang.Object
  extended by org.apache.commons.latka.validators.BaseValidator
      extended by org.apache.commons.latka.validators.BaseConditionalValidator
          extended by 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 :

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

Field Summary
protected  Object _lastSelected
           
protected  String _select
           
protected  String _value
           
 
Fields inherited from class org.apache.commons.latka.validators.BaseConditionalValidator
_condition, _log
 
Fields inherited from class org.apache.commons.latka.validators.BaseValidator
_label
 
Constructor Summary
XPathValidator()
           
XPathValidator(String label)
           
XPathValidator(String label, String select, boolean cond, String value)
           
 
Method Summary
 boolean assertTrue(Response response)
          Return true or false, depending on whether or not the test conditions were met.
 String generateBareExceptionMessage()
          The BASE exception message for a subclass of BaseConditionalValidator.
 void setSelect(String select)
           
 void setValue(String value)
           
 
Methods inherited from class org.apache.commons.latka.validators.BaseConditionalValidator
getCondition, setCondition, throwValidationException, validate
 
Methods inherited from class org.apache.commons.latka.validators.BaseValidator
fail, getLabel, setLabel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_select

protected String _select

_value

protected String _value

_lastSelected

protected Object _lastSelected
Constructor Detail

XPathValidator

public XPathValidator()

XPathValidator

public XPathValidator(String label)

XPathValidator

public XPathValidator(String label,
                      String select,
                      boolean cond,
                      String value)
Method Detail

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.