Hello everybody,

 

I'm having problems with testing my wicket application with WicketTester

I get this error:

org.apache.wicket.WicketRuntimeException: There is no application attached to 
current thread main

 

รจ See below for fulle stacktrace.

 

 

I have been looking everywhere on the net, and I can't seem to get it working L

 

I have following WEB.XML

 

[WEB.XML]

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";

         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";>

    <context-param>

        <param-name>contextConfigLocation</param-name>

        <param-value>classpath:applicationContext.xml</param-value>

    </context-param>

 

    <servlet>

        <servlet-name>SLF4J helper</servlet-name>

        <servlet-class>be.thomascook.SLF4JHelperServlet</servlet-class>

        <load-on-startup>1</load-on-startup>

    </servlet>

 

    <listener>

        
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>

 

    <filter>

        <filter-name>opensessioninview</filter-name>

        
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>

    </filter>

    <filter-mapping>

        <filter-name>opensessioninview</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

 

    <servlet>

        <servlet-name>Jersey Spring Web Application</servlet-name>

        
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>

        <init-param>

            
<param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name>

            <param-value>/WEB-INF/jsp</param-value>

        </init-param>

        <load-on-startup>2</load-on-startup>

    </servlet>

    <servlet-mapping>

        <servlet-name>Jersey Spring Web Application</servlet-name>

        <url-pattern>/rest/*</url-pattern>

    </servlet-mapping>

 

    <filter>

        <filter-name>wicket-spring</filter-name>

        
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>

        <init-param>

            <param-name>applicationFactoryClassName</param-name>

            
<param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>

        </init-param>

        <init-param>

            <param-name>applicationBean</param-name>

            <param-value>wicketApplication</param-value>

        </init-param>

    </filter>

 

    <filter-mapping>

        <filter-name>wicket-spring</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

</web-app>

[/WEB.XML]

 

 

My WebApplication

In the init method we weave spring to our wicket

[APP]

public class WicketFilter extends WebApplication {

    /**

     * Constructor.

     */

    public WicketFilter() {

 

    }

 

    @Override

    protected void init() {

        addComponentInstantiationListener(new SpringComponentInjector(this));

    }

 

    public Class getHomePage() {

        return UserListPage.class;

    }

}

[/APP]

 

My userListPage

With the     @SpringBean we inject a spring bean which is defined in our 
applicationContext.

[PAGE]

public class UserListPage extends TemplatePage {

 

    @SpringBean(name = "userservice")

    private GenericCRUDService<User, Long> service;

 

    public UserListPage() {

        setPageTitle("Users List");

        this.add(new CRUDPanel<User, Long>("userlist", service, "username", 
"firstName", "lastName", "email", "enabled") {

            @Override

            protected void onEdit(IModel<User> rowModel) {

                UserPage page = new UserPage(rowModel);

                setResponsePage(page);

            }

        });

    }

}

[/PAGE]

 

 

And finally my test which fails

[TEST]

@ContextConfiguration(locations = {

        "/applicationContext-dao.xml",

        "/applicationContext-service.xml",

        "/applicationContext-database.xml"})

public class UserListPageTest extends AbstractTestNGSpringContextTests {

 

    @Autowired

    private ApplicationContext applicationContext;

    @Autowired

    protected WicketFilter wicketApplication;

 

    @Test

    public void labelContainsHelloWorld() {

 

        wicketApplication.addComponentInstantiationListener(new 
SpringComponentInjector(wicketApplication, applicationContext, true));

 

        WicketTester tester = new WicketTester(wicketApplication);

 

 

        tester.startPage(UserListPage.class);

        tester.assertNoErrorMessage();

        tester.assertLabel("title", "Roles List");

    }

}

[/TEST]

 

 

[EXCEPTION]

org.apache.wicket.WicketRuntimeException: There is no application attached to 
current thread main

                at org.apache.wicket.Application.get(Application.java:179)

                at 
org.apache.wicket.injection.web.InjectorHolder.setInjector(InjectorHolder.java:88)

                at 
org.apache.wicket.spring.injection.annot.SpringComponentInjector.<init>(SpringComponentInjector.java:104)

                at 
be.thomascook.ui.pages.admin.UserListPageTest.labelContainsHelloWorld(UserListPageTest.java:46)

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                at java.lang.reflect.Method.invoke(Method.java:597)

                at 
org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:644)

                at 
org.testng.internal.MethodHelper$1.runTestMethod(MethodHelper.java:762)

                at 
org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:158)

 

Process finished with exit code 0

[/EXCEPTION]

 

 

 

Thanks in advance.

Kim

 

Reply via email to