#212 - Traverson can now return the last link.
This commit is contained in:
@@ -285,6 +285,18 @@ public class Traverson {
|
||||
return operations.exchange(traverseToFinalUrl(), GET, prepareRequest(headers), type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Link} found for the last rel int the rels configured to follow.
|
||||
*
|
||||
* @return
|
||||
* @since 0.15
|
||||
*/
|
||||
public Link asLink() {
|
||||
|
||||
Assert.isTrue(rels.size() > 0, "At least one rel needs to be provided!");
|
||||
return new Link(traverseToFinalUrl(), rels.get(rels.size() - 1));
|
||||
}
|
||||
|
||||
private String traverseToFinalUrl() {
|
||||
|
||||
String uri = getAndFindLinkWithRel(baseUri.toString(), rels.iterator());
|
||||
|
||||
@@ -197,6 +197,18 @@ public class TraversonTests {
|
||||
assertThat(value, is("value"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #212
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnLastLinkFound() {
|
||||
|
||||
Link result = traverson.follow("movies").asLink();
|
||||
|
||||
assertThat(result.getHref(), endsWith("/movies"));
|
||||
assertThat(result.getRel(), is("movies"));
|
||||
}
|
||||
|
||||
private void setUpActors() {
|
||||
|
||||
Resource<Actor> actor = new Resource<Actor>(new Actor("Keanu Reaves"));
|
||||
|
||||
Reference in New Issue
Block a user