BBSController { @PostMapping("post") @Secured("ROLE_USER") @Transactional public String post(@RequestParam(value = "problem_id", required = false) Long problemId, @RequestParam(value = "parent_id", required = false) Long parentId, @RequestParam(value = "content", defaultValue = "") String content, @RequestParam(value = "title", defaultValue = "") String title, RedirectAttributes redirectAttributes, Authentication authentication) { final String userId = authentication != null ? authentication.getName() : null; if (!StringUtils.hasText(title)) { throw new BusinessException(BusinessCode.MESSAGE_EMPTY_TITLE); } messageService.save(parentId, problemId, userId, title, content); if (problemId != null) { redirectAttributes.addAttribute("problem_id", problemId); } return "redirect:/bbs"; }  @GetMapping("bbs") String bbs(HttpServletRequest request,
            @RequestParam(value = "problem_id", required = false) Long problemId,
            @RequestParam(value = "size", defaultValue = "50") final int threadLimit,
            @RequestParam(value = "top", defaultValue = "99999999") final long top,
            Model model); @Secured("ROLE_USER") @GetMapping({"postpage", "post"}) String postpage(Model model,
            @RequestParam(value = "problem_id", required = false) Long problemId); @PostMapping("post") @Secured("ROLE_USER") @Transactional String post(@RequestParam(value = "problem_id", required = false) Long problemId,
            @RequestParam(value = "parent_id", required = false) Long parentId,
            @RequestParam(value = "content", defaultValue = "") String content,
            @RequestParam(value = "title", defaultValue = "") String title,
            RedirectAttributes redirectAttributes,
            Authentication authentication); @Secured("ROLE_USER") @GetMapping("showmessage") String showMessage(
            @RequestParam("message_id") long messageId,
            Model model);  }
@Test public void testPost() throws Exception { log.info("post"); Long[] problemIds = {null, mockDataService.problem().getId()}; Long parentId = null; String content = "test"; String title = "title"; SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor user = user(createUser()); for (Long problemId : problemIds) { String redirectedUrl = "/bbs" + (problemId != null ? "?problem_id=" + problemId : ""); MvcResult result = mvc.perform(post("/post").with(user) .param("problem_id", Objects.toString(problemId, "")) .param("parent_id", Objects.toString(parentId, "")) .param("content", content) .param("title", title)) .andExpect(status().isFound()) .andExpect(redirectedUrl(redirectedUrl)) .andReturn(); } mvc.perform(get("/bbs").with(user)) .andExpect(status().is2xxSuccessful()); }