@Test public void testAcceptsMultiple7() throws Exception { router.route().produces("application/json").produces("text/plain").handler(rc -> { rc.response().setStatusMessage(rc.getAcceptableContentType()); rc.response().end(); }); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9,application/json;q=1.0", 200, "application/json"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9;a,application/json;q=1.0", 200, "application/json"); }
@Test public void testAcceptsMultiple6() throws Exception { router.route().produces("application/json").produces("text/plain").handler(rc -> { rc.response().setStatusMessage(rc.getAcceptableContentType()); rc.response().end(); }); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9,application/json", 200, "application/json"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9,application/json;a", 200, "application/json"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9;a,application/json", 200, "application/json"); }
@Test public void testAcceptsMultiple8() throws Exception { router.route().produces("application/json").produces("text/html").handler(rc -> { rc.response().setStatusMessage(rc.getAcceptableContentType()); rc.response().end(); }); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9,application/json;q=1.0", 200, "text/html"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9;b,application/json;q=1.0", 200, "text/html"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9;b,application/json;q=1.0;a", 200, "application/json"); }
@Test public void testProducesMultiple() throws Exception { router.route().produces("text/html").produces("application/json").handler(rc -> rc.response().end()); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html", 200, "OK"); testRequestWithAccepts(HttpMethod.GET, "/foo", "application/json", 200, "OK"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/json", 404, "Not Found"); testRequestWithAccepts(HttpMethod.GET, "/foo", "something/html", 404, "Not Found"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/json", 404, "Not Found"); testRequestWithAccepts(HttpMethod.GET, "/foo", "application/blah", 404, "Not Found"); }
@Test public void testAcceptsMultiple4() throws Exception { router.route().produces("application/json").produces("text/plain").handler(rc -> { rc.response().setStatusMessage(rc.getAcceptableContentType()); rc.response().end(); }); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain,application/json", 200, "text/plain"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;a,application/json", 200, "text/plain"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain,application/json;a", 200, "application/json"); }
@Test public void testAcceptsMultiple9() throws Exception { router.route().produces("application/json").produces("text/plain").handler(rc -> { rc.response().setStatusMessage(rc.getAcceptableContentType()); rc.response().end(); }); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9,application/json;q=0.8", 200, "text/plain"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9;d,application/json;q=0.8", 200, "text/plain"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;q=0.9,application/json;q=0.8;s", 200, "text/plain"); }
@Test public void testAcceptsMultiple5() throws Exception { router.route().produces("application/json").produces("text/plain").handler(rc -> { rc.response().setStatusMessage(rc.getAcceptableContentType()); rc.response().end(); }); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain,application/json;q=0.9", 200, "text/plain"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain,application/json;q=0.9;a", 200, "text/plain"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain,application/json;a;q=0.9", 200, "text/plain"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,text/plain;a,application/json;q=0.9", 200, "text/plain"); }
@Test public void testAcceptsMultiple3() throws Exception { router.route().produces("application/json").produces("text/plain").handler(rc -> { rc.response().setStatusMessage(rc.getAcceptableContentType()); rc.response().end(); }); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,application/json,text/plain", 200, "application/json"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,application/json;a,text/plain", 200, "application/json"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,application/json,text/plain;a", 200, "text/plain"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,application/json;c,text/plain;a", 200, "application/json"); }
@Test public void testProducesWithParameter() throws Exception { router.route().produces("text/html;boo=ya").handler(rc -> rc.response().end()); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html;boo=ya", 200, "OK"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html;boo", 404, "Not Found"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html", 404, "Not Found"); }
@Test public void testProduces() throws Exception { router.route().produces("text/html").handler(rc -> rc.response().end()); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html", 200, "OK"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/json", 404, "Not Found"); testRequestWithAccepts(HttpMethod.GET, "/foo", "something/html", 404, "Not Found"); testRequest(HttpMethod.GET, "/foo", 200, "OK"); }
@Test public void testProducesAll2() throws Exception { router.route().produces("application/json").handler(rc -> { rc.response().setStatusMessage(rc.getAcceptableContentType()); rc.response().end(); }); testRequestWithAccepts(HttpMethod.GET, "/foo", "*", 200, "application/json"); }
@Test public void testProducesAll1() throws Exception { router.route().produces("application/json").handler(rc -> { rc.response().setStatusMessage(rc.getAcceptableContentType()); rc.response().end(); }); testRequestWithAccepts(HttpMethod.GET, "/foo", "*/*", 200, "application/json"); }
@Test public void testProducesTopLevelTypeWildcard() throws Exception { router.route().produces("application/json").handler(rc -> { rc.response().setStatusMessage(rc.getAcceptableContentType()); rc.response().end(); }); testRequestWithAccepts(HttpMethod.GET, "/foo", "*/json", 200, "application/json"); testRequestWithAccepts(HttpMethod.GET, "/foo", "*/html", 404, "Not Found"); }
@Test public void testProducesMissingSlash() throws Exception { // will assume "*/json" router.route().produces("application/json").handler(rc -> { rc.response().setStatusMessage(rc.getAcceptableContentType()); rc.response().end(); }); testRequestWithAccepts(HttpMethod.GET, "/foo", "json", 200, "application/json"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text", 404, "Not Found"); }
@Test public void testProducesSubtypeWildcard() throws Exception { router.route().produces("text/html").handler(rc -> { rc.response().setStatusMessage(rc.getAcceptableContentType()); rc.response().end(); }); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/*", 200, "text/html"); testRequestWithAccepts(HttpMethod.GET, "/foo", "application/*", 404, "Not Found"); }
@Test public void testAcceptsMultiple1() throws Exception { router.route().produces("application/json").handler(rc -> { rc.response().setStatusMessage(rc.getAcceptableContentType()); rc.response().end(); }); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,application/json,text/plain", 200, "application/json"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,application/json;b,text/plain", 200, "application/json"); }
@Test public void testProducesWithParameterKey() throws Exception { router.route().produces("text/html;boo").handler(rc -> rc.response().end()); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html;boo;itWorks", 200, "OK"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html;boo=ya", 200, "OK"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html;boo", 200, "OK"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html", 404, "Not Found"); testRequestWithAccepts(HttpMethod.GET, "/foo", "*/*", 200, "OK"); }
@Test public void testAcceptsMultiple2() throws Exception { router.route().produces("application/json").handler(rc -> { rc.response().setStatusMessage(rc.getAcceptableContentType()); rc.response().end(); }); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html,application/*,text/plain", 200, "application/json"); testRequestWithAccepts(HttpMethod.GET, "/foo", "text/html;a,application/*,text/plain", 200, "application/json"); }
@Test public void testNoContent() { testRoute.produces("application/json").handler(rc -> rc.response().end()); client.get(testRoute.getPath(), onSuccess(resp -> { assertNull(contentType(resp)); assertEquals(Integer.valueOf(0), contentLength(resp)); testComplete(); })).putHeader(HttpHeaders.ACCEPT, "application/json").end(); await(); }
@Test public void testExistingHeader() { testRoute.produces("application/json").handler(rc -> rc.response().putHeader(CONTENT_TYPE, "text/plain").end()); client.get(testRoute.getPath(), onSuccess(resp -> { assertEquals("text/plain", contentType(resp)); testComplete(); })).putHeader(HttpHeaders.ACCEPT, "application/json").end(); await(); }