Class WebValidatorBase

java.lang.Object
ee.jakarta.tck.ws.rs.common.webclient.validation.WebValidatorBase
All Implemented Interfaces:
ValidationStrategy
Direct Known Subclasses:
TokenizedValidator

public abstract class WebValidatorBase extends Object implements ValidationStrategy
Base abstract class for WebTestCase validation.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected WebTestCase
    The test case being validated
    protected HttpRequest
    This test case's HttpRequest
    protected HttpResponse
    This test case's HttpResponse
    protected static final char
    Used to detect 4xx class HTTP errors to allow fail fast situations when 4xx errors are not expected.
    protected static final char
    Used to detect 5xx class HTTP errors to allows fail fast situations when 5xx errors are not expected.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    checkExpectedHeaders will check the response for the configured expected headers.
    protected abstract boolean
    checkGoldenFile compare the server's response with the configured goldenfile Check the goldenfile
    protected boolean
    checkReasonPhrase will perform comparisons between the configued reason-phrase and that of the response.
    protected boolean
    checkSearchStrings will scan the response for the configured strings that are to be expected in the response.
    protected boolean
    checkSearchStringsNoCase will scan the response for the configured case insensitive strings that are to be expected in the response.
    protected boolean
    checkStatusCode will perform status code comparisons based on the algorithm below Check the HTTP status code
    protected boolean
    checkUnexpectedHeaders will check the response for the configured unexpected expected headers.
    protected boolean
    checkUnexpectedSearchStrings will scan the response for the configured strings that are not expected in the response.
    protected boolean
    checkUnorderedSearchStrings will scan the response for the configured strings that are to be expected in the response.
    protected boolean
    isEmpty(org.apache.commons.httpclient.Header[] headers)
    Utility method to determine of the expected or unexpected headers are empty or not.
    boolean
    validate Will validate the response against the configured TestCase.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CLIENT_ERROR

      protected static final char CLIENT_ERROR
      Used to detect 4xx class HTTP errors to allow fail fast situations when 4xx errors are not expected.
      See Also:
    • SERVER_ERROR

      protected static final char SERVER_ERROR
      Used to detect 5xx class HTTP errors to allows fail fast situations when 5xx errors are not expected.
      See Also:
    • _res

      protected HttpResponse _res
      This test case's HttpResponse
    • _req

      protected HttpRequest _req
      This test case's HttpRequest
    • _case

      protected WebTestCase _case
      The test case being validated
  • Constructor Details

    • WebValidatorBase

      public WebValidatorBase()
  • Method Details

    • validate

      public boolean validate(WebTestCase testCase)
      validate Will validate the response against the configured TestCase.
      • Check the HTTP status-code
      • Check the HTTP reason-phrase
      • Check for expected headers
      • Check from unexpected headers
      • Check expected search strings
      • Check unexpected search strings
      • Check the goldenfile
      Specified by:
      validate in interface ValidationStrategy
    • checkStatusCode

      protected boolean checkStatusCode() throws IOException
      checkStatusCode will perform status code comparisons based on the algorithm below
      • Check the HTTP status code
        • If status code is -1, then return true

        • If test case status code null and response 4xx, return failure, print error; return false

        • If test case status code null and response 5xx, return failure include response body; return false

        • If test case status code null, and response not 4xx or 5xx, return true

        • Test case status code not null, compare it with the response status code; return true if equal

      Returns:
      boolen result of check
      Throws:
      IOException - if an IO error occurs during validation
    • checkSearchStrings

      protected boolean checkSearchStrings() throws IOException
      checkSearchStrings will scan the response for the configured strings that are to be expected in the response.
      • Check search strings
        • If list of Strings is null, return true.

        • If list of Strings is not null, scan response body. If string is found, return true, otherwise display error and return false.

      NOTE: If there are multiple search strings, the search will be performed as such to preserve the order. For example, if the list of search strings contains two entities, the search for the second entity will be started after the index if the first match.
      Returns:
      boolen result of check
      Throws:
      IOException - if an IO error occurs during validation
    • checkSearchStringsNoCase

      protected boolean checkSearchStringsNoCase() throws IOException
      checkSearchStringsNoCase will scan the response for the configured case insensitive strings that are to be expected in the response.
      • Check search strings
        • If list of Strings is null, return true.

        • If list of Strings is not null, scan response body. If string is found, return true, otherwise display error and return false.

      NOTE: If there are multiple search strings, the search will be performed as such to preserve the order. For example, if the list of search strings contains two entities, the search for the second entity will be started after the index if the first match.
      Returns:
      boolen result of check
      Throws:
      IOException - if an IO error occurs during validation
    • checkUnorderedSearchStrings

      protected boolean checkUnorderedSearchStrings() throws IOException
      checkUnorderedSearchStrings will scan the response for the configured strings that are to be expected in the response.
      • Check search strings
        • If list of Strings is null, return true.

        • If list of Strings is not null, scan response body. If string is found, return true, otherwise display error and return false.

      Returns:
      boolen result of check
      Throws:
      IOException - if an IO error occurs during validation
    • checkUnexpectedSearchStrings

      protected boolean checkUnexpectedSearchStrings() throws IOException
      checkUnexpectedSearchStrings will scan the response for the configured strings that are not expected in the response.
      • Check unexpected search strings
        • If list of Strings is null, return true.

        • If list of Strings is not null, scan response body. If string is not found, return true, otherwise display error and return false.

      Returns:
      boolen result of check
      Throws:
      IOException - if an IO error occurs during validation
    • checkGoldenfile

      protected abstract boolean checkGoldenfile() throws IOException
      checkGoldenFile compare the server's response with the configured goldenfile
      • Check the goldenfile
        • If goldenfile is null, return true.

        • If goldenfile is not null, compare the goldenfile with the response. If equal, return true, otherwise display error and return false.

      Returns:
      boolen result of check
      Throws:
      IOException - if an IO error occurs during validation
    • checkReasonPhrase

      protected boolean checkReasonPhrase()
      checkReasonPhrase will perform comparisons between the configued reason-phrase and that of the response.
      • Check reason-phrase
        • If configured reason-phrase is null, return true.

        • If configured reason-phrase is not null, compare the reason-phrases with the response. If equal, return true, otherwise display error and return false.

      Returns:
      boolen result of check
    • checkExpectedHeaders

      protected boolean checkExpectedHeaders()
      checkExpectedHeaders will check the response for the configured expected headers.
      • Check expected headers
        • If there are no expected headers, return true.

        • If there are expected headers, scan the response for the expected headers. If all expected headers are found, return true, otherwise display an error and return false.

      Returns:
      boolen result of check
    • checkUnexpectedHeaders

      protected boolean checkUnexpectedHeaders()
      checkUnexpectedHeaders will check the response for the configured unexpected expected headers.
      • Check unexpected headers
        • If there are no configured unexpected headers, return true.

        • If there are configured unexpected headers, scan the response for the unexpected headers. If the headers are not found, return true, otherwise display an error and return false.

      Returns:
      boolen result of check
    • isEmpty

      protected boolean isEmpty(org.apache.commons.httpclient.Header[] headers)
      Utility method to determine of the expected or unexpected headers are empty or not.