SpringResourceLinkGenerator extends ResourceLinkGenerator { @Override public boolean isCandidateForAnalysis(final Method method) { return AnnotationUtils.findAnnotation(method, RequestMapping.class) != null; } SpringResourceLinkGenerator(final URI applicationBaseUri,
                                       final URI relationTypeBaseUri,
                                       final URI varTypeBaseUri,
                                       final String docRootDir); @Override boolean isCandidateForAnalysis(final Method method);  }
@Test public void shouldUseHrefUriFromSpringAnnotations() throws Exception { final SpringResourceLinkGenerator generator = new SpringResourceLinkGenerator(BASE_URI, BASE_URI, null, null); final Method method = ControllerWithDirectResourceLink.class.getMethod("getSomething"); final boolean isCandidateForAnalysis = generator.isCandidateForAnalysis(method); final ResourceLink resourceLink = generator.resourceLinkFor(method); assertTrue(isCandidateForAnalysis); assertEquals(resourceLink, directLink( BASE_URI.resolve("/rel/bar"), BASE_URI.resolve("/foo"), hintsBuilder() .representedAs("text/html") .allowing(Allow.GET) .build()) ); }
@Test public void shouldOverrideHrefUriUsingHrefAnnotation() throws Exception { final SpringResourceLinkGenerator generator = new SpringResourceLinkGenerator(BASE_URI, BASE_URI, null, null); final Method method = ControllerWithOverriddenFullyQualifiedResourceLink.class.getMethod("getSomething"); final boolean isCandidateForAnalysis = generator.isCandidateForAnalysis(method); final ResourceLink resourceLink = generator.resourceLinkFor(method); assertTrue(isCandidateForAnalysis); assertEquals(resourceLink, directLink( BASE_URI.resolve("/rel/bar"), BASE_URI.resolve("/bar"), hintsBuilder() .representedAs("text/html") .allowing(Allow.GET) .build()) ); }
@Test public void shouldOverrideHrefUriUsingRelativeHrefAnnotation() throws Exception { final SpringResourceLinkGenerator generator = new SpringResourceLinkGenerator(BASE_URI, BASE_URI.normalize(), null, null); final Method method = ControllerWithOverriddenFullyQualifiedResourceLink.class.getMethod("getSomethingElse"); final boolean isCandidateForAnalysis = generator.isCandidateForAnalysis(method); final ResourceLink resourceLink = generator.resourceLinkFor(method); assertTrue(isCandidateForAnalysis); assertEquals(resourceLink, directLink( BASE_URI.resolve("/rel/bar"), BASE_URI.resolve("/bar"), hintsBuilder() .representedAs("text/html") .allowing(Allow.GET) .build()) ); }
@Test public void shouldOverrideHrefTemplateUsingHrefTemplateAnnotation() throws Exception { final SpringResourceLinkGenerator generator = new SpringResourceLinkGenerator(BASE_URI, BASE_URI, null, null); final Method method = ControllerWithOverriddenRelativeTemplatedResourceLink.class.getMethod("getSomething"); final boolean isCandidateForAnalysis = generator.isCandidateForAnalysis(method); final ResourceLink resourceLink = generator.resourceLinkFor(method); assertTrue(isCandidateForAnalysis); assertEquals(resourceLink, templatedLink( BASE_URI.resolve("/rel/bar"), "http: asList(hrefVar("var1", BASE_URI.resolve("/rel/bar#var1"))), hintsBuilder() .representedAs("text/html") .allowing(Allow.GET) .build()) ); }