|
20 | 20 |
|
21 | 21 | import static java.util.Objects.requireNonNull; |
22 | 22 |
|
23 | | -import org.jooby.Env; |
24 | 23 | import org.jooby.Jooby; |
25 | 24 | import org.junit.rules.ExternalResource; |
26 | 25 |
|
27 | | -import com.google.inject.Binder; |
28 | | -import com.typesafe.config.Config; |
29 | | -import com.typesafe.config.ConfigFactory; |
30 | | -import com.typesafe.config.ConfigValueFactory; |
31 | | - |
| 26 | +/** |
| 27 | + * <p> |
| 28 | + * Junit rule to run integration tests. You can choose between @ClassRule or @Rule. The next example |
| 29 | + * uses ClassRule: |
| 30 | + * |
| 31 | + * <pre> |
| 32 | + * import org.jooby.test.JoobyRule; |
| 33 | + * |
| 34 | + * public class MyIntegrationTest { |
| 35 | + * |
| 36 | + * @ClassRule |
| 37 | + * private static JoobyRule bootstrap = new JoobyRule(new MyApp()); |
| 38 | + * |
| 39 | + * } |
| 40 | + * </pre> |
| 41 | + * |
| 42 | + * <p> |
| 43 | + * Here one and only one instance will be created, which means the application start before the |
| 44 | + * first test and stop after the last test. Application state is shared between tests. |
| 45 | + * </p> |
| 46 | + * <p> |
| 47 | + * While with Rule a new application is created per test. If you have N test, then the application |
| 48 | + * will start/stop N times: |
| 49 | + * </p> |
| 50 | + * |
| 51 | + * <pre> |
| 52 | + * import org.jooby.test.JoobyRule; |
| 53 | + * |
| 54 | + * public class MyIntegrationTest { |
| 55 | + * |
| 56 | + * @Rule |
| 57 | + * private static JoobyRule bootstrap = new JoobyRule(new MyApp()); |
| 58 | + * |
| 59 | + * } |
| 60 | + * </pre> |
| 61 | + * |
| 62 | + * <p> |
| 63 | + * You are free to choice the HTTP client of your choice, like Fluent Apache HTTP client, REST |
| 64 | + * Assured, etc.. |
| 65 | + * </p> |
| 66 | + * <p> |
| 67 | + * Here is a full example with REST Assured: |
| 68 | + * </p> |
| 69 | + * |
| 70 | + * <pre>{@code |
| 71 | + * import org.jooby.Jooby; |
| 72 | + * |
| 73 | + * public class MyApp extends Jooby { |
| 74 | + * |
| 75 | + * { |
| 76 | + * get("/", () -> "I'm real"); |
| 77 | + * } |
| 78 | + * |
| 79 | + * } |
| 80 | + * |
| 81 | + * import org.jooby.test.JoobyRyle; |
| 82 | + * |
| 83 | + * public class MyIntegrationTest { |
| 84 | + * |
| 85 | + * @ClassRule |
| 86 | + * static JoobyRule bootstrap = new JoobyRule(new MyApp()); |
| 87 | + * |
| 88 | + * @Test |
| 89 | + * public void integrationTestJustWorks() { |
| 90 | + * get("/") |
| 91 | + * .then() |
| 92 | + * .assertThat() |
| 93 | + * .body(equalTo("I'm real")); |
| 94 | + * } |
| 95 | + * } |
| 96 | + * }</pre> |
| 97 | + * |
| 98 | + * @author edgar |
| 99 | + */ |
32 | 100 | public class JoobyRule extends ExternalResource { |
33 | 101 |
|
34 | | - private static class NoJoin implements Jooby.Module { |
35 | | - |
36 | | - @Override |
37 | | - public void configure(final Env env, final Config config, final Binder binder) { |
38 | | - } |
39 | | - |
40 | | - @Override |
41 | | - public Config config() { |
42 | | - return ConfigFactory.empty("test-config") |
43 | | - .withValue("server.join", ConfigValueFactory.fromAnyRef(false)); |
44 | | - } |
45 | | - } |
46 | | - |
47 | 102 | private Jooby app; |
48 | 103 |
|
| 104 | + /** |
| 105 | + * Creates a new {@link JoobyRule} to run integration tests. |
| 106 | + * |
| 107 | + * @param app Application to test. |
| 108 | + */ |
49 | 109 | public JoobyRule(final Jooby app) { |
50 | 110 | this.app = requireNonNull(app, "App required."); |
51 | | - |
52 | | - app.use(new NoJoin()); |
53 | 111 | } |
54 | 112 |
|
55 | 113 | @Override |
56 | 114 | protected void before() throws Throwable { |
57 | | - app.start(); |
| 115 | + app.start("server.join=false"); |
58 | 116 | } |
59 | 117 |
|
60 | 118 | @Override |
|
0 commit comments