mercredi 7 septembre 2016

Why cant I use redirectUrl() to test in mockMvc, if using redirection in spring mvc controller

Having such kind of controller redirection:

@RequestMapping("/someUrl")
@Secured("ROLE_USER")
String someMethod() {        
    handler.doSomething();
    return "redirect:/main";
}

I want to test this, like this:

 mockMvc.perform(post("/someUrl")
        .andExpect(status().isOk())
        .andExpect(redirectedUrl("main")); // redirectedUrl("redirect:/main")

I know, that I can test, with using an exact match on view().name("redirect:/main").

But why is redirectedUrl(..) not working ? When testing the value returned is null. Can someone explain ? Is this behaviour, because I do redirection with redirect prefix ?

Aucun commentaire:

Enregistrer un commentaire