@Test public void testSimpleGET() { String uri = "/some-uri?foo=bar"; testSimpleRequest(uri, HttpMethod.GET, resp -> testComplete()); }
@Test public void testSimplePOST() { String uri = "/some-uri?foo=bar"; testSimpleRequest(uri, HttpMethod.POST, resp -> testComplete()); }
@Test public void testSimpleGETAbsolute() { String uri = "/some-uri?foo=bar"; testSimpleRequest(uri, HttpMethod.GET, true, resp -> testComplete()); }
@Test public void testNoPathButQueryGETAbsolute() { String uri = "?foo=bar"; testSimpleRequest(uri, HttpMethod.GET, true, resp -> testComplete()); }
@Test public void testSimpleCONNECTAbsolute() { String uri = "/some-uri?foo=bar"; testSimpleRequest(uri, HttpMethod.CONNECT, true, resp -> testComplete()); }
@Test public void testSimpleHEAD() { String uri = "/some-uri?foo=bar"; testSimpleRequest(uri, HttpMethod.HEAD, resp -> testComplete()); }
@Test public void testSimpleTRACE() { String uri = "/some-uri?foo=bar"; testSimpleRequest(uri, HttpMethod.TRACE, resp -> testComplete()); }
@Test public void testSimpleCONNECT() { String uri = "/some-uri?foo=bar"; testSimpleRequest(uri, HttpMethod.CONNECT, resp -> testComplete()); }
@Test public void testSimpleOPTIONS() { String uri = "/some-uri?foo=bar"; testSimpleRequest(uri, HttpMethod.OPTIONS, resp -> testComplete()); }
@Test public void testSimpleTRACEAbsolute() { String uri = "/some-uri?foo=bar"; testSimpleRequest(uri, HttpMethod.TRACE, true, resp -> testComplete()); }
@Test public void testSimplePATCHAbsolute() { String uri = "/some-uri?foo=bar"; testSimpleRequest(uri, HttpMethod.PATCH, true, resp -> testComplete()); }
@Test public void testSimplePUTAbsolute() { String uri = "/some-uri?foo=bar"; testSimpleRequest(uri, HttpMethod.PUT, true, resp -> testComplete()); }
@Test public void testSimpleDELETEAbsolute() { String uri = "/some-uri?foo=bar"; testSimpleRequest(uri, HttpMethod.DELETE, true, resp -> testComplete()); }
@Test public void testListenTwice() throws Exception { server.requestHandler(noOpHandler()); server.listen(onSuccess(v -> testComplete())); assertIllegalStateException(() -> server.listen()); await(); }
@Test public void testListenInvalidHost() { server.close(); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setHost("iqwjdoqiwjdoiqwdiojwd")); server.requestHandler(noOpHandler()); server.listen(onFailure(s -> testComplete())); }
private void testURIAndPath(String uri, String path) { server.requestHandler(req -> { assertEquals(uri, req.uri()); assertEquals(path, req.path()); req.response().end(); }); server.listen(onSuccess(server -> { client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, uri, resp -> testComplete()).end(); })); await(); }
@Test public void testGetAbsoluteURI() { server.requestHandler(req -> { assertEquals(req.scheme() + "://localhost:" + DEFAULT_HTTP_PORT + "/foo/bar", req.absoluteURI()); req.response().end(); }); server.listen(onSuccess(s -> { client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/foo/bar", onSuccess(resp -> resp.endHandler(v -> testComplete()))).end(); })); await(); }
@Test public void testSendFileNotFound() throws Exception { server.requestHandler(req -> { req.response().putHeader("Content-Type", "wibble"); req.response().sendFile("nosuchfile.html"); }); server.listen(onSuccess(s -> { client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onFailure(err -> {})).end(); vertx.setTimer(100, tid -> testComplete()); })); await(); }
@Test public void testConnectInvalidHost() { client.request(HttpMethod.GET, 9998, "255.255.255.255", DEFAULT_TEST_URI, onFailure(resp -> testComplete())) .exceptionHandler(t -> fail("Exception handler should not be called")) .end(); await(); }
@Test public void testConnectInvalidPort() { client.request(HttpMethod.GET, 9998, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onFailure(err -> testComplete())) .exceptionHandler(t -> fail("Exception handler should not be called")) .end(); await(); }