Class WebTestCase

java.lang.Object
ee.jakarta.tck.ws.rs.common.webclient.WebTestCase
All Implemented Interfaces:
TestCase
Direct Known Subclasses:
JaxrsWebTestCase

public class WebTestCase extends Object implements TestCase
A TestCase implementation for HTTP-based testing. This allows the user to set criteria for test success which will be compared against the response from the server.
  • Field Details

    • TOKENIZED_STRATEGY

      public static final String TOKENIZED_STRATEGY
      Tokenized response validation strategy
      See Also:
    • WHITESPACE_STRATEGY

      public static final String WHITESPACE_STRATEGY
      Whitespace response validation strategy
      See Also:
  • Constructor Details

    • WebTestCase

      public WebTestCase()
      Creates a new instance of WebTestCase By default, a new WebTestCase instance will use the TokenizedValidator to verify the response with the configured properties of the test case.
  • Method Details

    • execute

      public void execute() throws TestFailureException
      Executes the test case.
      Specified by:
      execute in interface TestCase
      Throws:
      TestFailureException - if the test fails for any reason.
      IllegalStateException - if no request was configured or if no Validator is available at runtime.
    • setExpectedStatusCode

      public void setExpectedStatusCode(String statusCode)
      Sets the status code to be expected in the response from the server, i.e. 500 or 404, etc.
      Parameters:
      statusCode - the expected status code
    • setExpectedReasonPhrase

      public void setExpectedReasonPhrase(String reasonPhrase)
      Sets the reason phrase to be expected in the response from the server.
      Parameters:
      reasonPhrase - the expected reason-phrase
    • addExpectedHeader

      public void addExpectedHeader(String header)
      Adds a header that is to be expected in the response from the server.
      Parameters:
      header - in the format of : (test:foo)
    • setGoldenFilePath

      public void setGoldenFilePath(String gfPath)
      Sets the path to the goldenfile the test case should use.
      Parameters:
      gfPath - a fully qualified path including filename.
    • setRequest

      public void setRequest(HttpRequest request)
      Sets the request that should be dispatched by this test case.
      Parameters:
      request - the HTTP request used for this test case
    • addUnexpectedHeader

      public void addUnexpectedHeader(String header)
      Adds a header that is should not be in the server's response.
      Parameters:
      header - in the format of : (test:foo)
    • setAssertNoResponseBody

      public void setAssertNoResponseBody(boolean value)
      Enables/Disables an assertion that a response body is present.
      Parameters:
      value - a value of true will enable the assertion.
    • setResponseSearchString

      public void setResponseSearchString(String searchString)
      Sets a string that will be scanned for and expected in the response body from the server. If multiple search strings are required, one can either call this method for each string, or pass in one string with pipe | delimiting the individual search strings within the large string.
      Parameters:
      searchString - a string expected in the server's response body
    • setResponseSearchStringIgnoreCase

      public void setResponseSearchStringIgnoreCase(String searchString)
      Sets a string that will be scanned for and expected in the response body from the server. If multiple search strings are required, one can either call this method for each string, or pass in one string with pipe | delimiting the individual search strings within the large string.
      Parameters:
      searchString - a case insensitive string expected in the server's response body
    • setUnexpectedResponseSearchString

      public void setUnexpectedResponseSearchString(String searchString)
      Sets a string that will be scanned for and should not be present in the response body from the server. If multiple search strings are required, one can either call this method for each string, or pass in one string with pipe | delimiting the individual search strings within the large string.
      Parameters:
      searchString - a string that is not expected in the server's response body
    • setUnorderedSearchString

      public void setUnorderedSearchString(String searchString)
      Sets a string or series of strings that will be searched for in the response. If multiple search strings are required, one can either call this method for each string, or pass in one string with pipe | delimiting the individual search strings within the large string.
      Parameters:
      searchString - a string that is not expected in the server's response body
    • getUnorderedSearchStrings

      public List<String> getUnorderedSearchStrings()
      Returns the list of search strings.
      Returns:
      the list of search strings.
    • getResponse

      public HttpResponse getResponse()
      Returns the response for this particular test case.
      Returns:
      an HttpResponse object
    • getExpectedHeaders

      public org.apache.commons.httpclient.Header[] getExpectedHeaders()
      Returns an array of Header objects that are expected to be found in the responst.
      Returns:
      an array of headers
    • getUnexpectedHeaders

      public org.apache.commons.httpclient.Header[] getUnexpectedHeaders()
      Returns an array of Header objects that are not expected to be found in the responst.
      Returns:
      an array of headers
    • getStatusCode

      public String getStatusCode()
      Returns the status code expected to be found in the server's response
      Returns:
      status code
    • getReasonPhrase

      public String getReasonPhrase()
      Returns the reason phrase that is expected to be found in the server's response.
      Returns:
      reason phrase
    • getSearchStrings

      public List<String> getSearchStrings()
      Returns the configured list of strings that will be used when scanning the server's response.
      Returns:
      list of Strings
    • getSearchStringsNoCase

      public List<String> getSearchStringsNoCase()
      Returns the configured list of strings that will be used when scanning the server's response.
      Returns:
      list of case insensitive Strings
    • getUnexpectedSearchStrings

      public List<String> getUnexpectedSearchStrings()
      Returns the configured list of strings that will be used when scanning the server's response (these strings are not expected in the response).
      Returns:
      list of Strings
    • getExpectResponseBody

      public boolean getExpectResponseBody()
      Returns an indicator on whether a response body is expected or not.
      Returns:
      boolean value
    • getRequest

      public HttpRequest getRequest()
      Returns the HttpRequest for this particular test case.
      Returns:
      HttpRequest of this test case
    • getGoldenfilePath

      public String getGoldenfilePath()
      Returns the path to the goldenfile.
      Returns:
      path to the goldenfile
    • getState

      public Object getState()
      Returns the state for this particular test case.
      Specified by:
      getState in interface TestCase
      Returns:
      test state
    • setState

      public void setState(Object state)
      Sets the state for this test case.
      Specified by:
      setState in interface TestCase
      Parameters:
      state - test state
    • setName

      public void setName(String name)
      Sets a logical name for this test case.
      Specified by:
      setName in interface TestCase
      Parameters:
      name - the logical name for this test
    • getName

      public String getName()
      Returns the logical name for this test case.
      Specified by:
      getName in interface TestCase
      Returns:
      test name
    • setStrategy

      public void setStrategy(String validator)
      Sets the validation strategy for this test case instance.
      Parameters:
      validator - - the fully qualified class name of the response validator to use.
    • getStrategy

      public String getStrategy()
      Returns the class name of the response validator used.
      Returns:
      the fully qualified class of the validator used