wicket - 检票口测试中的 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
}
解决方案
如https://issues.apache.org/jira/browse/WICKET-6856中所述,Wicket 8.11.0 中的错误测试现在失败。
在#signOut()(调用#invalidate())之后,会话无效,并且用于呈现有状态页面的重定向将在测试中失败。
您必须调用 #invalidateNow() 正如您在更新中已经指出的那样。
推荐阅读
- html - 为什么我的图标在 firefox 上变得模糊,而在 chrome 和其他浏览器上却很清晰?
- condor - 确保您具有对目标 Master 的 CONFIG 访问权限
- c - 为字符串数组配置库函数节点参数
- java - 从命令行调用时如何将 OJDBC 用作 Jython 脚本的外部 jar
- python - Pandas 将非数字分类虚拟列转换为单个分类列
- google-play-console - Google Play 安装量减去卸载量是否应该与有效安装量相匹配?
- css - 如何以表格的形式在屏幕上设置我的 json 数据样式?
- javascript - 使用 gitignore 隐藏文件
- ubuntu-18.04 - ROS2 Eloquent 安装在 Ubuntu 18.04.4 LTS 中失败
- sql - 使用 BETWEEN 函数