#971 - Only expand templated links with Traverson when requested.

This commit is contained in:
Michael Wirth
2019-04-01 21:03:41 +02:00
committed by Greg Turnquist
parent f27160d16f
commit bee02810f6
2 changed files with 23 additions and 0 deletions

View File

@@ -100,6 +100,12 @@ public class Server implements Closeable {
withBody("{ \"_links\" : { \"self\" : { \"href\" : \"/{?template}\" }}}"). //
withContentType(MediaTypes.HAL_JSON.toString());
onRequest(). //
havingPathEqualTo("/github-with-template"). //
respond(). //
withBody("{ \"foo_url_templated\" : \"" + rootResource() + "/github/{issue}\"}"). //
withContentType(MediaTypes.HAL_JSON.toString());
// Sample traversal of HAL docs based on Spring-a-Gram showcase
ResourceLoader resourceLoader = new DefaultResourceLoader();
org.springframework.core.io.Resource springagramRoot = resourceLoader

View File

@@ -247,6 +247,23 @@ public class TraversonTest {
assertThat(link.isTemplated()).isFalse();
}
@Test
public void returnsTemplatedRequiredLinkIfRequested() {
TraversalBuilder follow = new Traverson(URI.create(server.rootResource().concat("/github-with-template")), MediaTypes.HAL_JSON)
.follow("foo_url_templated");
Link link = follow.asTemplatedLink();
assertThat(link.isTemplated()).isTrue();
assertThat(link.getVariableNames()).contains("template");
link = follow.asLink();
assertThat(link.isTemplated()).isFalse();
}
/**
* @see #258
*/