RootResource implements RootApi { protected Link methodLink(String rel, Method m) { Path resource = m.getDeclaringClass().getAnnotation(Path.class); Path method = m.getAnnotation(Path.class); String href = resource.value() + "/" + method.value(); href = href.replaceAll("/+", "/").replaceAll("/$", ""); if (rel == null) { rel = generateRel(href); } return new Link().rel(rel).href(href); } @Inject  RootResource(Configuration config); @SecurityHole(noAuth = true, anon = true) List<Link> getRootResources(); static final Map<Object, String> RESOURCE_CLASSES; }
@Test public void getMethodEntryWithSlash() throws NoSuchMethodException { Method m = FooResource.class.getMethod("methodWithSlash"); Link result = rootResource.methodLink("hello_world", m); assertEquals("hello_world", result.getRel()); assertEquals("/foo/slash", result.getHref()); }
@Test public void getMethodEntryWithOutSlash() throws NoSuchMethodException { Method m = FooResource.class.getMethod("methodWithoutSlash"); Link result = rootResource.methodLink("hello_world", m); assertEquals("hello_world", result.getRel()); assertEquals("/foo/noslash", result.getHref()); }
@Test public void getMethodEntryWithTrailingSlash() throws NoSuchMethodException { Method m = FooResource.class.getMethod("methodWithTrailingSlash"); Link result = rootResource.methodLink("hello_world", m); assertEquals("hello_world", result.getRel()); assertEquals("/foo/trailingslash", result.getHref()); }