Skip to content

Instantly share code, notes, and snippets.

@simonpai
Created August 19, 2015 03:16
Show Gist options
  • Save simonpai/a2d7aa0832854df4634a to your computer and use it in GitHub Desktop.
Save simonpai/a2d7aa0832854df4634a to your computer and use it in GitHub Desktop.
Vert.x 3.x HttpClient::requestAbs test case
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.http.HttpMethod;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Created by simonpai on 2015/8/19.
*/
@RunWith(VertxUnitRunner.class)
public class RequestAbs {
Vertx vertx;
@Before
public void before(TestContext context) {
vertx = Vertx.vertx();
}
@After
public void after(TestContext context) {
vertx.close(context.asyncAssertSuccess());
}
@Test
public void requestAbs(TestContext context) {
HttpClient client = vertx.createHttpClient(new HttpClientOptions().setDefaultPort(80));
try {
client.requestAbs(HttpMethod.GET, "http://www.google.com", res -> {}).end();
//client.request(HttpMethod.GET, "www.google.com", "/", res -> {}).end(); // this works
} catch (Exception e) {
context.fail();
} finally {
client.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment