Package ratpack.test.http
Interface TestHttpClient
-
public interface TestHttpClient
A Http Client focused on testing Ratpack applications.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description ReceivedResponse
delete()
Make a DELETE request with a path of "" this is the same as calling delete("").ReceivedResponse
delete(String path)
Make a DELETE request to the specified path.String
deleteText()
A convenience method for doing a DELETE request then callingReceivedResponse.getBody()
thenTypedData.getText()
.String
deleteText(String path)
A convenience method for doing a DELETE request then callingReceivedResponse.getBody()
thenTypedData.getText()
.ReceivedResponse
get()
Make a GET request with a path of "" this is the same as calling get("").ReceivedResponse
get(String path)
Make a GET request to the specified path.ApplicationUnderTest
getApplicationUnderTest()
Retrieves the application under test that is bound to this client.List<io.netty.handler.codec.http.cookie.Cookie>
getCookies(String path)
Get cookies withPath=
attribute equal topath
and all its subpaths.ReceivedResponse
getResponse()
Retrieve the response from the last request made by this client.String
getText()
A convenience method for doing a GET request then callingReceivedResponse.getBody()
thenTypedData.getText()
.String
getText(String path)
A convenience method for doing a GET request then callingReceivedResponse.getBody()
thenTypedData.getText()
.ReceivedResponse
head()
Make a HEAD request with a path of "" this is the same as calling head("").ReceivedResponse
head(String path)
Make a HEAD request to the specified path.ReceivedResponse
options()
Make a OPTIONS request with a path of "" this is the same as calling options("").ReceivedResponse
options(String path)
Make a OPTIONS request to the specified path.String
optionsText()
A convenience method for doing a OPTIONS request then callingReceivedResponse.getBody()
thenTypedData.getText()
.String
optionsText(String path)
A convenience method for doing a OPTIONS request then callingReceivedResponse.getBody()
thenTypedData.getText()
.TestHttpClient
params(Action<? super com.google.common.collect.ImmutableMultimap.Builder<String,Object>> params)
Specify query parameters to be included with outgoing requests from this client.ReceivedResponse
patch()
Make a PATCH request with a path of "" this is the same as calling patch("").ReceivedResponse
patch(String path)
Make a PATCH request to the specified path.String
patchText()
A convenience method for doing a PATCH request then callingReceivedResponse.getBody()
thenTypedData.getText()
.String
patchText(String path)
A convenience method for doing a PATCH request then callingReceivedResponse.getBody()
thenTypedData.getText()
.ReceivedResponse
post()
Make a POST request with a path of "" this is the same as calling post("").ReceivedResponse
post(String path)
Make a POST request to the specified path.String
postText()
A convenience method for doing a POST request then callingReceivedResponse.getBody()
thenTypedData.getText()
.String
postText(String path)
A convenience method for doing a POST request then callingReceivedResponse.getBody()
thenTypedData.getText()
.ReceivedResponse
put()
Make a PUT request with a path of "" this is the same as calling put("").ReceivedResponse
put(String path)
Make a PUT request to the specified path.String
putText()
A convenience method for doing a PUT request then callingReceivedResponse.getBody()
thenTypedData.getText()
.String
putText(String path)
A convenience method for doing a PUT request then callingReceivedResponse.getBody()
thenTypedData.getText()
.ReceivedResponse
request(String path, Action<? super RequestSpec> requestAction)
Executes the request as specified by the providedRequestSpec
against the provided path.ReceivedResponse
request(Action<? super RequestSpec> requestAction)
Executes the request as specified by the providedRequestSpec
.TestHttpClient
requestSpec(Action<? super RequestSpec> requestAction)
Configure the settings for outgoing requests from this client.void
resetRequest()
Set the requestSpec back to a No Op default and clear the cookies.static TestHttpClient
testHttpClient(ApplicationUnderTest applicationUnderTest)
A method to create an instance of the default implementation of TestHttpClient.static TestHttpClient
testHttpClient(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.core.http.client.RequestSpec>)
.- Parameters:
applicationUnderTest
- the Ratpack application to make requests againstrequestConfigurer
- aAction
that will set up theRequestSpec
for 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()
Retrieves the application under test that is bound to this client.- Returns:
- the application requests are being made against
-
requestSpec
TestHttpClient requestSpec(Action<? super RequestSpec> requestAction)
Configure the settings for outgoing requests from this client.- Parameters:
requestAction
- anAction
that will act on theRequestSpec
this is used to configure details of the next request- Returns:
- this
-
params
TestHttpClient params(Action<? super com.google.common.collect.ImmutableMultimap.Builder<String,Object>> params)
Specify query parameters to be included with outgoing requests from this client.- 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()
Retrieve the response from the last request made by this client.- 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(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(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
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
String optionsText(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(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
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
String getText(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(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
String postText()
A convenience method for doing a POST request then callingReceivedResponse.getBody()
thenTypedData.getText()
.- Returns:
- the response body as a String
-
postText
String postText(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(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
String putText()
A convenience method for doing a PUT request then callingReceivedResponse.getBody()
thenTypedData.getText()
.- Returns:
- the response body as a String
-
putText
String putText(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(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
String patchText()
A convenience method for doing a PATCH request then callingReceivedResponse.getBody()
thenTypedData.getText()
.- Returns:
- the response body as a String
-
patchText
String patchText(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(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
String deleteText()
A convenience method for doing a DELETE request then callingReceivedResponse.getBody()
thenTypedData.getText()
.- Returns:
- the response body as a String
-
deleteText
String deleteText(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
List<io.netty.handler.codec.http.cookie.Cookie> getCookies(String path)
Get cookies withPath=
attribute equal topath
and 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.core.http.client.RequestSpec>)
method.- Parameters:
requestAction
- an action to configure this request- Returns:
- the response from the request
- Since:
- 1.2
-
request
ReceivedResponse request(String path, Action<? super RequestSpec> requestAction)
Executes the request as specified by the providedRequestSpec
against 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.core.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.core.http.client.RequestSpec>)
-
-