Code example for MockMvc

Methods: perform

0
 
    @Test 
    public void testAdd() throws Exception { 
        log.debug("testing add new user..."); 
 
        HttpSession session = mockMvc.perform(post("/j_security_check") 
            .param("j_username", "admin").param("j_password", "admin")) 
            .andExpect(status().is(HttpStatus.FOUND.value())) 
            .andExpect(redirectedUrl("/")) 
            .andReturn() 
            .getRequest() 
            .getSession(); 
 
        mockMvc.perform((get("/userform").session((MockHttpSession) session)) 
            .param("method", "Add")) 
            .andExpect(status().isOk()) 
            .andExpect(model().attributeExists("user")) 
            .andExpect(model().attribute("user", hasProperty("username", nullValue()))); 
    }