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; }
public String render() { try { StringBuilder sb = new StringBuilder(); UriBuilder writer = new UriBuilder(sb, MimeType.PLAIN); render(writer); return sb.toString(); } catch (IOException e) { throw new UndeclaredIOException(e); } } }
public final RouteMatch matches(Map<String, String> parameters) { // HashMap<String, String> unmatched = new HashMap<String, String>(parameters); HashMap<PathParam, String> matched = new HashMap<PathParam, String>(); // if (_matches(unmatched, matched)) { return new RouteMatch(this, unmatched, matched); } else { return null; } }
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)); } } } } };
private void assertMatch(String expected, Route route, Map<String, String> parameters) { RouteMatch match = route.matches(parameters); assertNotNull("Was expecting to match " + expected, match); StringBuilder sb = new StringBuilder(); UriBuilder writer = new UriBuilder(sb); try { match.render(writer); for (Map.Entry<String, String> entry : match.getUnmatched().entrySet()) { writer.appendQueryParameter(entry.getKey(), entry.getValue()); } } catch (IOException e) { throw new UndeclaredIOException(e); } assertEquals(expected, sb.toString()); }
RouteDescriptor routeDesc = getMethods(match.getRoute()); if (routeDesc != null) { ControllerHandler target = this.bridge.getApplication().resolveBean(ControllerService.class).getDescriptor().getMethodByHandle(routeDesc.handle); if (requestMatch != null && (requestMatch.getMatched().size() > 0 || bridge.getRequestContext().getParameters().size() > 0)) { requestParameters = new HashMap<String, RequestParameter>(); for (RequestParameter requestParameter : bridge.getRequestContext().getParameters().values()) { requestParameters.put(requestParameter.getName(), requestParameter); for (Map.Entry<PathParam, String> entry : requestMatch.getMatched().entrySet()) { RequestParameter requestParameter = RequestParameter.create(entry.getKey().getName(), entry.getValue()); requestParameters.put(requestParameter.getName(), requestParameter); if (requestMatch != null) { StringBuilder sb = new StringBuilder(); requestMatch.render(new UriBuilder(sb)); if (!sb.toString().equals(requestPath)) { StringBuilder redirect = new StringBuilder();
public void assertRoutes(Iterable<Route> expected, String path) { Iterator<RouteMatch> matches = matcher(path, Collections.<String, String[]>emptyMap()); List<Route> routes = new ArrayList<Route>(); while (matches.hasNext()) { routes.add(matches.next().getRoute()); } AbstractTestCase.assertEquals(expected, routes); }
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; }
RouteDescriptor routeDesc = getMethods(match.getRoute()); if (routeDesc != null) { ControllerHandler target = this.bridge.getApplication().resolveBean(ControllerService.class).getDescriptor().getMethodByHandle(routeDesc.handle); if (requestMatch != null && (requestMatch.getMatched().size() > 0 || bridge.getRequestContext().getParameters().size() > 0)) { requestParameters = new HashMap<String, RequestParameter>(); for (RequestParameter requestParameter : bridge.getRequestContext().getParameters().values()) { requestParameters.put(requestParameter.getName(), requestParameter); for (Map.Entry<PathParam, String> entry : requestMatch.getMatched().entrySet()) { RequestParameter requestParameter = RequestParameter.create(entry.getKey().getName(), entry.getValue()); requestParameters.put(requestParameter.getName(), requestParameter); if (requestMatch != null) { StringBuilder sb = new StringBuilder(); requestMatch.render(new UriBuilder(sb)); if (!sb.toString().equals(requestPath)) { StringBuilder redirect = new StringBuilder();
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)); } } } } };
public void assertRoutes(Iterable<Route> expected, String path) { Iterator<RouteMatch> matches = matcher(path, Collections.<String, String[]>emptyMap()); List<Route> routes = new ArrayList<Route>(); while (matches.hasNext()) { routes.add(matches.next().getRoute()); } AbstractTestCase.assertEquals(expected, routes); }
private void assertMatch(String expected, Route route, Map<String, String> parameters) { RouteMatch match = route.matches(parameters); assertNotNull("Was expecting to match " + expected, match); StringBuilder sb = new StringBuilder(); UriBuilder writer = new UriBuilder(sb); try { match.render(writer); for (Map.Entry<String, String> entry : match.getUnmatched().entrySet()) { writer.appendQueryParameter(entry.getKey(), entry.getValue()); } } catch (IOException e) { throw new UndeclaredIOException(e); } assertEquals(expected, sb.toString()); }
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 String render() { try { StringBuilder sb = new StringBuilder(); UriBuilder writer = new UriBuilder(sb, MimeType.PLAIN); render(writer); return sb.toString(); } catch (IOException e) { throw new UndeclaredIOException(e); } } }
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; }
public final RouteMatch matches(Map<String, String> parameters) { // HashMap<String, String> unmatched = new HashMap<String, String>(parameters); HashMap<PathParam, String> matched = new HashMap<PathParam, String>(); // if (_matches(unmatched, matched)) { return new RouteMatch(this, unmatched, matched); } else { return null; } }
@Test public void testComponent() throws Exception { Map<String, String> expectedParameters = new HashMap<String, String>(); expectedParameters.put(Names.GTN_SITENAME, "classic"); expectedParameters.put(Names.GTN_SITETYPE, "portal"); expectedParameters.put(Names.GTN_PATH, "/"); // router.assertRoute(portal, expectedParameters, "/private/portal/classic/"); assertEquals("/private/portal/classic/", portal.matches(expectedParameters).render()); }
public RouteMatch next() { if (!hasNext()) { throw new NoSuchElementException(); } Map<PathParam, String> parameters = next.getParameters(); Route route = next.route; next = null; return new RouteMatch(route, parameters); }