org.apache.commons.latka.validators
Class RegexpValidator

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.RegexpValidator
All Implemented Interfaces:
Validator

public class RegexpValidator
extends BaseConditionalValidator
implements Validator

Perform regular expression matches on the body of the HTTP response. Setting the "condition" attribute of the test indicates whether or not a match is expected. If the server returns a null (e.g. in the case of an empty HEAD response), the validator will always fail, regardless of the setting of the "condition" attribute.

Version:
$Id: RegexpValidator.java 155424 2005-02-26 13:09:29Z dirkv $
Author:
Morgan Delagrange, dIon Gillard

Field Summary
protected  boolean _ignoreCase
           
protected  String _pattern
           
protected static String BARE_EXCEPTION_MESSAGE
           
 
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
RegexpValidator()
           
RegexpValidator(String label)
           
RegexpValidator(String label, String pattern, boolean cond, boolean ignoreCase)
           
 
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 setIgnoreCase(boolean ignoreCase)
           
 void setPattern(String pattern)
           
 
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
 
Methods inherited from interface org.apache.commons.latka.Validator
validate
 

Field Detail

_pattern

protected String _pattern

_ignoreCase

protected boolean _ignoreCase

BARE_EXCEPTION_MESSAGE

protected static final String BARE_EXCEPTION_MESSAGE
See Also:
Constant Field Values
Constructor Detail

RegexpValidator

public RegexpValidator()

RegexpValidator

public RegexpValidator(String label)

RegexpValidator

public RegexpValidator(String label,
                       String pattern,
                       boolean cond,
                       boolean ignoreCase)
Method Detail

setPattern

public void setPattern(String pattern)

setIgnoreCase

public void setIgnoreCase(boolean ignoreCase)

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.