ResourceLinkGenerator { public ResourceLink resourceLinkFor(final Method method) { ResourceLink resourceLink = null; if (isCandidateForAnalysis(method)) { final String resourcePath = overriddenOrCalculatedResourcePathFor(method); final URI relationType = relationTypeFrom(method); final URI varTypeBaseUri = this.varTypeBaseUri != null ? this.varTypeBaseUri : relationType; if (relationType != null) { final Hints hints = hintsGenerator.hintsOf(relationType, method); if (resourcePath.matches(".*\\{.*\\}.*")) { resourceLink = templatedLink( relationType, resourcePath, hrefVarsGenerator.hrefVarsFor(varTypeBaseUri, this.varTypeBaseUri == null, method), hints ); } else { resourceLink = directLink( relationType, create(resourcePath), hints ); } } } return resourceLink; } protected  ResourceLinkGenerator(final URI applicationBaseUri,
                                    final URI relationTypeBaseUri,
                                    final URI varTypeBaseUri,
                                    final HintsGenerator hintsGenerator,
                                    final HrefVarsGenerator hrefVarsGenerator); ResourceLink resourceLinkFor(final Method method);  }
@Test public void resourceLinkForDirectLink() throws Exception { ResourceLinkGenerator generator = new TestResourceLinkGenerator(); final ResourceLink resourceLink = generator.resourceLinkFor(TestController.class.getMethod("directLink")); assertEquals(resourceLink.asDirectLink().getHref().toString(), APPLICATION_BASE_URI + "/foo"); }
@Test public void resourceLinkForAnnotatedDirectLink() throws Exception { ResourceLinkGenerator generator = new TestResourceLinkGenerator(); final ResourceLink resourceLink = generator.resourceLinkFor(TestController.class.getMethod("annotatedDirectLink")); assertEquals(resourceLink.asDirectLink().getHref().toString(), "http: }
@Test public void resourceLinkForTemplatedLink() throws Exception { ResourceLinkGenerator generator = new TestResourceLinkGenerator(); final ResourceLink resourceLink = generator.resourceLinkFor(TestController.class.getMethod("templatedLink", String.class)); final String expectedTemplate = APPLICATION_BASE_URI + "/foo/{bar}"; assertEquals(resourceLink.asTemplatedLink().getHrefTemplate(), expectedTemplate); }
@Test public void varTypeForTemplatedLinkWithDefaultVarTypeUri() throws Exception { ResourceLinkGenerator generator = new TestResourceLinkGenerator(); final ResourceLink resourceLink = generator.resourceLinkFor(TestController.class.getMethod("templatedLink", String.class)); final URI expectedVarType = URI.create(RELATION_TYPE_BASE_URI + "/rel/test#bar"); assertNotNull(resourceLink.asTemplatedLink().getHrefVar(expectedVarType)); }
@Test public void varTypeForTemplatedLinkWithBaseVarTypeUri() throws Exception { ResourceLinkGenerator generator = new TestResourceLinkGenerator(VAR_TYPE_BASE_URI); final ResourceLink resourceLink = generator.resourceLinkFor(TestController.class.getMethod("templatedLink", String.class)); final URI expectedVarType = URI.create(VAR_TYPE_BASE_URI.toString() + "/bar"); assertNotNull(resourceLink.asTemplatedLink().getHrefVar(expectedVarType)); }
@Test public void resourceLinkForAnnotatedTemplatedLink() throws Exception { ResourceLinkGenerator generator = new TestResourceLinkGenerator(); final ResourceLink resourceLink = generator.resourceLinkFor(TestController.class.getMethod("templatedLinkWithHrefTemplate", String.class)); final String expectedTemplate = APPLICATION_BASE_URI + "/bar/{foo}"; assertEquals(resourceLink.asTemplatedLink().getHrefTemplate(), expectedTemplate); }