Derive a link's description from its title

Previously, a LinkDescriptor had to be created with both a rel and a
description. If a description was not provided a failure would occur.

This commit relaxes the above-described restriction by allowing a
link's title to be used as its default description. If a descriptor
has a description, it will always be used irrespective of whether or
not the link has a title. If the descriptor does not have a
description and the link does have a title, the link's title will be
used. If the descriptor does not have a description and the link does
not have a title a failure will occur.

Closes gh-105
This commit is contained in:
Andy Wilkinson
2016-04-13 14:01:33 +01:00
parent 984f90fa7b
commit c4b7438708
17 changed files with 137 additions and 27 deletions

View File

@@ -40,7 +40,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.restdocs.hypermedia.Link;
import org.springframework.restdocs.restassured.RestAssuredRestDocumentationIntegrationTests.TestApplication;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
@@ -329,7 +328,10 @@ public class RestAssuredRestDocumentationIntegrationTests {
public ResponseEntity<Map<String, Object>> foo() {
Map<String, Object> response = new HashMap<>();
response.put("a", "alpha");
response.put("links", Arrays.asList(new Link("rel", "href")));
Map<String, String> link = new HashMap<>();
link.put("rel", "rel");
link.put("href", "href");
response.put("links", Arrays.asList(link));
HttpHeaders headers = new HttpHeaders();
headers.add("a", "alpha");
headers.add("Foo", "http://localhost:12345/foo/bar");