[英]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 当我因以下错误尝试在tomcat上启动它时,我的tomcat应用程序拒绝构建
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是什么意思。
302 means temporary redirecting request. 302表示临时重定向请求。 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. 当需要完成网址重定向时,我们可以使用302
状态代码并将网址作为标头中的参数来完成。
Since you are doing a redirection, I think you should expect a 302 response as well. 由于您正在进行重定向,因此我认为您也应该收到302响应。 status().isOk()
means 200
status code. status().isOk()
表示200
状态代码。 Check is there any method for temporary redirect or just put 302 there. 检查是否有任何用于临时重定向的方法,或者只是在其中放置302。 hence it can check for 302 code instead of 200. 因此它可以检查302代码而不是200。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.