I wrote this controller method:
@RequestMapping("/submitFormAdd")
public ModelAndView submitFormAdd(
Model model,
@ModelAttribute("myCandidate") @Valid Candidate myCandidate,
BindingResult result,
RedirectAttributes redirectAttributes) {
if (result.hasErrors()) {
return new ModelAndView("candidateDetailsAdd");
}
myCandidate.setDate(new Date());
candidateService.add(myCandidate);
redirectAttributes.addAttribute("message", "added Correctly at "+ new Date() );
redirectAttributes.addAttribute("id", myCandidate.getId());
ModelAndView modelAndView = new ModelAndView(
"redirect:loadCandidateById");
return modelAndView;
}
UPDATE
myCandidate instantiants so:
@ModelAttribute(value = "myCandidate")
public Candidate loadCandidateById(
@RequestParam(required = false) Integer candidateId) {
if (candidateId != null)
return candidateService.findById(candidateId);
return null;
}
What way can I test that this method gets Candidate ?
I use MockMvc.