Improve rels in Spring-HATEOAS based sample and update the docs to match

This commit is contained in:
Andy Wilkinson
2014-11-04 11:02:52 +00:00
parent 57dd861958
commit 91498bb5b6
4 changed files with 13 additions and 12 deletions

View File

@@ -79,7 +79,7 @@ This request will produce a response with the note's details in its body:
include::{generated}/get-note/response.asciidoc[]
Note the `tags` link which we'll make use of later.
Note the `note-tags` link which we'll make use of later.
@@ -141,7 +141,8 @@ As before, a `GET` request executed against this URI will retrieve the note's de
include::{generated}/get-tagged-note/request-response.asciidoc[]
To see the note's tags, execute a `GET` request against the URI of the note's tags link:
To see the note's tags, execute a `GET` request against the URI of the note's
`note-tags` link:
include::{generated}/get-tags/request.asciidoc[]
@@ -163,7 +164,7 @@ This request should produce a `204 No Content` response:
include::{generated}/tag-existing-note/response.asciidoc[]
When we first created this note, we noted the tags link included in its details:
When we first created this note, we noted the `note-tags` link included in its details:
include::{generated}/get-note/response.asciidoc[]

View File

@@ -119,7 +119,7 @@ public class GettingStartedDocumentation {
this.mockMvc.perform(get(noteLocation)).andExpect(status().isOk())
.andExpect(jsonPath("title", is(notNullValue())))
.andExpect(jsonPath("body", is(notNullValue())))
.andExpect(jsonPath("_links.tags", is(notNullValue()))));
.andExpect(jsonPath("_links.note-tags", is(notNullValue()))));
}
String createTag() throws Exception, JsonProcessingException {
@@ -143,7 +143,7 @@ public class GettingStartedDocumentation {
"get-tag",
this.mockMvc.perform(get(tagLocation)).andExpect(status().isOk())
.andExpect(jsonPath("name", is(notNullValue())))
.andExpect(jsonPath("_links.notes", is(notNullValue()))));
.andExpect(jsonPath("_links.tagged-notes", is(notNullValue()))));
}
String createTaggedNote(String tag) throws Exception {
@@ -170,12 +170,12 @@ public class GettingStartedDocumentation {
this.mockMvc.perform(get(tagLocation)).andExpect(status().isOk())
.andExpect(jsonPath("title", is(notNullValue())))
.andExpect(jsonPath("body", is(notNullValue())))
.andExpect(jsonPath("_links.tags", is(notNullValue()))));
.andExpect(jsonPath("_links.note-tags", is(notNullValue()))));
}
void getTags(String taggedNoteLocation) throws Exception {
String tagsLocation = getLink(this.mockMvc.perform(get(taggedNoteLocation))
.andReturn(), "tags");
.andReturn(), "note-tags");
document("get-tags",
this.mockMvc.perform(get(tagsLocation)).andExpect(status().isOk())
.andExpect(jsonPath("_embedded.tags", hasSize(1))));
@@ -201,15 +201,15 @@ public class GettingStartedDocumentation {
void getTagsForExistingNote(String taggedNoteLocation) throws Exception {
String tagsLocation = getLink(this.mockMvc.perform(get(taggedNoteLocation))
.andReturn(), "tags");
.andReturn(), "note-tags");
document("get-tags-for-existing-note",
this.mockMvc.perform(get(tagsLocation)).andExpect(status().isOk())
.andExpect(jsonPath("_embedded.tags", hasSize(1))));
}
private String getLink(MvcResult result, String href)
private String getLink(MvcResult result, String rel)
throws UnsupportedEncodingException {
return JsonPath.parse(result.getResponse().getContentAsString()).read(
"_links.tags.href");
"_links." + rel + ".href");
}
}

View File

@@ -35,7 +35,7 @@ public class NoteResourceAssembler extends ResourceAssemblerSupport<Note, NoteRe
public NoteResource toResource(Note note) {
NoteResource resource = createResourceWithId(note.getId(), note);
resource.add(linkTo(NotesController.class).slash(note.getId()).slash("tags")
.withRel("tags-on-note"));
.withRel("note-tags"));
return resource;
}

View File

@@ -35,7 +35,7 @@ public class TagResourceAssembler extends ResourceAssemblerSupport<Tag, TagResou
public TagResource toResource(Tag tag) {
TagResource resource = createResourceWithId(tag.getId(), tag);
resource.add(linkTo(TagsController.class).slash(tag.getId()).slash("notes")
.withRel("notes-with-tag"));
.withRel("tagged-notes"));
return resource;
}