简体   繁体   中英

java.lang.AssertionError: Status expected:<200> but was:<302> itShouldAllowAccessToSecuredPageForPermittedUser

My tomcat application is refusing to build when I try to launch it on tomcat on the following errors

Tests run: 3, Failures: 3, Errors: 0, Skipped: 0, Time elapsed: 13.603 sec <<< FAILURE!
itShouldAllowAccessToSecuredPageForPermittedUser(ie.claddino.chat.LoginTestCase)  Time elapsed: 12.791 sec  <<< FAILURE!
java.lang.AssertionError: Status expected:<200> but was:<302>

This is the method that is failing from controller class

@Test
    public void itShouldAllowAccessToSecuredPageForPermittedUser() throws Exception {
        SecurityContext securityContext = userAuthentication();
        MockHttpSession session = new MockHttpSession();
        session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, securityContext);
        mockMvc.perform(get(SECURED_URI).session(session))
                .andExpect(status().isOk()).andExpect(redirectedUrl(LOGIN_PAGE_URL));
    }*

Please what could be wrong with my application? Please does anyone know what status 302 means.

302 means temporary redirecting request. When there is url redirect to be completed, we can do it using a 302 status code and having the url as a parameter in the header.

Since you are doing a redirection, I think you should expect a 302 response as well. status().isOk() means 200 status code. Check is there any method for temporary redirect or just put 302 there. hence it can check for 302 code instead of 200.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM