public class MainClassApplicationUnderTest extends ServerBackedApplicationUnderTest
import ratpack.server.RatpackServer;
import ratpack.test.MainClassApplicationUnderTest;
import static org.junit.Assert.assertEquals;
public class Example {
public static class App {
public static void main(String[] args) throws Exception {
RatpackServer.start(s -> s
.handlers(c -> c
.get(ctx -> ctx.render("Hello world!"))
)
);
}
}
public static void main(String[] args) throws Exception {
new MainClassApplicationUnderTest(App.class).test(testHttpClient ->
assertEquals("Hello world!", testHttpClient.getText())
);
}
}
Note that this type implements CloseableApplicationUnderTest
, and should be closed when no longer needed.
Constructor and Description |
---|
MainClassApplicationUnderTest(java.lang.Class<?> mainClass)
Creates a new app under test, based on the given main class.
|
Modifier and Type | Method and Description |
---|---|
protected RatpackServer |
createServer()
Starts the Ratpack server by invoking the
public static void main(String[]) method of the “main class” backing this object. |
addDefaultImpositions, addImpositions, close, createImpositions, getAddress, of, of, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
test
getHttpClient
public MainClassApplicationUnderTest(java.lang.Class<?> mainClass)
mainClass
- a class who's main method starts a Ratpack serverprotected RatpackServer createServer() throws java.lang.Exception
public static void main(String[])
method of the “main class” backing this object.createServer
in class ServerBackedApplicationUnderTest
java.lang.Exception
- if the main method cannot be invoked