Java Code Examples for org.springframework.restdocs.mockmvc.RestDocumentationResultHandler#document()
The following examples show how to use
org.springframework.restdocs.mockmvc.RestDocumentationResultHandler#document() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserControllerDocumentation.java From spring-tutorials with Apache License 2.0 | 6 votes |
private void insertUser(User user) throws Exception { RestDocumentationResultHandler document = documentPrettyPrintReqResp("insertUser"); document.document( requestFields(userFields(false)), responseFields(userFields(false)) ); this.mockMvc.perform(post("/api/v1/users") .accept(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(user)) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andDo(document); }
Example 2
Source File: UserControllerDocumentation.java From spring-tutorials with Apache License 2.0 | 6 votes |
private void getUser(UUID userId) throws Exception { RestDocumentationResultHandler document = documentPrettyPrintReqResp("getUser"); document.document( pathParameters(userPathParams()), responseFields(userFields(false)) ); this.mockMvc.perform(get("/api/v1/users/{userId}", userId) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("userId").isNotEmpty()) .andExpect(jsonPath("firstName").isNotEmpty()) .andExpect(jsonPath("lastName").isNotEmpty()) .andExpect(jsonPath("username").isNotEmpty()) .andDo(document); }
Example 3
Source File: UserControllerDocumentation.java From spring-tutorials with Apache License 2.0 | 6 votes |
private void getUsers() throws Exception { RestDocumentationResultHandler document = documentPrettyPrintReqResp("getUsers"); document.document( pathParameters( parameterWithName("page").description("Page of results"), parameterWithName("size").description("Size of results") ), responseFields(userFields(true)) ); this.mockMvc.perform(get("/api/v1/users?page={page}&size={size}", 0, 10) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$").isArray()) .andExpect(jsonPath("[*].userId").isNotEmpty()) .andExpect(jsonPath("[*].firstName").isNotEmpty()) .andExpect(jsonPath("[*].lastName").isNotEmpty()) .andExpect(jsonPath("[*].username").isNotEmpty()) .andDo(document); }
Example 4
Source File: UserControllerDocumentation.java From spring-tutorials with Apache License 2.0 | 6 votes |
private void updateUser(User user) throws Exception { RestDocumentationResultHandler document = documentPrettyPrintReqResp("updateUser"); document.document( pathParameters(userPathParams()), requestFields(userFields(false)), responseFields(userFields(false)) ); this.mockMvc.perform( put("/api/v1/users/{userId}", user.getUserId()) .accept(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(user)) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andDo(document); }
Example 5
Source File: UserControllerDocumentation.java From spring-tutorials with Apache License 2.0 | 5 votes |
private void deleteUser(UUID userId) throws Exception { RestDocumentationResultHandler document = documentPrettyPrintReqResp("deleteUser"); document.document( pathParameters(userPathParams()), responseFields(userFields(false)) ); this.mockMvc.perform(delete("/api/v1/users/{userId}", userId) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andDo(document); }