【问题标题】:PageExpiredException in wicket's test检票口测试中的 PageExpiredException
【发布时间】:2020-12-28 12:49:45
【问题描述】:

我已经将 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


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2013-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多