6

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?

Cloud
  • 458
  • 1
  • 13
  • 34
  • Can you give as some more input on how your web.xml is structured? The main issue is obviously that jetty can't find an loginService for the login-config. With an embedded jetty you normally could add this service by "server.addBean(loginService);" - but wicket-tester doesn't allow a lot of customization on how to start the jetty server etc – Thorsten Wendelmuth Apr 02 '15 at 14:19

1 Answers1

0

Im not a java pro but i searched for your question i find some usefull links Link 1 Link 2 link 3

Ahmad Saad
  • 771
  • 6
  • 17