@Test public void usePatternMatchingForRegexParameters() throws Exception { builder = newBuilder("/abc/{abc:a+b+c+}/def/{def}/ghi/{ghi}"); builder.is(MyResource.class, method.getMethod()); Route route = builder.build(); assertFalse("invalid uri", route.canHandle("/abc/itIsInvalid/def/123/ghi/123.45")); assertTrue("valid uri", route.canHandle("/abc/aaabbccccc/def/-123/ghi/-1")); }
@Test public void usingRegexesWithAsterisksAtTheEnd() throws Exception { builder = newBuilder("/abc/{abc:[0-9A-Z]*}/def/{def}"); builder.is(MyResource.class, method.getMethod()); Route route = builder.build(); assertFalse("invalid uri", route.canHandle("/abc/not_Valid/def/12")); assertTrue("valid uri", route.canHandle("/abc/ABC123/def/12")); assertTrue("valid uri", route.canHandle("/abc/10AB3/def/12")); }
@Test public void usingRegexesWithCurlyBracesNotOnTheEndAndOtherVar() throws Exception { builder = newBuilder("/abc/{abc:[0-9A-Z]{5}}/def/{def}"); builder.is(MyResource.class, method.getMethod()); Route route = builder.build(); assertFalse("invalid uri", route.canHandle("/abc/notValid/def/12")); assertFalse("invalid uri", route.canHandle("/abc/ABC123/def/12")); assertTrue("valid uri", route.canHandle("/abc/10AB3/def/12")); }
@Test @Ignore("Should it work someday?") public void shouldUseGenericParameters() throws SecurityException, NoSuchMethodException { builder = newBuilder("/my/{abc.y}"); Method method = Generic.class.getDeclaredMethods()[0]; builder.is(Specific.class, method); Route route = builder.build(); assertTrue(route.canHandle("/my/123")); assertFalse(route.canHandle("/my/abc")); }
@Test public void usePatternMatchinForPrimitiveParameters() throws Exception { builder = newBuilder("/abc/{abc}/def/{def}/ghi/{ghi}"); builder.is(MyResource.class, method.getMethod()); Route route = builder.build(); assertTrue("valid uri", route.canHandle("/abc/AnythingHere/def/123/ghi/123.45")); assertTrue("valid uri", route.canHandle("/abc/AnythingHere/def/-123/ghi/-1")); assertTrue( "valid uri with integer decimal", route.canHandle("/abc/AnythingHere/def/123/ghi/123")); assertFalse("invalid integer", route.canHandle("/abc/AnythingHere/def/Duh/ghi/123")); assertFalse("invalid decimal", route.canHandle("/abc/AnythingHere/def/123/ghi/kkk")); }
@Test public void shouldSupportPathsWithDotsAndAsterisks() throws SecurityException, NoSuchMethodException { builder = newBuilder("/my/{abc.def*}"); Method method = AbcResource.class.getDeclaredMethods()[0]; builder.is(AbcResource.class, method); Route route = builder.build(); assertTrue(route.canHandle("/my/troublesome/uri")); }