"bootique-jetty-junit5" - a test module for Jetty
andrus opened this issue · comments
Let's build a JUnit5 test module for Jetty, like we did for JDBC and Cayenne. It will have the following functionality:
- Disable all the existing connectors and provide a test connector to start on a dynamic port (see #98)
- Provide access to the test HTTP client.
- Help with common response assertions.
Compared to Bootique 1.1, this will provide YAML-free unit test configs, solve potential port conflicts and simplify checking test results.
Example:
// JettyTester provides a bunch of static methods and isn't itself
// a part of the JUnit lifecycle
@BQApp
static final BQRuntime app = Bootique.app("-s")
.autoLoadModules()
// override all app connectors with one test connector
.module(JettyTester.moduleReplacingConnectors())
.createRuntime();
@Test
public void test() {
// obtain client without knowing the port
Response r = JettyTester.getClient(app).request().get();
JettyTester.assertOk(r)
// simple assertions
.assertContent("Hi!")
// custom assertions... Can use Hamcrest, etc.
.assertContent(c -> {
assertNotNull(c);
assertTrue(c.contains("Hi"));
})
}