Package ratpack.test.http
Interface TestHttpClient
-
public interface TestHttpClientA Http Client focused on testing Ratpack applications.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description ReceivedResponsedelete()Make a DELETE request with a path of "" this is the same as calling delete("").ReceivedResponsedelete(java.lang.String path)Make a DELETE request to the specified path.java.lang.StringdeleteText()A convenience method for doing a DELETE request then callingReceivedResponse.getBody()thenTypedData.getText().java.lang.StringdeleteText(java.lang.String path)A convenience method for doing a DELETE request then callingReceivedResponse.getBody()thenTypedData.getText().ReceivedResponseget()Make a GET request with a path of "" this is the same as calling get("").ReceivedResponseget(java.lang.String path)Make a GET request to the specified path.ApplicationUnderTestgetApplicationUnderTest()java.util.List<io.netty.handler.codec.http.cookie.Cookie>getCookies(java.lang.String path)Get cookies withPath=attribute equal topathand all its subpaths.ReceivedResponsegetResponse()java.lang.StringgetText()A convenience method for doing a GET request then callingReceivedResponse.getBody()thenTypedData.getText().java.lang.StringgetText(java.lang.String path)A convenience method for doing a GET request then callingReceivedResponse.getBody()thenTypedData.getText().ReceivedResponsehead()Make a HEAD request with a path of "" this is the same as calling head("").ReceivedResponsehead(java.lang.String path)Make a HEAD request to the specified path.ReceivedResponseoptions()Make a OPTIONS request with a path of "" this is the same as calling options("").ReceivedResponseoptions(java.lang.String path)Make a OPTIONS request to the specified path.java.lang.StringoptionsText()A convenience method for doing a OPTIONS request then callingReceivedResponse.getBody()thenTypedData.getText().java.lang.StringoptionsText(java.lang.String path)A convenience method for doing a OPTIONS request then callingReceivedResponse.getBody()thenTypedData.getText().TestHttpClientparams(Action<? super com.google.common.collect.ImmutableMultimap.Builder<java.lang.String,java.lang.Object>> params)ReceivedResponsepatch()Make a PATCH request with a path of "" this is the same as calling patch("").ReceivedResponsepatch(java.lang.String path)Make a PATCH request to the specified path.java.lang.StringpatchText()A convenience method for doing a PATCH request then callingReceivedResponse.getBody()thenTypedData.getText().java.lang.StringpatchText(java.lang.String path)A convenience method for doing a PATCH request then callingReceivedResponse.getBody()thenTypedData.getText().ReceivedResponsepost()Make a POST request with a path of "" this is the same as calling post("").ReceivedResponsepost(java.lang.String path)Make a POST request to the specified path.java.lang.StringpostText()A convenience method for doing a POST request then callingReceivedResponse.getBody()thenTypedData.getText().java.lang.StringpostText(java.lang.String path)A convenience method for doing a POST request then callingReceivedResponse.getBody()thenTypedData.getText().ReceivedResponseput()Make a PUT request with a path of "" this is the same as calling put("").ReceivedResponseput(java.lang.String path)Make a PUT request to the specified path.java.lang.StringputText()A convenience method for doing a PUT request then callingReceivedResponse.getBody()thenTypedData.getText().java.lang.StringputText(java.lang.String path)A convenience method for doing a PUT request then callingReceivedResponse.getBody()thenTypedData.getText().ReceivedResponserequest(java.lang.String path, Action<? super RequestSpec> requestAction)Executes the request as specified by the providedRequestSpecagainst the provided path.ReceivedResponserequest(Action<? super RequestSpec> requestAction)Executes the request as specified by the providedRequestSpec.TestHttpClientrequestSpec(Action<? super RequestSpec> requestAction)voidresetRequest()Set the requestSpec back to a No Op default and clear the cookies.static TestHttpClienttestHttpClient(ApplicationUnderTest applicationUnderTest)A method to create an instance of the default implementation of TestHttpClient.static TestHttpClienttestHttpClient(ApplicationUnderTest applicationUnderTest, Action<? super RequestSpec> requestConfigurer)A method to create an instance of the default implementation of TestHttpClient.
-
-
-
Method Detail
-
testHttpClient
static TestHttpClient testHttpClient(ApplicationUnderTest applicationUnderTest)
A method to create an instance of the default implementation of TestHttpClient.- Parameters:
applicationUnderTest- the Ratpack application to make requests against- Returns:
- a http client which is configured to make requests against the provided ApplicationUnderTest
-
testHttpClient
static TestHttpClient testHttpClient(ApplicationUnderTest applicationUnderTest, @Nullable Action<? super RequestSpec> requestConfigurer)
A method to create an instance of the default implementation of TestHttpClient.The settings provided can be overridden on a per request basis via
requestSpec(ratpack.func.Action<? super ratpack.http.client.RequestSpec>).- Parameters:
applicationUnderTest- the Ratpack application to make requests againstrequestConfigurer- aActionthat will set up theRequestSpecfor all requests made through this instance of TestHttpClient- Returns:
- a http client which is configured to make requests against the provided ApplicationUnderTest
-
getApplicationUnderTest
ApplicationUnderTest getApplicationUnderTest()
- Returns:
- the application requests are being made against
-
requestSpec
TestHttpClient requestSpec(Action<? super RequestSpec> requestAction)
- Parameters:
requestAction- anActionthat will act on theRequestSpecthis is used to configure details of the next request- Returns:
- this
-
params
TestHttpClient params(Action<? super com.google.common.collect.ImmutableMultimap.Builder<java.lang.String,java.lang.Object>> params)
- Parameters:
params- the params that will be used with the HttpUrlBuilder passed intoHttpUrlBuilder.params(Action)- Returns:
- this
-
resetRequest
void resetRequest()
Set the requestSpec back to a No Op default and clear the cookies.
-
getResponse
ReceivedResponse getResponse()
- Returns:
- the response from the last request sent
-
head
ReceivedResponse head()
Make a HEAD request with a path of "" this is the same as calling head("").- Returns:
- the response from the request
-
head
ReceivedResponse head(java.lang.String path)
Make a HEAD request to the specified path.- Parameters:
path- the path the request is made against- Returns:
- the response from the request
-
options
ReceivedResponse options()
Make a OPTIONS request with a path of "" this is the same as calling options("").- Returns:
- the response from the request
-
options
ReceivedResponse options(java.lang.String path)
Make a OPTIONS request to the specified path.- Parameters:
path- the path the request is made against- Returns:
- the response from the request
-
optionsText
java.lang.String optionsText()
A convenience method for doing a OPTIONS request then callingReceivedResponse.getBody()thenTypedData.getText().- Returns:
- the response body as a String
- Since:
- 1.1
-
optionsText
java.lang.String optionsText(java.lang.String path)
A convenience method for doing a OPTIONS request then callingReceivedResponse.getBody()thenTypedData.getText().- Parameters:
path- the path the request is made against- Returns:
- the response body as a String
- Since:
- 1.1
-
get
ReceivedResponse get()
Make a GET request with a path of "" this is the same as calling get("").- Returns:
- the response from the request
-
get
ReceivedResponse get(java.lang.String path)
Make a GET request to the specified path.- Parameters:
path- the path the request is made against- Returns:
- the response from the request
-
getText
java.lang.String getText()
A convenience method for doing a GET request then callingReceivedResponse.getBody()thenTypedData.getText(). Useful if you need to only check details of the response body.- Returns:
- the response body as a String
-
getText
java.lang.String getText(java.lang.String path)
A convenience method for doing a GET request then callingReceivedResponse.getBody()thenTypedData.getText(). Useful if you need to only check details of the response body.- Parameters:
path- the path the request is made against- Returns:
- the response body as a String
-
post
ReceivedResponse post()
Make a POST request with a path of "" this is the same as calling post("").- Returns:
- the response from the request
-
post
ReceivedResponse post(java.lang.String path)
Make a POST request to the specified path.- Parameters:
path- the path the request is made against- Returns:
- the response from the request
-
postText
java.lang.String postText()
A convenience method for doing a POST request then callingReceivedResponse.getBody()thenTypedData.getText().- Returns:
- the response body as a String
-
postText
java.lang.String postText(java.lang.String path)
A convenience method for doing a POST request then callingReceivedResponse.getBody()thenTypedData.getText().- Parameters:
path- the path the request is made against- Returns:
- the response body as a String
-
put
ReceivedResponse put()
Make a PUT request with a path of "" this is the same as calling put("").- Returns:
- the response from the request
-
put
ReceivedResponse put(java.lang.String path)
Make a PUT request to the specified path.- Parameters:
path- the path the request is made against- Returns:
- the response from the request
-
putText
java.lang.String putText()
A convenience method for doing a PUT request then callingReceivedResponse.getBody()thenTypedData.getText().- Returns:
- the response body as a String
-
putText
java.lang.String putText(java.lang.String path)
A convenience method for doing a PUT request then callingReceivedResponse.getBody()thenTypedData.getText().- Parameters:
path- the path the request is made against- Returns:
- the response body as a String
-
patch
ReceivedResponse patch()
Make a PATCH request with a path of "" this is the same as calling patch("").- Returns:
- the response from the request
-
patch
ReceivedResponse patch(java.lang.String path)
Make a PATCH request to the specified path.- Parameters:
path- the path the request is made against- Returns:
- the response from the request
-
patchText
java.lang.String patchText()
A convenience method for doing a PATCH request then callingReceivedResponse.getBody()thenTypedData.getText().- Returns:
- the response body as a String
-
patchText
java.lang.String patchText(java.lang.String path)
A convenience method for doing a PATCH request then callingReceivedResponse.getBody()thenTypedData.getText().- Parameters:
path- the path the request is made against- Returns:
- the response body as a String
-
delete
ReceivedResponse delete()
Make a DELETE request with a path of "" this is the same as calling delete("").- Returns:
- the response from the request
-
delete
ReceivedResponse delete(java.lang.String path)
Make a DELETE request to the specified path.- Parameters:
path- the path the request is made against- Returns:
- the response from the request
-
deleteText
java.lang.String deleteText()
A convenience method for doing a DELETE request then callingReceivedResponse.getBody()thenTypedData.getText().- Returns:
- the response body as a String
-
deleteText
java.lang.String deleteText(java.lang.String path)
A convenience method for doing a DELETE request then callingReceivedResponse.getBody()thenTypedData.getText().- Parameters:
path- the path the request is made against- Returns:
- the response body as a String
-
getCookies
java.util.List<io.netty.handler.codec.http.cookie.Cookie> getCookies(java.lang.String path)
Get cookies withPath=attribute equal topathand all its subpaths.- Parameters:
path- a URI path attached to cookies- Returns:
- the list of cookies attached to the given
path
-
request
ReceivedResponse request(Action<? super RequestSpec> requestAction)
Executes the request as specified by the providedRequestSpec.If the request method is not specified by the provided action, it will default to being a GET request. The action provided to this method is additive to that configured with the
requestSpec(ratpack.func.Action<? super ratpack.http.client.RequestSpec>)method.- Parameters:
requestAction- an action to configure this request- Returns:
- the response from the request
- Since:
- 1.2
-
request
ReceivedResponse request(java.lang.String path, Action<? super RequestSpec> requestAction)
Executes the request as specified by the providedRequestSpecagainst the provided path.If the request method is not specified by the provided action, it will default to being a GET request. The action provided to this method is additive to that configured with the
requestSpec(ratpack.func.Action<? super ratpack.http.client.RequestSpec>)method.- Parameters:
path- the path the request will be made againstrequestAction- an action to configure this request- Returns:
- the response from the request
- Since:
- 1.2
- See Also:
request(ratpack.func.Action<? super ratpack.http.client.RequestSpec>)
-
-