I have a springBoot 2.1.9.RELEASE application that uses Spring REST Docs.
I have this method in my TestController
@Test
public void createOK() throws Exception {
String content = ResourceUtils.getResourceFileAsString ("/new_hostel.json");
mockMvc.perform(post("/hostel")
.content(content)
.contentType(APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(document("create-hostel",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
links(halLinks(),
linkWithRel("ld:GetHostel").
description("Get Hostel"),
linkWithRel("curies").
description("Documentation")),
requestFields(
fieldWithPath("description").description("The description"),
fieldWithPath("name").description("The name"),
fieldWithPath("id").description("The id")
)
));
}
but when I run it I have this error:
org.springframework.restdocs.snippet.ModelCreationException: com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
at [Source: (byte[])""; line: 1, column: 0]
at org.springframework.restdocs.hypermedia.LinksSnippet.createModel(LinksSnippet.java:127)
at org.springframework.restdocs.snippet.TemplatedSnippet.document(TemplatedSnippet.java:81)
at org.springframework.restdocs.generate.RestDocumentationGenerator.handle(RestDocumentationGenerator.java:201)
at org.springframework.restdocs.mockmvc.RestDocumentationResultHandler.handle(RestDocumentationResultHandler.java:55)
at org.springframework.test.web.servlet.MockMvc$1.andDo(MockMvc.java:200)
at com.bendiciones.buenas.noches.HostelControllerIT.createOK(HostelControllerIT.java:88)
The links snippet documents hypermedia links in the response. Judging by the error, the response from your controller is empty so there are no links to document. You should either update your test to remove the documentation of the links in the response to the POST
request or update the controller method that handles it to return a body that contains some links.