Class WebTestCase
java.lang.Object
com.sun.ts.tests.common.webclient.WebTestCase
- All Implemented Interfaces:
- 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 SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionCreates 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 SummaryModifier and TypeMethodDescriptionvoidaddExpectedHeader(String header) Adds a header that is to be expected in the response from the server.voidaddUnexpectedHeader(String header) Adds a header that is should not be in the server's response.voidexecute()Executes the test case.org.apache.commons.httpclient.Header[]Returns an array of Header objects that are expected to be found in the responst.booleanReturns an indicator on whether a response body is expected or not.Returns the path to the goldenfile.Returns the InputStream of 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.voidsetAssertNoResponseBody(boolean value) Enables/Disables an assertion that a response body is present.voidsetExpectedReasonPhrase(String reasonPhrase) Sets the reason phrase to be expected in the response from the server.voidsetExpectedStatusCode(String statusCode) Sets the status code to be expected in the response from the server, i.e.voidsetGoldenFilePath(String gfPath) Sets the path to the goldenfile the test case should use.voidSets the InputStream of the goldenfile the test case should use.voidSets a logical name for this test case.voidsetRequest(HttpRequest request) Sets the request that should be dispatched by this test case.voidsetResponseSearchString(String searchString) Sets a string that will be scanned for and expected in the response body from the server.voidsetResponseSearchStringIgnoreCase(String searchString) Sets a string that will be scanned for and expected in the response body from the server.voidSets the state for this test case.voidsetStrategy(String validator) Sets the validation strategy for this test case instance.voidsetUnexpectedResponseSearchString(String searchString) Sets a string that will be scanned for and should not be present in the response body from the server.voidsetUnorderedSearchString(String searchString) Sets a string or series of strings that will be searched for in the response.
- 
Field Details- 
TOKENIZED_STRATEGYTokenized response validation strategy- See Also:
 
- 
WHITESPACE_STRATEGYWhitespace response validation strategy- See Also:
 
 
- 
- 
Constructor Details- 
WebTestCasepublic 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- 
executeExecutes the test case.- Specified by:
- executein 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.
 
- 
setExpectedStatusCodeSets the status code to be expected in the response from the server, i.e. 500 or 404, etc.- Parameters:
- statusCode- the expected status code
 
- 
setExpectedReasonPhraseSets the reason phrase to be expected in the response from the server.- Parameters:
- reasonPhrase- the expected reason-phrase
 
- 
addExpectedHeaderAdds a header that is to be expected in the response from the server.- Parameters:
- header- in the format of- : - (test:foo) 
 
- 
setGoldenFilePathSets the path to the goldenfile the test case should use.- Parameters:
- gfPath- a fully qualified path including filename.
 
- 
setGoldenFileStreamSets the InputStream of the goldenfile the test case should use.- Parameters:
- in- an InputStream value of the goldenfile.
 
- 
setRequestSets the request that should be dispatched by this test case.- Parameters:
- request- the HTTP request used for this test case
 
- 
addUnexpectedHeaderAdds a header that is should not be in the server's response.- Parameters:
- header- in the format of- : - (test:foo) 
 
- 
setAssertNoResponseBodypublic void setAssertNoResponseBody(boolean value) Enables/Disables an assertion that a response body is present.- Parameters:
- value- a value of true will enable the assertion.
 
- 
setResponseSearchStringSets 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
 
- 
setResponseSearchStringIgnoreCaseSets 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
 
- 
setUnexpectedResponseSearchStringSets 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
 
- 
setUnorderedSearchStringSets 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
 
- 
getUnorderedSearchStringsReturns the list of search strings.- Returns:
- the list of search strings.
 
- 
getResponseReturns the response for this particular test case.- Returns:
- an HttpResponse object
 
- 
getExpectedHeaderspublic 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
 
- 
getUnexpectedHeaderspublic 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
 
- 
getStatusCodeReturns the status code expected to be found in the server's response- Returns:
- status code
 
- 
getReasonPhraseReturns the reason phrase that is expected to be found in the server's response.- Returns:
- reason phrase
 
- 
getSearchStringsReturns the configured list of strings that will be used when scanning the server's response.- Returns:
- list of Strings
 
- 
getSearchStringsNoCaseReturns the configured list of strings that will be used when scanning the server's response.- Returns:
- list of case insensitive Strings
 
- 
getUnexpectedSearchStringsReturns 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
 
- 
getExpectResponseBodypublic boolean getExpectResponseBody()Returns an indicator on whether a response body is expected or not.- Returns:
- boolean value
 
- 
getRequestReturns the HttpRequest for this particular test case.- Returns:
- HttpRequest of this test case
 
- 
getGoldenfilePathReturns the path to the goldenfile.- Returns:
- path to the goldenfile
 
- 
getGoldenfileStreamReturns the InputStream of the goldenfile.- Returns:
- InputStream of the goldenfile
 
- 
getStateReturns the state for this particular test case.
- 
setStateSets the state for this test case.
- 
setNameSets a logical name for this test case.
- 
getNameReturns the logical name for this test case.
- 
setStrategySets the validation strategy for this test case instance.- Parameters:
- validator- - the fully qualified class name of the response validator to use.
 
- 
getStrategyReturns the class name of the response validator used.- Returns:
- the fully qualified class of the validator used
 
 
-