#971 - Only expand templated links with Traverson when requested.
This commit is contained in:
committed by
Greg Turnquist
parent
f27160d16f
commit
bee02810f6
@@ -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
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user