Package ratpack.test
Class MainClassApplicationUnderTest
- java.lang.Object
-
- ratpack.test.ServerBackedApplicationUnderTest
-
- ratpack.test.MainClassApplicationUnderTest
-
- All Implemented Interfaces:
AutoCloseable
,ApplicationUnderTest
,CloseableApplicationUnderTest
- Direct Known Subclasses:
GroovyRatpackMainApplicationUnderTest
public class MainClassApplicationUnderTest extends ServerBackedApplicationUnderTest
An application under test fixture that can be used to test a server started by a “main” method.import ratpack.core.server.RatpackServer; import ratpack.test.MainClassApplicationUnderTest; import static org.junit.jupiter.api.Assertions.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 Summary
Constructors Constructor Description MainClassApplicationUnderTest(Class<?> mainClass)
Creates a new app under test, based on the given main class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected RatpackServer
createServer()
Starts the Ratpack server by invoking thepublic static void main(String[])
method of the “main class” backing this object.-
Methods inherited from class ratpack.test.ServerBackedApplicationUnderTest
addDefaultImpositions, addImpositions, close, createImpositions, getAddress, of, of, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ratpack.test.ApplicationUnderTest
getHttpClient
-
Methods inherited from interface ratpack.test.CloseableApplicationUnderTest
test
-
-
-
-
Constructor Detail
-
MainClassApplicationUnderTest
public MainClassApplicationUnderTest(Class<?> mainClass)
Creates a new app under test, based on the given main class.- Parameters:
mainClass
- a class who's main method starts a Ratpack server
-
-
Method Detail
-
createServer
protected RatpackServer createServer() throws Exception
Starts the Ratpack server by invoking thepublic static void main(String[])
method of the “main class” backing this object.- Specified by:
createServer
in classServerBackedApplicationUnderTest
- Returns:
- the Ratpack server created by the main method
- Throws:
Exception
- if the main method cannot be invoked
-
-