public interface EmbeddedApp extends CloseableApplicationUnderTest
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.
EmbeddedAppSupport| Modifier and Type | Method and Description |
|---|---|
default void |
close()
Stops the server returned by
getServer(). |
static EmbeddedApp |
fromHandler(ratpack.handling.Handler handler)
Creates an embedded application with a default launch config (no base dir, ephemeral port) and the given handler.
|
static EmbeddedApp |
fromHandler(java.nio.file.Path baseDir,
ratpack.handling.Handler handler)
Creates an embedded application with a default launch config (ephemeral port) and the given handler.
|
static EmbeddedApp |
fromHandlerFactory(ratpack.func.Function<? super ratpack.registry.Registry,? extends ratpack.handling.Handler> handlerFactory)
Creates an embedded application with a default launch config (no base dir, ephemeral port) and the given handler.
|
static EmbeddedApp |
fromHandlerFactory(java.nio.file.Path baseDir,
ratpack.func.Function<? super ratpack.registry.Registry,? extends ratpack.handling.Handler> handlerFactory)
Creates an embedded application with a default launch config (ephemeral port) and the given handler.
|
static EmbeddedApp |
fromHandlers(ratpack.func.Action<? super ratpack.handling.Chain> action)
Creates an embedded application with a default launch config (no base dir, ephemeral port) and the given handler chain.
|
static EmbeddedApp |
fromServer(ratpack.func.Factory<? extends ratpack.server.RatpackServer> server)
Creates an embedded application for the given server.
|
static EmbeddedApp |
fromServer(ratpack.server.RatpackServer server)
Creates an embedded application for the given server.
|
static EmbeddedApp |
fromServer(ratpack.server.ServerConfig serverConfig,
ratpack.func.Function<? super ratpack.server.RatpackServer.Definition.Builder,? extends ratpack.server.RatpackServer.Definition> builder)
Creates an embedded application using the given server config, and server creating function.
|
default java.net.URI |
getAddress()
The address of the application under test, which is guaranteed to be accepting requests.
|
ratpack.server.RatpackServer |
getServer()
The server for the application.
|
static EmbeddedApp |
of(ratpack.func.Function<? super ratpack.server.RatpackServer.Definition.Builder,? extends ratpack.server.RatpackServer.Definition> definition)
Creates an embedded application from the given function.
|
testgetHttpClient, of, of, of, ofstatic EmbeddedApp fromServer(ratpack.server.RatpackServer server)
server - the server to embedstatic EmbeddedApp of(ratpack.func.Function<? super ratpack.server.RatpackServer.Definition.Builder,? extends ratpack.server.RatpackServer.Definition> definition) throws java.lang.Exception
definition - a function that defines the serverjava.lang.Exception - if an error is encountered creating the applicationRatpackServer.of(ratpack.func.Function)static EmbeddedApp fromServer(ratpack.func.Factory<? extends ratpack.server.RatpackServer> server)
server - a factory that creates the server to embedstatic EmbeddedApp fromServer(ratpack.server.ServerConfig serverConfig, ratpack.func.Function<? super ratpack.server.RatpackServer.Definition.Builder,? extends ratpack.server.RatpackServer.Definition> builder)
serverConfig - the server configurationbuilder - a function to create the server to embedstatic EmbeddedApp fromHandlerFactory(ratpack.func.Function<? super ratpack.registry.Registry,? extends ratpack.handling.Handler> handlerFactory)
If you need to tweak the server config, use fromServer(ServerConfig, Function).
handlerFactory - a handler factorystatic EmbeddedApp fromHandlerFactory(java.nio.file.Path baseDir, ratpack.func.Function<? super ratpack.registry.Registry,? extends ratpack.handling.Handler> handlerFactory)
If you need to tweak the server config, use fromServer(ServerConfig, Function).
baseDir - the base dir for the embedded apphandlerFactory - a handler factorystatic EmbeddedApp fromHandler(ratpack.handling.Handler handler)
If you need to tweak the server config, use fromServer(ServerConfig, Function).
handler - the application handlerstatic EmbeddedApp fromHandler(java.nio.file.Path baseDir, ratpack.handling.Handler handler)
If you need to tweak the server config, use fromServer(ServerConfig, Function).
baseDir - the base dir for the embedded apphandler - the application handlerstatic EmbeddedApp fromHandlers(ratpack.func.Action<? super ratpack.handling.Chain> action)
If you need to tweak the server config, use fromServer(ServerConfig, Function).
action - the handler chain definitionratpack.server.RatpackServer getServer()
Calling this method does not implicitly start the server.
default java.net.URI getAddress()
getAddress in interface ApplicationUnderTestdefault void close()
getServer().
Exceptions thrown by calling RatpackServer.stop() are suppressed and written to System.err.
close in interface java.lang.AutoCloseableclose in interface CloseableApplicationUnderTest