Class WebTestCase
java.lang.Object
ee.jakarta.tck.ws.rs.common.webclient.WebTestCase
- All Implemented Interfaces:
TestCase
- Direct Known Subclasses:
JaxrsWebTestCase
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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 Summary
Modifier and TypeMethodDescriptionvoid
addExpectedHeader
(String header) Adds a header that is to be expected in the response from the server.void
addUnexpectedHeader
(String header) Adds a header that is should not be in the server's response.void
execute()
Executes the test case.org.apache.commons.httpclient.Header[]
Returns an array of Header objects that are expected to be found in the responst.boolean
Returns an indicator on whether a response body is expected or not.Returns the path to the goldenfile.getName()
Returns the logical name for this test case.Returns the reason phrase that is expected to be found in the server's response.Returns the HttpRequest for this particular test case.Returns the response for this particular test case.Returns the configured list of strings that will be used when scanning the server's response.Returns the configured list of strings that will be used when scanning the server's response.getState()
Returns the state for this particular test case.Returns the status code expected to be found in the server's responseReturns the class name of the response validator used.org.apache.commons.httpclient.Header[]
Returns an array of Header objects that are not expected to be found in the responst.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 the list of search strings.void
setAssertNoResponseBody
(boolean value) Enables/Disables an assertion that a response body is present.void
setExpectedReasonPhrase
(String reasonPhrase) Sets the reason phrase to be expected in the response from the server.void
setExpectedStatusCode
(String statusCode) Sets the status code to be expected in the response from the server, i.e.void
setGoldenFilePath
(String gfPath) Sets the path to the goldenfile the test case should use.void
Sets a logical name for this test case.void
setRequest
(HttpRequest request) Sets the request that should be dispatched by this test case.void
setResponseSearchString
(String searchString) Sets a string that will be scanned for and expected in the response body from the server.void
setResponseSearchStringIgnoreCase
(String searchString) Sets a string that will be scanned for and expected in the response body from the server.void
Sets the state for this test case.void
setStrategy
(String validator) Sets the validation strategy for this test case instance.void
setUnexpectedResponseSearchString
(String searchString) Sets a string that will be scanned for and should not be present in the response body from the server.void
setUnorderedSearchString
(String searchString) Sets a string or series of strings that will be searched for in the response.
-
Field Details
-
TOKENIZED_STRATEGY
Tokenized response validation strategy- See Also:
-
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
Executes the test case.- Specified by:
execute
in interfaceTestCase
- Throws:
TestFailureException
- if the test fails for any reason.IllegalStateException
- if no request was configured or if no Validator is available at runtime.
-
setExpectedStatusCode
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
Sets the reason phrase to be expected in the response from the server.- Parameters:
reasonPhrase
- the expected reason-phrase
-
addExpectedHeader
Adds a header that is to be expected in the response from the server.- Parameters:
header
- in the format of: (test:foo)
-
setGoldenFilePath
Sets the path to the goldenfile the test case should use.- Parameters:
gfPath
- a fully qualified path including filename.
-
setRequest
Sets the request that should be dispatched by this test case.- Parameters:
request
- the HTTP request used for this test case
-
addUnexpectedHeader
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
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
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
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
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
Returns the list of search strings.- Returns:
- the list of search strings.
-
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
Returns the status code expected to be found in the server's response- Returns:
- status code
-
getReasonPhrase
Returns the reason phrase that is expected to be found in the server's response.- Returns:
- reason phrase
-
getSearchStrings
Returns the configured list of strings that will be used when scanning the server's response.- Returns:
- list of Strings
-
getSearchStringsNoCase
Returns the configured list of strings that will be used when scanning the server's response.- Returns:
- list of case insensitive Strings
-
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
Returns the HttpRequest for this particular test case.- Returns:
- HttpRequest of this test case
-
getGoldenfilePath
Returns the path to the goldenfile.- Returns:
- path to the goldenfile
-
getState
Returns the state for this particular test case. -
setState
Sets the state for this test case. -
setName
Sets a logical name for this test case. -
getName
Returns the logical name for this test case. -
setStrategy
Sets the validation strategy for this test case instance.- Parameters:
validator
- - the fully qualified class name of the response validator to use.
-
getStrategy
Returns the class name of the response validator used.- Returns:
- the fully qualified class of the validator used
-