我正在我的 wicket 7 应用程序中测试一些组件。
我的组件没什么特别的,但它继承自
public PageAwarePanel extends Panel {
@Override
protected void onInitialize() {
super.onInitialize();
//refuse if used on page without PageConfig
if (getPageConfigurationModel() == null){
throw new RuntimeException("this component is only allowed inside pages having PageConfigurationModel");
}
}
protected IModel<PageConfiguration> getPageConfigurationModel(){
if (getPage() instanceof TemplatePage){
return ((TemplatePage)getPage()).getPageConfigurationModel();
}
return null;
}
}
有了这个,我可以从某个面板访问一些配置。
现在,当我尝试进行测试时:
PositionsPanel p = new PositionsPanel("123", asmNumber, Model.of());
tester.startPage(MyPage.class);
tester.startComponentInPage(p);
其中 MyPage 是一个 TemplatePage。
我得到了定义的 RuntimeException。我的问题是:
如何通过定义应在哪个页面上呈现该组件来测试此组件?
感谢所有高级帮助。