Я пытаюсь сделать модульный тест для Spring Controller, но получаю 404 вместо 200 Вот мой метод контроллера:
@Timed
@PostMapping(value = "/aaa/bbb", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@ApiOperation(value = "")
public ModelAndView redirectPsnResponseForCgu(@RequestParam final MultiValueMap<String, String> formData,
final ModelMap model) {
....
}
Вот мой метод испытаний
@Test
public void should_intercept_and_redirect() throws Exception {
final MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
formData.add("pa", "test");
formData.add("par", "test");
formData.add("param", "test");
final String content = AppUtils.printJson(formData.toSingleValueMap(), true);
this.mvc.perform(
post("/base-url/aaa/bbb")
.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)
.params(formData)
.header("origin", "*"))
.andExpect(status().isOk());
}
Это результаты теста. Я не понимаю, почему статус 404! Можете ли вы увидеть, если я что-то упустил в моем коде?
MockHttpServletRequest:
HTTP Method = POST
Request URI = /base-url/aaa/bbb
Parameters = {pa=[test], par=[test], param=[test]}
Headers = [Content-Type:"application/x-www-form-urlencoded", origin:"*"]
Body = <no character encoding set>
Session Attrs = {}
Handler:
Type = org.springframework.web.servlet.resource.ResourceHttpRequestHandler
Async:
Async started = false
Async result = null
Resolved Exception:
Type = null
ModelAndView:
View name = null
View = null
Model = null
FlashMap:
Attributes = null
MockHttpServletResponse:
Status = 404
Error message = null
Headers = [Access-Control-Allow-Origin:"*", Access-Control-Allow-Credentials:"false", Access-Control-Allow-Methods:"GET, POST, DELETE, PUT, OPTIONS", Access-Control-Max-Age:"3600", Access-Control-Allow-Headers:"Origin, Accept, Authorization, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, username", Access-Control-Expose-Headers:"Content-Length, Content-Disposition, Authorization"]
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies = []
java.lang.AssertionError: Status
Expected :200
Actual :404