'MockMvc Test Spring Controller with @Valid

I'm trying to test a controller in my spring project but I don't know how to go on... Google wasn't a great help for me.

@PostMapping
public String processDesign(
        @Valid Taco taco, Errors errors,
        @ModelAttribute Order order) {

    if (errors.hasErrors()) {
        return "redirect:/designView";
    }

    tacoRepo.save(taco);
    order.addDesign(taco);

    return "redirect:/orders/current";
}

This is the code I wanna test. At the moment I can test for the "error-redirection":

    @Test
public void postDesignViewNameAndRedirectedUrlWithError() throws Exception {
    this.mockMvc.perform(post("/design")
            .contentType("application/json"))
            .andExpect(status().is3xxRedirection())
            .andExpect(redirectedUrl("/designView"));
}

But I don't know how to go on. Can someone tell me what to do? Thanks a lot!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source