org.apache.commons.latka.validators
Class CookieValidator
java.lang.Object
org.apache.commons.latka.validators.BaseValidator
org.apache.commons.latka.validators.BaseConditionalValidator
org.apache.commons.latka.validators.CookieValidator
- All Implemented Interfaces:
- Validator
public class CookieValidator
- extends BaseConditionalValidator
CookieValidator validates cookie existence and/or value in an HTTP session.
- Version:
- $Id: CookieValidator.java 155424 2005-02-26 13:09:29Z dirkv $
- Author:
- Doug Sale, dIon Gillard
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 |
setCookieName(String name)
The cookie name must be set for this Validator to function properly. |
void |
setCookieValue(String value)
If cookie value is set, this Validator tests for cookie value equivalency, in addition to cookie existence |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
_cookieValue
protected String _cookieValue
_cookieName
protected String _cookieName
MESSAGE_INVALID_TEST
protected static final String MESSAGE_INVALID_TEST
- See Also:
- Constant Field Values
BARE_MESSAGE_EXISTENT_COOKIE
protected static final String BARE_MESSAGE_EXISTENT_COOKIE
- See Also:
- Constant Field Values
BARE_MESSAGE_EQUAL_VALUES
protected static final String BARE_MESSAGE_EQUAL_VALUES
- See Also:
- Constant Field Values
_lastTestedCookieValue
protected String _lastTestedCookieValue
CookieValidator
public CookieValidator()
CookieValidator
public CookieValidator(String label)
CookieValidator
public CookieValidator(String name,
String value)
CookieValidator
public CookieValidator(String label,
String name,
String value,
boolean condition)
setCookieValue
public void setCookieValue(String value)
- If cookie value is set, this
Validator
tests for cookie value equivalency, in addition to cookie existence
- Parameters:
value
- the value of the cookie
setCookieName
public void setCookieName(String name)
- The cookie name must be set for this
Validator
to function properly.
- Parameters:
name
- the name of the cookie
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
- if cookie name hasn't been set, the cookie doesn't exist in the session, or if cookie value has been set and the cookie values don't match
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.