Interface HandlingResult


  • public interface HandlingResult
    Represents the result of testing one or more handlers.
    See Also:
    RequestFixture
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      <T extends java.lang.Throwable>
      T
      exception​(java.lang.Class<T> type)
      The throwable thrown or given to Context.error(Throwable), unless a custom error handler is in use.
      byte[] getBodyBytes()
      The response body, as bytes.
      java.lang.String getBodyText()
      The response body, interpreted as a utf8 string.
      java.lang.Integer getClientError()
      The client error raised if any, unless a custom client error handler is in use.
      java.util.Set<io.netty.handler.codec.http.cookie.Cookie> getCookies()
      The cookies to be set as part of the response.
      ratpack.http.Headers getHeaders()
      The final response headers.
      ratpack.registry.Registry getRegistry()
      The final state of the context registry.
      ratpack.registry.Registry getRequestRegistry()
      The final state of the request registry.
      java.nio.file.Path getSentFile()
      Indicates whether the result of invoking the handler was that it invoked one of the Response.sendFile(java.nio.file.Path) methods.
      ratpack.http.Status getStatus()
      The response status information.
      boolean isCalledNext()
      Indicates whether the result of invoking the handler was that it delegated to a downstream handler.
      boolean isSentResponse()
      Indicates the the handler(s) invoked one of the Response.send() methods.
      <T> T rendered​(java.lang.Class<T> type)
      The object that was rendered to the response.
    • Method Detail

      • getBodyBytes

        @Nullable
        byte[] getBodyBytes()
        The response body, as bytes.

        This does not include file or rendered responses. See getSentFile() and rendered(Class).

        Returns:
        the response body, as bytes, or null if no response was sent.
      • getBodyText

        @Nullable
        java.lang.String getBodyText()
        The response body, interpreted as a utf8 string.

        This does not include file or rendered responses. See getSentFile() and rendered(Class).

        Returns:
        the response body, interpreted as a utf8 string, or null if no response was sent.
      • getCookies

        @Nullable
        java.util.Set<io.netty.handler.codec.http.cookie.Cookie> getCookies()
        The cookies to be set as part of the response.

        Cookies are set during request processing via the Response.cookie(String, String) method, or via directly modifying Response.getCookies().

        Returns:
        the cookies to be set as part of the response
        Since:
        1.3
      • getClientError

        @Nullable
        java.lang.Integer getClientError()
        The client error raised if any, unless a custom client error handler is in use.

        If no client error was “raised”, will be null.

        If a custom client error handler is used (either by specification in the request fixture or insertion by an upstream handler), this will always be null. In such a case, this result effectively indicates what the custom client error handler did as its implementation.

        Returns:
        the client error code, or null.
      • exception

        <T extends java.lang.Throwable> T exception​(java.lang.Class<T> type)
        The throwable thrown or given to Context.error(Throwable), unless a custom error handler is in use.

        If no throwable was “raised”, a new HandlerExceptionNotThrownException is raised.

        If a custom error handler is used (either by specification in the request fixture or insertion by an upstream handler), this will always raise a new HandlerExceptionNotThrownException In such a case, this result effectively indicates what the custom error handler did as its implementation.

        Type Parameters:
        T - The expected type of the exception captured.
        Parameters:
        type - The expected type of the exception captured.
        Returns:
        the “unhandled” throwable that occurred, or raise HandlerExceptionNotThrownException
      • getHeaders

        ratpack.http.Headers getHeaders()
        The final response headers.
        Returns:
        the final response headers
      • getRegistry

        ratpack.registry.Registry getRegistry()
        The final state of the context registry.
        Returns:
        the final state of the context registry
      • getRequestRegistry

        ratpack.registry.Registry getRequestRegistry()
        The final state of the request registry.
        Returns:
        the final state of the reqest registry
      • getSentFile

        @Nullable
        java.nio.file.Path getSentFile()
        Indicates whether the result of invoking the handler was that it invoked one of the Response.sendFile(java.nio.file.Path) methods.

        This does not include files rendered with Context.render(Object).

        Returns:
        the file given to one of the Response.sendFile(java.nio.file.Path) methods, or null if none of these methods were called
      • getStatus

        ratpack.http.Status getStatus()
        The response status information.

        Indicates the state of the context's Response.getStatus() after invoking the handler. If the result is a sent response, this indicates the status of the response.

        Returns:
        the response status
      • isCalledNext

        boolean isCalledNext()
        Indicates whether the result of invoking the handler was that it delegated to a downstream handler.
        Returns:
        whether the handler delegated to a downstream handler
      • isSentResponse

        boolean isSentResponse()
        Indicates the the handler(s) invoked one of the Response.send() methods.
        Returns:
        whether one of the Response.send() methods was invoked
      • rendered

        @Nullable
        <T> T rendered​(java.lang.Class<T> type)
                throws java.lang.AssertionError
        The object that was rendered to the response.

        The exact object that was given to Context.render(Object). The value must be assignment compatible with given type token. If it is not, an AssertionError will be thrown.

        Type Parameters:
        T - the expect type of the rendered object
        Parameters:
        type - the expect type of the rendered object
        Returns:
        the rendered object, or null if no object was rendered
        Throws:
        java.lang.AssertionError - if the rendered object cannot be cast to the given type