Wicket page test, Jetty security configuration

464 Views Asked by At

I am trying to test my wicket project using Wicket Page Test.

Starting the test causes Jetty to throw this error:

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

My testng suite looks like this:

<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>

The test class looks like this:

@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");
    }
}

I found some suggestions on the internet on changing Jetty configuration like this:

    <?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>

But I would not now how to include this configuration in my tests. What am I missing? How should I configure jetty for my test?

0

There are 0 best solutions below