@Test public void testPrecedence() throws Exception { RouterAssert router = new RouterAssert(); router.append("/a"); router.append("/{p}/b", Collections.singletonMap(Names.P, PathParam.matching("a"))); // router.assertRoute(Collections.<String, String>emptyMap(), "a"); router.assertRoute(Collections.<String, String>emptyMap(), "/a"); assertNull(router.route("/a/")); router.assertRoute(Collections.singletonMap(Names.P, "a"), "/a/b"); }
@Test public void testMatcher() throws Exception { RouterAssert router = new RouterAssert(); Route a = router.append("/{a}"); Route b = router.append("/a"); // router.assertRoutes(Arrays.asList(a, b), "/a"); }
@Test public void testTwoRules1() throws Exception { RouterAssert router = new RouterAssert(); Route a = router.append("/a"); Route b = router.append("/a/b"); // router.assertRoute(a, "/a"); router.assertRoute(b, "/a/b"); }
@Test public void testPartialMatching() throws Exception { RouterAssert router = new RouterAssert(); router.append("/{a}", Collections.singletonMap(Names.A, PathParam.matching("abc").preservePath(true))); // assertNull(router.route("/abcdef")); }
public Map<String, String> assertRoute(Route expectedRoute, String path) { return assertRoute(expectedRoute, path, Collections.<String, String>emptyMap()); }
@Override public void setUp() throws Exception { this.router = new RouterAssert(); Map<String, PathParam.Builder> params = Collections.singletonMap(Names.GTN_PATH, PathParam.matching(".*").preservePath(true)); portal = router.append("/private/{gtn:sitetype}/{gtn:sitename}{gtn:path}", params); group = router.append("/groups/{gtn:sitetype}/{gtn:sitename}{gtn:path}", params); user = router.append("/users/{gtn:sitetype}/{gtn:sitename}{gtn:path}", params); }
public void assertRoutes(List<Map<String, String>> expected, String path) { AbstractTestCase.assertEquals(expected, foo(path, Collections.<String, String>emptyMap())); } }
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); }
@Test public void testTwoRules1() throws Exception { RouterAssert router = new RouterAssert(); Route a = router.append("/a"); Route b = router.append("/a/b"); // router.assertRoute(a, "/a"); router.assertRoute(b, "/a/b"); }
@Test public void testPartialMatching() throws Exception { RouterAssert router = new RouterAssert(); router.append("/{a}", Collections.singletonMap(Names.A, PathParam.matching("abc").preservePath(true))); // assertNull(router.route("/abcdef")); }
public Map<String, String> assertRoute(Route expectedRoute, String path) { return assertRoute(expectedRoute, path, Collections.<String, String>emptyMap()); }
@Override public void setUp() throws Exception { this.router = new RouterAssert(); Map<String, PathParam.Builder> params = Collections.singletonMap(Names.GTN_PATH, PathParam.matching(".*").preservePath(true)); portal = router.append("/private/{gtn:sitetype}/{gtn:sitename}{gtn:path}", params); group = router.append("/groups/{gtn:sitetype}/{gtn:sitename}{gtn:path}", params); user = router.append("/users/{gtn:sitetype}/{gtn:sitename}{gtn:path}", params); }
public void assertRoutes(List<Map<String, String>> expected, String path) { AbstractTestCase.assertEquals(expected, foo(path, Collections.<String, String>emptyMap())); } }
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); }
@Test public void testRoot2() throws Exception { RouterAssert router = new RouterAssert(); router.append(""); // router.assertRoute(Collections.<String, String>emptyMap(), ""); router.assertRoute(Collections.<String, String>emptyMap(), "/"); assertNull(router.route("/a")); assertNull(router.route("a")); }
@Test public void testTwoRules2() throws Exception { RouterAssert router = new RouterAssert(); Route a = router.append("/{a}"); Route b = router.append("/{a}/b"); // router.assertRoute(a, Collections.singletonMap(Names.A, "a"), "/a"); router.assertRoute(b, Collections.singletonMap(Names.A, "a"), "/a/b"); }
@Test public void testMatcher() throws Exception { RouterAssert router = new RouterAssert(); Route a = router.append("/{a}"); Route b = router.append("/a"); // router.assertRoutes(Arrays.asList(a, b), "/a"); }
public void assertRoute(Map<String, String> expected, String path) { assertRoute(expected, path, Collections.<String, String>emptyMap()); }
public void assertRoutes(List<Map<String, String>> expected, String path, Map<String, String> parameters) { AbstractTestCase.assertEquals(expected, foo(path, parameters)); }
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; }