Interface EmbeddedApp

  • All Superinterfaces:
    ApplicationUnderTest, java.lang.AutoCloseable, CloseableApplicationUnderTest
    All Known Subinterfaces:
    GroovyEmbeddedApp
    All Known Implementing Classes:
    MockApi

    public interface EmbeddedApp
    extends CloseableApplicationUnderTest
    An application created and used at runtime, useful for functionally testing subsets of functionality.

    This mechanism can be used for functionally testing isolated sections of an application, or for testing general libraries that provide reusable functionality (e.g. Ratpack Guice modules).

    Different implementations expose different API that can be used to define the actual application under test.

    As embedded applications also implement ApplicationUnderTest, they are suitable for use with clients accessing the app via HTTP. Implementations must ensure that the application is up and receiving request when returning from getAddress(). Be sure to close() the application after use to free resources.

    • Method Detail

      • fromServer

        static EmbeddedApp fromServer​(RatpackServer server)
        Creates an embedded application for the given server.
        Parameters:
        server - the server to embed
        Returns:
        a newly created embedded application
      • of

        static EmbeddedApp of​(Action<? super RatpackServerSpec> definition)
                       throws java.lang.Exception
        Creates an embedded application from the given function.
        Parameters:
        definition - a function that defines the server
        Returns:
        a newly created embedded application
        Throws:
        java.lang.Exception - if an error is encountered creating the application
        See Also:
        RatpackServer.of(Action)
      • fromServer

        static EmbeddedApp fromServer​(Factory<? extends RatpackServer> server)
        Creates an embedded application for the given server.
        Parameters:
        server - a factory that creates the server to embed
        Returns:
        a newly created embedded application
      • fromServer

        static EmbeddedApp fromServer​(ServerConfigBuilder serverConfig,
                                      Action<? super RatpackServerSpec> definition)
        Creates an embedded application using the given server config, and server creating function.
        Parameters:
        serverConfig - the server configuration
        definition - a function to create the server to embed
        Returns:
        a newly created embedded application
      • fromServer

        static EmbeddedApp fromServer​(ServerConfig serverConfig,
                                      Action<? super RatpackServerSpec> definition)
        Creates an embedded application using the given server config, and server creating function.
        Parameters:
        serverConfig - the server configuration
        definition - a function to create the server to embed
        Returns:
        a newly created embedded application
      • fromHandlerFactory

        static EmbeddedApp fromHandlerFactory​(Function<? super Registry,​? extends Handler> handlerFactory)
        Creates an embedded application with a default launch config (no base dir, ephemeral port) and the given handler.

        If you need to tweak the server config, use fromServer(ServerConfig, Action).

        Parameters:
        handlerFactory - a handler factory
        Returns:
        a newly created embedded application
      • fromHandler

        static EmbeddedApp fromHandler​(Handler handler)
        Creates an embedded application with a default launch config (no base dir, ephemeral port) and the given handler.

        If you need to tweak the server config, use fromServer(ServerConfig, Action).

        Parameters:
        handler - the application handler
        Returns:
        a newly created embedded application
      • fromHandlers

        static EmbeddedApp fromHandlers​(Action<? super Chain> action)
        Creates an embedded application with a default launch config (no base dir, ephemeral port) and the given handler chain.

        If you need to tweak the server config, use fromServer(ServerConfig, Action).

        Parameters:
        action - the handler chain definition
        Returns:
        a newly created embedded application
      • getServer

        RatpackServer getServer()
        The server for the application.

        Calling this method does not implicitly start the server.

        Returns:
        The server for the application
      • getAddress

        default java.net.URI getAddress()
        The address of the application under test, which is guaranteed to be listening for requests.

        Implementations should start the application if it has not already been started before returning from this method.

        Specified by:
        getAddress in interface ApplicationUnderTest
        Returns:
        the address of the application under test