Add support for modifying a request prior to it being documented
Prior to this commit it was not possible to modify a request prior to it being documented, only a response. This commit builds on the new Operation abstraction to simplify the existing response modification support and to add support for request modification. Closes gh-84
This commit is contained in:
@@ -16,13 +16,17 @@
|
||||
|
||||
package com.example;
|
||||
|
||||
import static org.springframework.restdocs.RestDocumentation.modifyResponseTo;
|
||||
import static org.springframework.restdocs.RestDocumentationRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.removeHeaders;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
|
||||
import static org.springframework.restdocs.RestDocumentation.document;
|
||||
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
public class ResponsePostProcessing {
|
||||
public class Preprocessing {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@@ -30,8 +34,9 @@ public class ResponsePostProcessing {
|
||||
// tag::general[]
|
||||
this.mockMvc.perform(get("/"))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(modifyResponseTo(/* ... */) // <1>
|
||||
.andDocument("index")); // <2>
|
||||
.andDo(document("index",
|
||||
preprocessRequest(removeHeaders("Foo")), // <1>
|
||||
preprocessResponse(prettyPrint()))); // <2>
|
||||
// end::general[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user