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 ratpack.http.client.ReceivedResponse
delete()
Make a DELETE request with a path of "" this is the same as calling delete("").ratpack.http.client.ReceivedResponse
delete(java.lang.String path)
Make a DELETE request to the specified path.java.lang.String
deleteText()
A convenience method for doing a DELETE request then callingReceivedResponse.getBody()
thenTypedData.getText()
.java.lang.String
deleteText(java.lang.String path)
A convenience method for doing a DELETE request then callingReceivedResponse.getBody()
thenTypedData.getText()
.ratpack.http.client.ReceivedResponse
get()
Make a GET request with a path of "" this is the same as calling get("").ratpack.http.client.ReceivedResponse
get(java.lang.String path)
Make a GET request to the specified path.ApplicationUnderTest
getApplicationUnderTest()
java.util.List<io.netty.handler.codec.http.cookie.Cookie>
getCookies(java.lang.String path)
Get cookies withPath=
attribute equal topath
and all its subpaths.ratpack.http.client.ReceivedResponse
getResponse()
java.lang.String
getText()
A convenience method for doing a GET request then callingReceivedResponse.getBody()
thenTypedData.getText()
.java.lang.String
getText(java.lang.String path)
A convenience method for doing a GET request then callingReceivedResponse.getBody()
thenTypedData.getText()
.ratpack.http.client.ReceivedResponse
head()
Make a HEAD request with a path of "" this is the same as calling head("").ratpack.http.client.ReceivedResponse
head(java.lang.String path)
Make a HEAD request to the specified path.ratpack.http.client.ReceivedResponse
options()
Make a OPTIONS request with a path of "" this is the same as calling options("").ratpack.http.client.ReceivedResponse
options(java.lang.String path)
Make a OPTIONS request to the specified path.java.lang.String
optionsText()
A convenience method for doing a OPTIONS request then callingReceivedResponse.getBody()
thenTypedData.getText()
.java.lang.String
optionsText(java.lang.String path)
A convenience method for doing a OPTIONS request then callingReceivedResponse.getBody()
thenTypedData.getText()
.TestHttpClient
params(ratpack.func.Action<? super com.google.common.collect.ImmutableMultimap.Builder<java.lang.String,java.lang.Object>> params)
ratpack.http.client.ReceivedResponse
patch()
Make a PATCH request with a path of "" this is the same as calling patch("").ratpack.http.client.ReceivedResponse
patch(java.lang.String path)
Make a PATCH request to the specified path.java.lang.String
patchText()
A convenience method for doing a PATCH request then callingReceivedResponse.getBody()
thenTypedData.getText()
.java.lang.String
patchText(java.lang.String path)
A convenience method for doing a PATCH request then callingReceivedResponse.getBody()
thenTypedData.getText()
.ratpack.http.client.ReceivedResponse
post()
Make a POST request with a path of "" this is the same as calling post("").ratpack.http.client.ReceivedResponse
post(java.lang.String path)
Make a POST request to the specified path.java.lang.String
postText()
A convenience method for doing a POST request then callingReceivedResponse.getBody()
thenTypedData.getText()
.java.lang.String
postText(java.lang.String path)
A convenience method for doing a POST request then callingReceivedResponse.getBody()
thenTypedData.getText()
.ratpack.http.client.ReceivedResponse
put()
Make a PUT request with a path of "" this is the same as calling put("").ratpack.http.client.ReceivedResponse
put(java.lang.String path)
Make a PUT request to the specified path.java.lang.String
putText()
A convenience method for doing a PUT request then callingReceivedResponse.getBody()
thenTypedData.getText()
.java.lang.String
putText(java.lang.String path)
A convenience method for doing a PUT request then callingReceivedResponse.getBody()
thenTypedData.getText()
.ratpack.http.client.ReceivedResponse
request(java.lang.String path, ratpack.func.Action<? super ratpack.http.client.RequestSpec> requestAction)
Executes the request as specified by the providedRequestSpec
against the provided path.ratpack.http.client.ReceivedResponse
request(ratpack.func.Action<? super ratpack.http.client.RequestSpec> requestAction)
Executes the request as specified by the providedRequestSpec
.TestHttpClient
requestSpec(ratpack.func.Action<? super ratpack.http.client.RequestSpec> requestAction)
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, ratpack.func.Action<? super ratpack.http.client.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 ratpack.func.Action<? super ratpack.http.client.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
- 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()
- Returns:
- the application requests are being made against
-
requestSpec
TestHttpClient requestSpec(ratpack.func.Action<? super ratpack.http.client.RequestSpec> requestAction)
- Parameters:
requestAction
- anAction
that will act on theRequestSpec
this is used to configure details of the next request- Returns:
- this
-
params
TestHttpClient params(ratpack.func.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
ratpack.http.client.ReceivedResponse getResponse()
- Returns:
- the response from the last request sent
-
head
ratpack.http.client.ReceivedResponse head()
Make a HEAD request with a path of "" this is the same as calling head("").- Returns:
- the response from the request
-
head
ratpack.http.client.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
ratpack.http.client.ReceivedResponse options()
Make a OPTIONS request with a path of "" this is the same as calling options("").- Returns:
- the response from the request
-
options
ratpack.http.client.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
ratpack.http.client.ReceivedResponse get()
Make a GET request with a path of "" this is the same as calling get("").- Returns:
- the response from the request
-
get
ratpack.http.client.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
ratpack.http.client.ReceivedResponse post()
Make a POST request with a path of "" this is the same as calling post("").- Returns:
- the response from the request
-
post
ratpack.http.client.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
ratpack.http.client.ReceivedResponse put()
Make a PUT request with a path of "" this is the same as calling put("").- Returns:
- the response from the request
-
put
ratpack.http.client.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
ratpack.http.client.ReceivedResponse patch()
Make a PATCH request with a path of "" this is the same as calling patch("").- Returns:
- the response from the request
-
patch
ratpack.http.client.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
ratpack.http.client.ReceivedResponse delete()
Make a DELETE request with a path of "" this is the same as calling delete("").- Returns:
- the response from the request
-
delete
ratpack.http.client.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 topath
and all its subpaths.- Parameters:
path
- a URI path attached to cookies- Returns:
- the list of cookies attached to the given
path
-
request
ratpack.http.client.ReceivedResponse request(ratpack.func.Action<? super ratpack.http.client.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
ratpack.http.client.ReceivedResponse request(java.lang.String path, ratpack.func.Action<? super ratpack.http.client.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.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>)
-
-