首页 > 解决方案 > 检票口测试中的 PageExpiredException

问题描述

我已经将 wicket 从 8.10 更新到 8.11,现在我在单元测试中有很多失败。所有失败的测试都失败并出现一个错误:

@Test
public void testPanel() {
    Panel panel = new MyPanel("id");

    getTester().startComponentInPage(panel); // fails with PageExpiredException: Page with id '0' has expired.
}

没有可用的堆栈跟踪,控制台显示以下日志:

15:35:19.300 [main] WARN  RequestCycleExtra - ********************************
15:35:19.300 [main] WARN  RequestCycleExtra - Handling the following exception
org.apache.wicket.protocol.http.PageExpiredException: Page with id '0' has expired.
15:35:19.300 [main] WARN  RequestCycleExtra - ********************************

org.apache.wicket.protocol.http.PageExpiredException: Page with id '0' has expired.

因此,我在隔离中测试组件的所有测试都失败了。测试,我用以下代码运行页面,没问题:

getTester().startPage(pageClass, getPageParameters());

在 wicket 8.10 中,所有测试都通过了。

有什么问题?这是一个错误还是我错过了应用程序配置中的某些内容?

更新:

此处描述了此错误: https ://issues.apache.org/jira/browse/WICKET-6856

在每次测试之前,会话无效,这是异常的原因:

@Before
public void prepare() {
    logout(); // If this line is commented the error is not appears
}

protected void logout() {
    Session.get().signOut();
    application.getSecuritySettings().getAuthenticationStrategy().remove();
}

更新 2:

解决方法是在注销代码中添加 Session.invalidateNow():

protected void logout() {
    Session.get().signOut();
    application.getSecuritySettings().getAuthenticationStrategy().remove();
    Session.get().invalidateNow(); // with this line the error is not appears
}

标签: wicket

解决方案


https://issues.apache.org/jira/browse/WICKET-6856中所述,Wicket 8.11.0 中的错误测试现在失败。

在#signOut()(调用#invalidate())之后,会话无效,并且用于呈现有状态页面的重定向将在测试中失败。

您必须调用 #invalidateNow() 正如您在更新中已经指出的那样。


推荐阅读