org.apache.commons.latka.validators
Class ResponseHeaderValidator

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

public class ResponseHeaderValidator
extends BaseConditionalValidator

ResponseHeaderValidator validates response headers in an HTTP session. Setting just the header name tests for the existence of a header. If you set the headerValue and there is more than one header of that name, the validator matches on ANY header with that value.

Author:
Morgan Delagrange

Field Summary
protected  String _actualValue
           
protected  boolean _checkValue
           
protected  String _headerName
           
protected  String _headerValue
           
protected static String BARE_MESSAGE_EQUAL_VALUES
           
protected static String BARE_MESSAGE_EXISTENT_HEADER
           
 
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
ResponseHeaderValidator(String headerName)
          Constructs a validator for the given header with no label.
ResponseHeaderValidator(String label, String headerName)
          Constructs a labeled validator for the given header
ResponseHeaderValidator(String label, String headerName, boolean condition)
          Constructs a labeled validator for the given header
 
Method Summary
 boolean assertTrue(Response response)
          Checks to see that the header exists, and also checks its value if setHeaderValue(String) has been called
 String generateBareExceptionMessage()
          The BASE exception message for a subclass of BaseConditionalValidator.
 void setHeaderValue(String headerValue)
          Sets the desired value of the header to be validated.
 
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

_headerName

protected String _headerName

_headerValue

protected String _headerValue

_checkValue

protected boolean _checkValue

BARE_MESSAGE_EXISTENT_HEADER

protected static final String BARE_MESSAGE_EXISTENT_HEADER
See Also:
Constant Field Values

BARE_MESSAGE_EQUAL_VALUES

protected static final String BARE_MESSAGE_EQUAL_VALUES
See Also:
Constant Field Values

_actualValue

protected String _actualValue
Constructor Detail

ResponseHeaderValidator

public ResponseHeaderValidator(String headerName)
Constructs a validator for the given header with no label.

Parameters:
headerName - Name of the header to validate

ResponseHeaderValidator

public ResponseHeaderValidator(String label,
                               String headerName)
Constructs a labeled validator for the given header

Parameters:
label - name of the header to validate
headerName -

ResponseHeaderValidator

public ResponseHeaderValidator(String label,
                               String headerName,
                               boolean condition)
Constructs a labeled validator for the given header

Parameters:
label - name of the header to validate
headerName -
Method Detail

setHeaderValue

public void setHeaderValue(String headerValue)
Sets the desired value of the header to be validated. If this method is not called, then the validator will only check for the existence of the header and disregard its value.

Parameters:
headerValue - desired value of the header, or null to look for a header with the String value "null"

assertTrue

public boolean assertTrue(Response response)
                   throws ValidationException
Checks to see that the header exists, and also checks its value if setHeaderValue(String) has been called

Specified by:
assertTrue in class BaseConditionalValidator
Parameters:
response - The HTTP response to validate
Returns:
true if the test conditions were met, false otherwise
Throws:
ValidationException - if the header does not meet the criteria of the test

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.