private ArrayList<Map<String, String>> foo(String path, Map<String, String> parameters) { // Convert HashMap<String, String[]> tmp = new HashMap<String, String[]>(); for (Map.Entry<String, String> entry : parameters.entrySet()) { tmp.put(entry.getKey(), new String[]{entry.getValue()}); } // Iterator<RouteMatch> result = matcher(path, tmp); // ArrayList<Map<String, String>> a = new ArrayList<Map<String, String>>(); while (result.hasNext()) { HashMap<String, String> actual = new HashMap<String, String>(); for (Map.Entry<PathParam, String> entry : result.next().getMatched().entrySet()) { actual.put(entry.getKey().getName(), entry.getValue()); } a.add(actual); } // return a; }
public Route popupate(Route parent) { Map<String, PathParam.Builder> parameters; if (this.parameters != null && this.parameters.size() > 0) { parameters = new HashMap<String, PathParam.Builder>(this.parameters.size()); for (Map.Entry<String, ParamDescriptor> parameter : this.parameters.entrySet()) { ParamDescriptor paramDescriptor = parameter.getValue(); PathParam.Builder builder = PathParam.matching(paramDescriptor.pattern); if (paramDescriptor.preservePath != null) { builder.setPreservePath(paramDescriptor.preservePath); } if (paramDescriptor.captureGroup != null) { builder.setCaptureGroup(paramDescriptor.captureGroup); } parameters.put(parameter.getKey(), builder); } } else { parameters = Collections.emptyMap(); } return parent.append(path, parameters); } }
return new PathParam( name, preservePath,
public Route popupate(Route parent) { Map<String, PathParam.Builder> parameters; if (this.parameters != null && this.parameters.size() > 0) { parameters = new HashMap<String, PathParam.Builder>(this.parameters.size()); for (Map.Entry<String, ParamDescriptor> parameter : this.parameters.entrySet()) { ParamDescriptor paramDescriptor = parameter.getValue(); PathParam.Builder builder = PathParam.matching(paramDescriptor.pattern); if (paramDescriptor.preservePath != null) { builder.setPreservePath(paramDescriptor.preservePath); } if (paramDescriptor.captureGroup != null) { builder.setCaptureGroup(paramDescriptor.captureGroup); } parameters.put(parameter.getKey(), builder); } } else { parameters = Collections.emptyMap(); } return parent.append(path, parameters); } }
public void renderURL(PropertyMap properties, MimeType mimeType, Appendable appendable) throws IOException { // Render base URL http.renderRequestURL(appendable); // Render path UriBuilder writer = new UriBuilder(appendable, mimeType); match.render(writer); // Retain matched parameters for filtering later Set<String> matched = match.getMatched().isEmpty() ? Collections.<String>emptySet() : new HashSet<String>(match.getMatched().size()); for (PathParam param : match.getMatched().keySet()) { matched.add(param.getName()); } // Render remaining parameters which have not been rendered yet for (ResponseParameter parameter : parameters.values()) { if (!matched.contains(parameter.getName())) { for (int i = 0;i < parameter.size();i++) { writer.appendQueryParameter(parameter.getEncoding(), parameter.getName(), parameter.get(i)); } } } } };
return new PathParam( name, preservePath,
@Test public void testDisjunction() throws Exception { RouterAssert router = new RouterAssert(); router.append("/{a}{b}", Collections.singletonMap(Names.A, PathParam.matching("a|b"))); // Map<String, String> expectedParameters = new HashMap<String, String>(); expectedParameters.put(Names.A, "a"); expectedParameters.put(Names.B, "c"); // router.assertRoute(expectedParameters, "/ac"); expectedParameters.put(Names.A, "b"); router.assertRoute(expectedParameters, "/bc"); }
public void renderURL(PropertyMap properties, MimeType mimeType, Appendable appendable) throws IOException { // Render base URL http.renderRequestURL(appendable); // Render path UriBuilder writer = new UriBuilder(appendable, mimeType); match.render(writer); // Retain matched parameters for filtering later Set<String> matched = match.getMatched().isEmpty() ? Collections.<String>emptySet() : new HashSet<String>(match.getMatched().size()); for (PathParam param : match.getMatched().keySet()) { matched.add(param.getName()); } // Render remaining parameters which have not been rendered yet for (ResponseParameter parameter : parameters.values()) { if (!matched.contains(parameter.getName())) { for (int i = 0;i < parameter.size();i++) { writer.appendQueryParameter(parameter.getEncoding(), parameter.getName(), parameter.get(i)); } } } } };
@Test public void testDisjunction() throws Exception { RouterAssert router = new RouterAssert(); router.append("/{a}{b}", Collections.singletonMap(Names.A, PathParam.matching("a|b"))); // Map<String, String> expectedParameters = new HashMap<String, String>(); expectedParameters.put(Names.A, "a"); expectedParameters.put(Names.B, "c"); // router.assertRoute(expectedParameters, "/ac"); expectedParameters.put(Names.A, "b"); router.assertRoute(expectedParameters, "/bc"); }
private ArrayList<Map<String, String>> foo(String path, Map<String, String> parameters) { // Convert HashMap<String, String[]> tmp = new HashMap<String, String[]>(); for (Map.Entry<String, String> entry : parameters.entrySet()) { tmp.put(entry.getKey(), new String[]{entry.getValue()}); } // Iterator<RouteMatch> result = matcher(path, tmp); // ArrayList<Map<String, String>> a = new ArrayList<Map<String, String>>(); while (result.hasNext()) { HashMap<String, String> actual = new HashMap<String, String>(); for (Map.Entry<PathParam, String> entry : result.next().getMatched().entrySet()) { actual.put(entry.getKey().getName(), entry.getValue()); } a.add(actual); } // return a; }
@Test public void testLanguage3() throws Exception { RouterAssert router = new RouterAssert(); Route r = router. append("/public/{gtn:lang}", Collections.singletonMap(Names.GTN_LANG, PathParam.matching(LANG_PATTERN).preservePath(true))). append("{gtn:sitename}{gtn:path}", Collections.singletonMap(Names.GTN_PATH, PathParam.matching(".*").preservePath(true))); Map<String, String> expectedParameters = new HashMap<String, String>(); expectedParameters.put(Names.GTN_LANG, "fr"); expectedParameters.put(Names.GTN_SITENAME, "classic"); expectedParameters.put(Names.GTN_PATH, "/home"); // // assertEquals(Collections.<String, String>emptyMap(), router.route("/public")); router.assertRoute(expectedParameters, "/public/fr/classic/home"); expectedParameters.put(Names.GTN_PATH, ""); router.assertRoute(expectedParameters, "/public/fr/classic"); expectedParameters.put(Names.GTN_LANG, ""); expectedParameters.put(Names.GTN_PATH, "/home"); router.assertRoute(expectedParameters, "/public/classic/home"); }
public Map<String, String> assertRoute(Route expectedRoute, String path, Map<String, String> parameters) { // HashMap<String, String[]> tmp = new HashMap<String, String[]>(); for (Map.Entry<String, String> entry : parameters.entrySet()) { tmp.put(entry.getKey(), new String[]{entry.getValue()}); } // Iterator<RouteMatch> result = matcher(path, tmp); // Assert.assertTrue(result.hasNext()); RouteMatch match = result.next(); Assert.assertSame(expectedRoute, match.getRoute()); // Map<String, String> ret = new HashMap<String, String>(); for (Map.Entry<PathParam, String> entry : match.getMatched().entrySet()) { ret.put(entry.getKey().getName(), entry.getValue()); } // return ret; }
@Test public void testLanguage3() throws Exception { RouterAssert router = new RouterAssert(); Route r = router. append("/public/{gtn:lang}", Collections.singletonMap(Names.GTN_LANG, PathParam.matching(LANG_PATTERN).preservePath(true))). append("{gtn:sitename}{gtn:path}", Collections.singletonMap(Names.GTN_PATH, PathParam.matching(".*").preservePath(true))); Map<String, String> expectedParameters = new HashMap<String, String>(); expectedParameters.put(Names.GTN_LANG, "fr"); expectedParameters.put(Names.GTN_SITENAME, "classic"); expectedParameters.put(Names.GTN_PATH, "/home"); // // assertEquals(Collections.<String, String>emptyMap(), router.route("/public")); router.assertRoute(expectedParameters, "/public/fr/classic/home"); expectedParameters.put(Names.GTN_PATH, ""); router.assertRoute(expectedParameters, "/public/fr/classic"); expectedParameters.put(Names.GTN_LANG, ""); expectedParameters.put(Names.GTN_PATH, "/home"); router.assertRoute(expectedParameters, "/public/classic/home"); }
public Map<String, String> assertRoute(Route expectedRoute, String path, Map<String, String> parameters) { // HashMap<String, String[]> tmp = new HashMap<String, String[]>(); for (Map.Entry<String, String> entry : parameters.entrySet()) { tmp.put(entry.getKey(), new String[]{entry.getValue()}); } // Iterator<RouteMatch> result = matcher(path, tmp); // Assert.assertTrue(result.hasNext()); RouteMatch match = result.next(); Assert.assertSame(expectedRoute, match.getRoute()); // Map<String, String> ret = new HashMap<String, String>(); for (Map.Entry<PathParam, String> entry : match.getMatched().entrySet()) { ret.put(entry.getKey().getName(), entry.getValue()); } // return ret; }
@Test public void testPreservePath() throws Exception { RouterAssert router = new RouterAssert(); router.append("/{a}", Collections.singletonMap(Names.A, PathParam.matching(".*").preservePath(true))); router.assertRoute(Collections.singletonMap(Names.A, "a"), "/a"); router.assertRoute(Collections.singletonMap(Names.A, "//"), "///"); router.assertRoute(Collections.singletonMap(Names.A, "a/"), "/a/"); } }
RequestParameter requestParameter = RequestParameter.create(entry.getKey().getName(), entry.getValue()); requestParameters.put(requestParameter.getName(), requestParameter);
@Test public void testLang() throws Exception { RouterAssert router = new RouterAssert(); router.append("/{a}b", Collections.singletonMap(Names.A, PathParam.matching("(([A-Za-z]{2})/)?").preservePath(true))); // router.assertRoute(Collections.singletonMap(Names.A, "fr/"), "/fr/b"); router.assertRoute(Collections.singletonMap(Names.A, ""), "/b"); }
RequestParameter requestParameter = RequestParameter.create(entry.getKey().getName(), entry.getValue()); requestParameters.put(requestParameter.getName(), requestParameter);
@Test public void testLang() throws Exception { RouterAssert router = new RouterAssert(); router.append("/{a}b", Collections.singletonMap(Names.A, PathParam.matching("(([A-Za-z]{2})/)?").preservePath(true))); // router.assertRoute(Collections.singletonMap(Names.A, "fr/"), "/fr/b"); router.assertRoute(Collections.singletonMap(Names.A, ""), "/b"); }
@Test public void testCaptureGroup() throws Exception { RouterAssert router = new RouterAssert(); router.append("/{a}", Collections.singletonMap(Names.A, PathParam.matching("a(.)c").captureGroup(true))); // router.assertRoute(Collections.singletonMap(Names.A, "b"), "/abc"); }