Skip to content

Instantly share code, notes, and snippets.

@Narigo
Created March 13, 2014 07:17
Show Gist options
  • Save Narigo/9523241 to your computer and use it in GitHub Desktop.
Save Narigo/9523241 to your computer and use it in GitHub Desktop.
class YourTest extends TestVerticle {
// usual start(), etc.
private void afterPostActionDo(Handler<HttpClient> nextFn) {
final HttpClient client = vertx.createHttpClient().setHost("localhost").setPort(8080).setKeepAlive(false);
HttpClientRequest req = httpClient.post("/someapi", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse postResp) {
// do something with postResp
postResp.bodyHandler(new Handler<Buffer>() {
public void handle(Buffer body) {
// check body
// let someone else do something with it
nextFn(client);
}
});
}
});
// fill your req stuff and .end() it
}
@Test
public void testGet() {
afterPostActionDo(new Handler<HttpClient>() {
public void handle(HttpClient client) {
client.getNow("/someapi/", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse getResp) {
getResp.bodyHandler(new Handler<Buffer>() {
public void handle(Buffer body) {
//do something
testComplete();
}
});
}
});
}
}
}
@Test
public void testPut() { /* similar to testGet */ }
// more tests
}
class YourTest extends TestVerticle {
// usual start(), etc.
private def afterPostActionDo(nextFn: HttpClient => Unit): Unit = {
val client = vertx.createHttpClient().setHost("localhost").setPort(8080).setKeepAlive(false)
val req = httpClient.post("/someapi", { postResp =>
// do something with postResp
postResp.bodyHandler({ body =>
// check body
// let someone else do something with it
nextFn(client);
})
})
// fill your req stuff and .end() it
}
@Test
def testGet(): Unit = afterPostActionDo({client =>
client.getNow("/someapi/", { getResp =>
getResp.bodyHandler({ body =>
//do something
testComplete()
})
})
})
@Test
def testPut(): Unit = { /* similar to testGet */ }
// more tests
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment