Class RegexpValidator

  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:

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.

$Id: 155424 2005-02-26 13:09:29Z dirkv $
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
Constructor Summary
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

Field Detail


protected String _pattern


protected boolean _ignoreCase


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


public RegexpValidator()


public RegexpValidator(String label)


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


public void setPattern(String pattern)


public void setIgnoreCase(boolean ignoreCase)


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
response - HTTP response
true if the test conditions were met, false otherwise
ValidationException - when a validation fails


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
bare exception message, to which will be prepended "EXPECTED" or "DID NOT EXPECT"

Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.