Created
May 5, 2016 20:19
-
-
Save alexlehm/9a339fe0223c0adb1ed12ceb0a12dbd2 to your computer and use it in GitHub Desktop.
ProxyTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.After; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import io.vertx.core.Vertx; | |
import io.vertx.core.http.HttpClient; | |
import io.vertx.core.http.HttpClientOptions; | |
import io.vertx.core.http.HttpServer; | |
import io.vertx.core.http.HttpServerOptions; | |
import io.vertx.core.logging.Logger; | |
import io.vertx.core.logging.LoggerFactory; | |
import io.vertx.core.net.JksOptions; | |
import io.vertx.ext.unit.Async; | |
import io.vertx.ext.unit.TestContext; | |
import io.vertx.ext.unit.junit.VertxUnitRunner; | |
import io.vertx.test.core.ConnectHttpProxy; | |
@RunWith(VertxUnitRunner.class) | |
public class ProxyTest { | |
private static final Logger log = LoggerFactory.getLogger(ProxyTest.class); | |
private Vertx vertx = Vertx.vertx(); | |
private ConnectHttpProxy proxy; | |
@Test | |
public void test(TestContext context) { | |
log.info("test starting"); | |
Async async = context.async(); | |
HttpClientOptions options = new HttpClientOptions().setSsl(true).setTrustAll(true).setDefaultPort(4443) | |
.setProxyHost("localhost").setProxyPort(13128); | |
options.setDefaultHost("sdffsdsdfwerjhwerhherjjher.host"); | |
HttpClient client = vertx.createHttpClient(options); | |
client.get("/", resp -> { | |
log.info("response code: " + resp.statusCode()); | |
resp.bodyHandler(data -> { | |
log.info("body text: " + data.toString()); | |
context.assertEquals("this is the reply", data.toString()); | |
}); | |
resp.exceptionHandler(th -> context.fail(th)); | |
resp.endHandler(v -> async.complete()); | |
}).exceptionHandler(th -> context.fail(th)).end(); | |
} | |
@Before | |
public void startServers(TestContext context) { | |
Async async1 = context.async(); | |
Async async2 = context.async(); | |
JksOptions jksOptions = new JksOptions().setPath("keystore.jks").setPassword("password"); | |
HttpServerOptions options = new HttpServerOptions().setHost("localhost").setPort(4443).setSsl(true) | |
.setKeyStoreOptions(jksOptions); | |
HttpServer server = vertx.createHttpServer(options); | |
server.requestHandler(request -> request.response().end("this is the reply")); | |
server.listen(v -> async1.complete()); | |
proxy = new ConnectHttpProxy(null); | |
proxy.start(vertx, v -> async2.complete()); | |
} | |
@After | |
public void stopServers(TestContext context) { | |
proxy.stop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment