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

Original issue: #971
This commit is contained in:
Michael Wirth
2019-04-01 21:03:41 +02:00
committed by Greg Turnquist
parent 32cd95f351
commit 060b94e000
2 changed files with 23 additions and 0 deletions

View File

@@ -96,6 +96,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
org.springframework.core.io.Resource springagramRoot = resourceLoader.getResource("classpath:springagram-root.json");
org.springframework.core.io.Resource springagramItems = resourceLoader.getResource("classpath:springagram-items.json");

View File

@@ -239,6 +239,23 @@ public class TraversonTest {
assertThat(link.isTemplated(), is(false));
}
@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
*/