Support link formats other than HAL by using a strategy to extract links

This commit is contained in:
Andy Wilkinson
2014-11-05 14:32:35 +00:00
parent 2b858c5cd9
commit e9ac3ad709
6 changed files with 58 additions and 11 deletions

View File

@@ -19,6 +19,7 @@ package com.example.notes;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.springframework.restdocs.core.RestDocumentation.document;
import static org.springframework.restdocs.core.RestDocumentation.halLinks;
import static org.springframework.restdocs.core.RestDocumentation.linkWithRel;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
@@ -94,8 +95,9 @@ public class ApiDocumentation {
@Test
public void indexExample() throws Exception {
document("index-example",
this.mockMvc.perform(get("/")).andExpect(status().isOk()))
.andDocumentHalLinks(
this.mockMvc.perform(get("/"))
.andExpect(status().isOk()))
.andDocumentLinks(halLinks(),
linkWithRel("notes").description(
"The <<resources-notes,Notes resource>>"),
linkWithRel("tags").description(
@@ -171,7 +173,7 @@ public class ApiDocumentation {
.andExpect(jsonPath("body", is(note.get("body"))))
.andExpect(jsonPath("_links.self.href", is(noteLocation)))
.andExpect(jsonPath("_links.note-tags", is(notNullValue())))
.andDocumentHalLinks(
.andDocumentLinks(halLinks(),
linkWithRel("self").description("This <<resources-note,note>>"),
linkWithRel("note-tags").description(
"This note's <<resources-note-tags,tags>>"));
@@ -259,7 +261,7 @@ public class ApiDocumentation {
document("tag-get-example", this.mockMvc.perform(get(tagLocation)))
.andExpect(status().isOk())
.andExpect(jsonPath("name", is(tag.get("name"))))
.andDocumentHalLinks(
.andDocumentLinks(halLinks(),
linkWithRel("self").description("This <<resources-tag,tag>>"),
linkWithRel("tagged-notes")
.description(