#971 - Polishing.
This commit is contained in:
@@ -196,7 +196,8 @@ public class UriTemplate implements Iterable<TemplateVariable>, Serializable {
|
||||
public List<String> getVariableNames() {
|
||||
|
||||
return variables.asList().stream() //
|
||||
.map(TemplateVariable::getName).collect(Collectors.toList());
|
||||
.map(TemplateVariable::getName) //
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.hateoas.client;
|
||||
|
||||
import static org.springframework.http.HttpMethod.*;
|
||||
import static org.springframework.http.HttpMethod.GET;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Value;
|
||||
@@ -58,6 +58,7 @@ import com.jayway.jsonpath.JsonPath;
|
||||
* @author Greg Turnquist
|
||||
* @author Tom Bunting
|
||||
* @author Manish Misra
|
||||
* @author Michael Wirth
|
||||
* @since 0.11
|
||||
*/
|
||||
public class Traverson {
|
||||
@@ -376,10 +377,7 @@ public class Traverson {
|
||||
|
||||
Assert.isTrue(rels.size() > 0, "At least one rel needs to be provided!");
|
||||
|
||||
URIAndHeaders expandedFinalUriAndHeaders = traverseToExpandedFinalUrl();
|
||||
UriStringAndHeaders finalUriAndHeaders = traverseToFinalUrl();
|
||||
|
||||
return new Link(expandFinalUrl ? expandedFinalUriAndHeaders.getUri().toString() : finalUriAndHeaders.getUri(),
|
||||
return new Link(expandFinalUrl ? traverseToExpandedFinalUrl().getUri().toString() : traverseToFinalUrl().getUri(),
|
||||
rels.get(rels.size() - 1).getRel());
|
||||
}
|
||||
|
||||
|
||||
@@ -15,16 +15,8 @@
|
||||
*/
|
||||
package org.springframework.hateoas.client;
|
||||
|
||||
import static net.jadler.Jadler.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.support.MessageSourceAccessor;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
@@ -43,14 +35,25 @@ import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.jadler.Jadler.closeJadler;
|
||||
import static net.jadler.Jadler.initJadler;
|
||||
import static net.jadler.Jadler.onRequest;
|
||||
import static net.jadler.Jadler.port;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Helper class for integration tests.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Greg Turnquist
|
||||
* @author Michael Wirth
|
||||
*/
|
||||
public class Server implements Closeable {
|
||||
|
||||
@@ -103,7 +106,7 @@ public class Server implements Closeable {
|
||||
onRequest(). //
|
||||
havingPathEqualTo("/github-with-template"). //
|
||||
respond(). //
|
||||
withBody("{ \"foo_url_templated\" : \"" + rootResource() + "/github/{issue}\"}"). //
|
||||
withBody("{ \"_links\" : { \"rel_to_templated_link\" : { \"href\" : \"/github/{issue}\" }}}"). //
|
||||
withContentType(MediaTypes.HAL_JSON.toString());
|
||||
|
||||
// Sample traversal of HAL docs based on Spring-a-Gram showcase
|
||||
|
||||
@@ -15,10 +15,12 @@
|
||||
*/
|
||||
package org.springframework.hateoas.client;
|
||||
|
||||
import static net.jadler.Jadler.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.springframework.hateoas.client.Hop.*;
|
||||
import static net.jadler.Jadler.verifyThatRequest;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.springframework.hateoas.client.Hop.rel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -33,9 +35,9 @@ import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.client.Traverson.TraversalBuilder;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpRequest;
|
||||
@@ -53,6 +55,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Greg Turnquist
|
||||
* @author Michael Wirth
|
||||
* @since 0.11
|
||||
*/
|
||||
public class TraversonTest {
|
||||
@@ -247,23 +250,22 @@ public class TraversonTest {
|
||||
assertThat(link.isTemplated()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test // #971
|
||||
public void returnsTemplatedRequiredLinkIfRequested() {
|
||||
|
||||
TraversalBuilder follow = new Traverson(URI.create(server.rootResource().concat("/github-with-template")), MediaTypes.HAL_JSON)
|
||||
.follow("foo_url_templated");
|
||||
Link templatedLink = new Traverson(URI.create(server.rootResource() + "/github-with-template"), MediaTypes.HAL_JSON) //
|
||||
.follow("rel_to_templated_link") //
|
||||
.asTemplatedLink();
|
||||
|
||||
Link link = follow.asTemplatedLink();
|
||||
assertThat(templatedLink.isTemplated()).isTrue();
|
||||
assertThat(templatedLink.getVariableNames()).contains("issue");
|
||||
|
||||
assertThat(link.isTemplated()).isTrue();
|
||||
assertThat(link.getVariableNames()).contains("template");
|
||||
Link expandedLink = templatedLink.expand("42");
|
||||
|
||||
link = follow.asLink();
|
||||
|
||||
assertThat(link.isTemplated()).isFalse();
|
||||
assertThat(expandedLink.isTemplated()).isFalse();
|
||||
assertThat(expandedLink.getHref()).isEqualTo("/github/42");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see #258
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user