我正在尝试使用Wicket Page Test来测试我的wicket项目。
开始测试会导致Jetty抛出此错误:
2015-03-24 17:46:24,789 WARN [:] [main] [] [||] - org.eclipse.jetty.webapp.WebAppContext - Failed startup of context o.e.j.w.WebAppContext
java.lang.IllegalStateException: No LoginService for org.eclipse.jetty.security.authentication.BasicAuthenticator@4c451268 in org.eclipse.jetty.security.ConstraintSecurityHandler@4abb90f6
我的testng套件如下所示:
<suite name="wicket-page-test-sample">
<test verbose="2" name="tests" annotations="JDK">
<packages>
<package name="..."></package>
</packages>
<classes>
<class name="com.ttdev.wicketpagetest.WebPageTestContext"></class>
<class name="nl.pack.test.MessagePanelTest"></class>
</classes>
</test>
测试类看起来像这样:
@Test
public class MessagePanelTest
{
public void testOpenComponent()
{
final StringBuffer log = new StringBuffer();
MockableSpringBeanInjector.mockBean("hibernateService", mock(HibernateService.class));
WicketSeleniumDriver ws = WebPageTestContext.getWicketSelenium();
ws.openComponent(new ComponentFactory()
{
private static final long serialVersionUID = 1L;
public Component createComponent(String id)
{
return new MessagePanel(mock(AjaxRequestTarget.class));
}
});
assert ws.getText(By.id("info")).equals("Hello");
}
}
我在互联网上发现了一些改变Jetty配置的建议:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Get name="securityHandler">
<Set name="loginService">
<New class="org.eclipse.jetty.security.HashLoginService">
<Set name="name">MySecurityRealm</Set>
<Set name="config">src/test/resources/jetty-realm.properties</Set>
<Call name="start"/>
</New>
</Set>
<Set name="checkWelcomeFiles">true</Set>
</Get>
</Configure>
但我现在不知道如何在我的测试中包含此配置。我错过了什么?我应该如何为我的测试配置码头?