Package io.mangoo.test.http
Class TestResponse
java.lang.Object
io.mangoo.test.http.TestResponse
- Direct Known Subclasses:
TestBrowser
- Author:
- svenkubiak
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionexecute()Executes the HTTP requestRetrieves a cookie from the cookie store with a given nameRetrieves a specific header with the given nameintSets the URI to be executed by the requestwithBasicAuthentication(String username, String password) Sets Basic HTTP Authentication the requestwithContentType(String contentType) Sets the ContentType of the requestwithCookie(HttpCookie cookie) Adds an additional cookie to the requestDisables redirects when the request is executed by setting followReditects to HttpClient.Redirect.NEVER Default is HttpClient.Redirect.ALWAYSSimulates a FORM post by setting: Content-Type to application/x-www-form-urlencoded HTTP method to POST URLEncoding of the given parameterswithHeader(String name, String value) Adds an additional header to the requestwithHTTPMethod(String method) Sets the HTTP method to execute the request withwithStringBody(String body) Sets a String body to the requestwithTimeout(long amount, TemporalUnit unit) Sets the timeout of the HTTP request Default is 2 seconds
-
Constructor Details
-
TestResponse
public TestResponse() -
TestResponse
-
-
Method Details
-
withHeader
Adds an additional header to the request- Parameters:
name- The name of the headervalue- The value of the header- Returns:
- TestResponse instance
-
withHTTPMethod
Sets the HTTP method to execute the request with- Parameters:
method- The HTTP Method- Returns:
- TestResponse instance
-
withTimeout
Sets the timeout of the HTTP request Default is 2 seconds- Parameters:
amount- The amount of timeunit- The unit of time- Returns:
- TestResponse instance
-
withBasicAuthentication
Sets Basic HTTP Authentication the request- Parameters:
username- The usernamepassword- The password- Returns:
- TestResponse instance
-
to
Sets the URI to be executed by the request- Parameters:
uri- The URI to call- Returns:
- TestResponse instance
-
withCookie
Adds an additional cookie to the request- Parameters:
cookie- The cookie to add- Returns:
- TestResponse instance
-
withStringBody
Sets a String body to the request- Parameters:
body- The request body to use- Returns:
- TestResponse instance
-
withContentType
Sets the ContentType of the request- Parameters:
contentType- The content type to use- Returns:
- TestResponse instance
-
withDisabledRedirects
Disables redirects when the request is executed by setting followReditects to HttpClient.Redirect.NEVER Default is HttpClient.Redirect.ALWAYS- Returns:
- TestResponse instance
-
withForm
Simulates a FORM post by setting: Content-Type to application/x-www-form-urlencoded HTTP method to POST URLEncoding of the given parameters- Parameters:
parameters- The parameters to use- Returns:
- TestResponse instance
-
execute
Executes the HTTP request- Returns:
- TestResponse instance with response parameters
-
getContent
- Returns:
- The response content
-
getHttpResponse
- Returns:
- The HTTP response object
-
getStatusCode
public int getStatusCode()- Returns:
- The status code of the response
-
getContentType
- Returns:
- The content type of the response
-
getResponseUrl
- Returns:
- The URL of the response
-
getCookies
- Returns:
- The response cookie or an empty list
-
getCookie
Retrieves a cookie from the cookie store with a given name- Parameters:
name- The name of the cookie- Returns:
- A Cookie or null if non found by name
-
getHeader
Retrieves a specific header with the given name- Parameters:
name- The name of the header- Returns:
- The value of the header or an empty string if not found
-