spring restdocs 문서에 context-path 표현하기
spring restdocs 문서에 context-path 표현하기
java.lang.IllegalArgumentException: requestURI [/] does not start with contextPath [/api]
@AutoConfigureRestDocs
class ContextTest{
void ok() throws Exception {
var objectMapper = new ObjectMapper();
var json = objectMapper.writeValueAsString(BranchLificCategoryDTOUtil.getBranchLificCategoryDTO());
mockMvc.perform(post("/api/context-path").contextPath("/api")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content(json))
.andDo(print())
.andExpect(status().isOk())
.andDo(getDocument());
}
}
restdoc를 할때 test code에 contextPath를 지정해 주면된다.
실제 rest 코드에는 context-path가 지정되지 않는다.
@RestController
public class TestController{
@PostMapping(path = "/context-path", consumes = MimeTypeUtils.APPLICATION_JSON_VALUE, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public void contextPath(@RequestBody @Valid ContextPathDTO dto) {
log.debug("{}", dto);
}
}