--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/39d70de3-ebe5-463b-8bc3-f2574beb332cn%40googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/CACiEr_Qi-HYwX-9tZJ0r8E9NN4Rvs0FV%3D3Cg%2ByJpjY-PHzoRpw%40mail.gmail.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/CAMqqFuN7uuBiwa9fPgG-Kcmvi5MV%3DKBWzhLv%2BYmqW0v-BOxGiw%40mail.gmail.com.
You can do something like this. In the setup phase create a http server and add your desired handlers/routes.
@RunWith(VertxUnitRunner.class)
public class RestApplicationTest {
@Rule
public static RunTestOnContext rule = new RunTestOnContext();
private int port = 8081;
private WebClient client;
@Before
public void before(TestContext should) {
Async setup = should.async();
Router app = Router.router(rule.vertx());
// add the desired handlers/routes...
rule.vertx()
.createHttpServer()
.requestHandler(app)
.listen(0)
.onFailure(should::fail)
.onSuccess(server -> {
port = server.actualPort();
client = WebClient.create(rule.vertx());
setup.complete();
});
}
@After
public void after() {
client.close();
}
@Test
public void callGreetingTest(TestContext should) {
// Send a request and get a response
Async test = should.async();
client.get(port, "localhost", "/greeting")
.send()
.onFailure(should::fail)
.onSuccess(response -> {
should.assertEquals(401, response.statusCode());
test.complete();
});
}