【发布时间】: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
}
【问题讨论】:
-
听起来像issues.apache.org/jira/browse/WICKET-6856。请附上失败的单元测试,我们会看看!
标签: wicket