简体   繁体   English

java.lang.AssertionError:预期状态:<200>但原为:<302> itShouldAllowAccessToSecuredPageForPermittedUser

[英]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.

相关问题 java.lang.AssertionError:预期状态:&lt;200&gt;但原为:&lt;405&gt; - java.lang.AssertionError: Status expected:<200> but was:<405> @RequestMapping java.lang.AssertionError:预期状态:200 实际:404 - @RequestMapping java.lang.AssertionError: Status Expected :200 Actual :404 java.lang.AssertionError: Status expected:&lt;200&gt; but was:&lt;404&gt; in Junit test - java.lang.AssertionError: Status expected:<200> but was:<404> in Junit test java.lang.AssertionError:预期状态:&lt;200&gt;但原为:&lt;201&gt; - java.lang.AssertionError: Status expected:<200> but was:<201> java.lang.AssertionError:预期状态:&lt;200&gt;但原为:&lt;404&gt; - java.lang.AssertionError: Status expected:<200> but was:<404> java.lang.AssertionError:预期状态:&lt;200&gt;,但在静态服务中为:&lt;404&gt; - java.lang.AssertionError: Status expected:<200> but was:<404> in restful services java.lang.AssertionError: 预期状态:&lt;200&gt; 但为:&lt;400&gt; - java.lang.AssertionError: Status expected:<200> but was:<400> java.lang.AssertionError:预期状态:&lt;400&gt; 但原为:&lt;200&gt; 预期:400 实际:200 - java.lang.AssertionError: Status expected:<400> but was:<200> Expected :400 Actual :200 java.lang.AssertionError:预期状态:&lt;200&gt; 但原为:&lt;404&gt; Spring 引导页面未找到 - java.lang.AssertionError: Status expected:<200> but was:<404> Spring Boot Page Not found 我在尝试进行单元测试时收到 java.lang.AssertionError: Status expected:&lt;200&gt; but was:&lt;401&gt; - I'm getting a java.lang.AssertionError: Status expected:<200> but was:<401> when trying to do unit tests
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM