Interface TestHttpClient


  • public interface TestHttpClient
    A Http Client focused on testing Ratpack applications.
    • 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
      • 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 - an Action that will act on the RequestSpec 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 into HttpUrlBuilder.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
      • 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​(String path)
        A convenience method for doing a GET request then calling ReceivedResponse.getBody() then TypedData.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
      • 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
      • 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
      • 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
      • getCookies

        List<io.netty.handler.codec.http.cookie.Cookie> getCookies​(String path)
        Get cookies with Path= attribute equal to path and all its subpaths.
        Parameters:
        path - a URI path attached to cookies
        Returns:
        the list of cookies attached to the given path