/** * Set the path prefix for this route. If set then this route will only match request URI paths which start with this * path prefix. Only a single path or path regex can be set for a route. * @param path the path prefix * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.web.Route path(String path) { delegate.path(path); return this; }
route.path(callbackPath);
@Test public void testInvalidPath() throws Exception { try { router.route("blah"); fail(); } catch (IllegalArgumentException e) { // OK } try { router.route().path("blah"); fail(); } catch (IllegalArgumentException e) { // OK } }
@Test public void testRoutePathBuilderBegin() throws Exception { String path = "/blah"; router.route().path(path + "*").handler(rc -> rc.response().setStatusCode(200).setStatusMessage(rc.request().path()).end()); testPathBegin(path); }
@Test public void testPattern1WithBuilder() throws Exception { router.route().path("/:abc").handler(rc -> rc.response().setStatusMessage(rc.request().params().get("abc")).end()); testPattern("/tim", "tim"); }
@Test public void testRoutePathBuilder() throws Exception { String path = "/blah"; router.route().path(path).handler(rc -> rc.response().setStatusCode(200).setStatusMessage(rc.request().path()).end()); testPathExact(path); }
@Test public void testInvalidPatternWithBuilder() throws Exception { router.route().path("/blah/:!!!/").handler(rc -> { MultiMap params = rc.request().params(); rc.response().setStatusMessage(params.get("!!!")).end(); }); testRequest(HttpMethod.GET, "/blah/tim", 404, "Not Found"); // Because it won't match }
@Test public void testRoutePathAndMethodBuilder() throws Exception { String path = "/blah"; router.route().path(path).method(HttpMethod.GET).handler(rc -> rc.response().setStatusCode(200).setStatusMessage(rc.request().path()).end()); testPathExact(HttpMethod.GET, path); testRequest(HttpMethod.POST, path, 404, "Not Found"); }
@Test public void testRoutePathAndMethodBuilderBegin() throws Exception { String path = "/blah"; router.route().path(path + "*").method(HttpMethod.GET).handler(rc -> rc.response().setStatusCode(200).setStatusMessage(rc.request().path()).end()); testPathBegin(HttpMethod.GET, path); testRequest(HttpMethod.POST, path, 404, "Not Found"); }
@Test public void testRoutePathAndMultipleMethodBuilderBegin() throws Exception { String path = "/blah"; router.route().path(path + "*").method(HttpMethod.GET).method(HttpMethod.POST).handler(rc -> rc.response().setStatusCode(200).setStatusMessage(rc.request().path()).end()); testPathBegin(HttpMethod.GET, path); testPathBegin(HttpMethod.POST, path); testRequest(HttpMethod.PUT, path, 404, "Not Found"); }
@Test public void testRoutePathAndMultipleMethodBuilder() throws Exception { String path = "/blah"; router.route().path(path).method(HttpMethod.GET).method(HttpMethod.POST).handler(rc -> rc.response().setStatusCode(200).setStatusMessage(rc.request().path()).end()); testPathExact(HttpMethod.GET, path); testPathExact(HttpMethod.POST, path); testRequest(HttpMethod.PUT, path, 404, "Not Found"); }
final Route qbitRoute = router.route().path("/hello/*");
final Route qbitRoute = router.route().path("/hello/*");
}); final Route qbitRoute = router.route().path("/hello/*");
private void testRelativeToRoutePath(String pathPrefix) throws Exception { TemplateEngine engine = new TestEngine(false); router.route().handler(context -> { context.put("foo", "badger"); context.put("bar", "fox"); context.next(); }); Route route = router.route(); if (pathPrefix != null) { route.path(pathPrefix + "*"); } route.handler(TemplateHandler.create(engine, "somedir", "text/html")); String expected = "<html>\n" + "<body>\n" + "<h1>Test template</h1>\n" + "foo is badger bar is fox<br>\n" + "</body>\n" + "</html>"; testRequest(HttpMethod.GET, pathPrefix != null ? pathPrefix + "/test-template.html" : "/test-template.html", 200, "OK", expected); }
@Test public void testRoutePathBuilderBegin() throws Exception { String path = "/blah"; router.route().path(path + "*").handler(rc -> rc.response().setStatusCode(200).setStatusMessage(rc.request().path()).end()); testPathBegin(path); }
@Test public void testRoutePathBuilder() throws Exception { String path = "/blah"; router.route().path(path).handler(rc -> rc.response().setStatusCode(200).setStatusMessage(rc.request().path()).end()); testPathExact(path); }
@Test public void testRoutePathAndMethodBuilderBegin() throws Exception { String path = "/blah"; router.route().path(path + "*").method(HttpMethod.GET).handler(rc -> rc.response().setStatusCode(200).setStatusMessage(rc.request().path()).end()); testPathBegin(HttpMethod.GET, path); testRequest(HttpMethod.POST, path, 404, "Not Found"); }
@Test public void testRoutePathAndMultipleMethodBuilderBegin() throws Exception { String path = "/blah"; router.route().path(path + "*").method(HttpMethod.GET).method(HttpMethod.POST).handler(rc -> rc.response().setStatusCode(200).setStatusMessage(rc.request().path()).end()); testPathBegin(HttpMethod.GET, path); testPathBegin(HttpMethod.POST, path); testRequest(HttpMethod.PUT, path, 404, "Not Found"); }
@Test public void testRoutePathAndMultipleMethodBuilder() throws Exception { String path = "/blah"; router.route().path(path).method(HttpMethod.GET).method(HttpMethod.POST).handler(rc -> rc.response().setStatusCode(200).setStatusMessage(rc.request().path()).end()); testPathExact(HttpMethod.GET, path); testPathExact(HttpMethod.POST, path); testRequest(HttpMethod.PUT, path, 404, "Not Found"); }