@Test public void testSetRegexGroupsNamesMethod() throws Exception { List<String> groupNames = new ArrayList<>(); groupNames.add("hello"); Route route1 = router.getWithRegex("\\/(?<p0>[a-z]{2})"); route1.setRegexGroupsNames(groupNames); route1.handler(routingContext -> routingContext .response() .setStatusCode(200) .setStatusMessage(routingContext.pathParam("hello")) .end()); testRequest(HttpMethod.GET, "/hi", 200, "hi"); }
@Test public void testRegexGroupsNamesWithMethodOverride() throws Exception { List<String> groupNames = new ArrayList<>(); groupNames.add("FirstParam"); groupNames.add("SecondParam"); Route route = router.getWithRegex("\\/([a-z]{2})([a-z]{2})"); route.setRegexGroupsNames(groupNames); route.handler(routingContext -> routingContext .response() .setStatusCode(200) .setStatusMessage(routingContext.pathParam("FirstParam") + "-" + routingContext.pathParam("SecondParam")) .end()); testRequest(HttpMethod.GET, "/aabb", 200, "aa-bb"); }
@Test public void testSetRegexGroupsNamesMethodWithUnorderedGroups() throws Exception { List<String> groupNames = new ArrayList<>(); groupNames.add("firstParam"); groupNames.add("secondParam"); Route route1 = router.getWithRegex("\\/(?<p1>[a-z]{2})(?<p0>[a-z]{2})"); route1.setRegexGroupsNames(groupNames); route1.handler(routingContext -> routingContext .response() .setStatusCode(200) .setStatusMessage(routingContext.pathParam("firstParam") + "-" + routingContext.pathParam("secondParam")) .end()); testRequest(HttpMethod.GET, "/bbaa", 200, "aa-bb"); }
@Test public void testSetRegexGroupsNamesMethodWithNestedRegex() throws Exception { List<String> groupNames = new ArrayList<>(); groupNames.add("firstParam"); groupNames.add("secondParam"); Route route1 = router.getWithRegex("\\/(?<p1>[a-z]{2}(?<p0>[a-z]{2}))"); route1.setRegexGroupsNames(groupNames); route1.handler(routingContext -> routingContext .response() .setStatusCode(200) .setStatusMessage(routingContext.pathParam("firstParam") + "-" + routingContext.pathParam("secondParam")) .end()); testRequest(HttpMethod.GET, "/bbaa", 200, "aa-bbaa"); }
@Override public Route setRegexGroupsNames(List<String> groups) { return delegate.setRegexGroupsNames(groups); } }
/** * When you add a new route with a regular expression, you can add named capture groups for parameters. <br/> * However, if you need more complex parameters names (like "param_name"), you can add parameters names with * this function. You have to name capture groups in regex with names: "p0", "p1", "p2", ... <br/> * <br/> * For example: If you declare route with regex \/(?<p0>[a-z]*)\/(?<p1>[a-z]*) and group names ["param_a", "param-b"] * for uri /hello/world you receive inside pathParams() the parameter param_a = "hello" * @param groups group names * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.web.Route setRegexGroupsNames(List<String> groups) { delegate.setRegexGroupsNames(groups); return this; }
/** * When you add a new route with a regular expression, you can add named capture groups for parameters. <br/> * However, if you need more complex parameters names (like "param_name"), you can add parameters names with * this function. You have to name capture groups in regex with names: "p0", "p1", "p2", ... <br/> * <br/> * For example: If you declare route with regex \/(?<p0>[a-z]*)\/(?<p1>[a-z]*) and group names ["param_a", "param-b"] * for uri /hello/world you receive inside pathParams() the parameter param_a = "hello" * @param groups group names * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.web.Route setRegexGroupsNames(List<String> groups) { delegate.setRegexGroupsNames(groups); return this; }
@Test public void testSetRegexGroupsNamesMethodWithUnorderedGroups() throws Exception { List<String> groupNames = new ArrayList<>(); groupNames.add("firstParam"); groupNames.add("secondParam"); Route route1 = router.getWithRegex("\\/(?<p1>[a-z]{2})(?<p0>[a-z]{2})"); route1.setRegexGroupsNames(groupNames); route1.handler(routingContext -> routingContext .response() .setStatusCode(200) .setStatusMessage(routingContext.pathParam("firstParam") + "-" + routingContext.pathParam("secondParam")) .end()); testRequest(HttpMethod.GET, "/bbaa", 200, "aa-bb"); }
@Test public void testRegexGroupsNamesWithMethodOverride() throws Exception { List<String> groupNames = new ArrayList<>(); groupNames.add("FirstParam"); groupNames.add("SecondParam"); Route route = router.getWithRegex("\\/([a-z]{2})([a-z]{2})"); route.setRegexGroupsNames(groupNames); route.handler(routingContext -> routingContext .response() .setStatusCode(200) .setStatusMessage(routingContext.pathParam("FirstParam") + "-" + routingContext.pathParam("SecondParam")) .end()); testRequest(HttpMethod.GET, "/aabb", 200, "aa-bb"); }
@Test public void testSetRegexGroupsNamesMethodWithNestedRegex() throws Exception { List<String> groupNames = new ArrayList<>(); groupNames.add("firstParam"); groupNames.add("secondParam"); Route route1 = router.getWithRegex("\\/(?<p1>[a-z]{2}(?<p0>[a-z]{2}))"); route1.setRegexGroupsNames(groupNames); route1.handler(routingContext -> routingContext .response() .setStatusCode(200) .setStatusMessage(routingContext.pathParam("firstParam") + "-" + routingContext.pathParam("secondParam")) .end()); testRequest(HttpMethod.GET, "/bbaa", 200, "aa-bbaa"); }
@Test public void testSetRegexGroupsNamesMethod() throws Exception { List<String> groupNames = new ArrayList<>(); groupNames.add("hello"); Route route1 = router.getWithRegex("\\/(?<p0>[a-z]{2})"); route1.setRegexGroupsNames(groupNames); route1.handler(routingContext -> routingContext .response() .setStatusCode(200) .setStatusMessage(routingContext.pathParam("hello")) .end()); testRequest(HttpMethod.GET, "/hi", 200, "hi"); }