James Carman wrote:
Why are you using the Spring injector to inject your dependencies?
Can you not manually inject your dependencies?  Adding stuff manually
to a Spring context and then having the Spring injector inject it
doesn't really test what's going to be going on "in production"
anyway.  If it were me, I'd provide "setters" for my dependencies and
just set them that way with my mock objects.

It can be pretty use fully for several purposes, one could be using mock object's instead (like easymock).
On Fri, Apr 25, 2008 at 8:42 PM, Jorge Gallardo
<[EMAIL PROTECTED]> wrote:
Hi everyone,

 I'm setting up an app with wicket 1.3.3
 I have my Application class defined this way, to use Spring  injection with
 annotations

 public class WicketApplication extends SpringWebApplication {

    /**
     * Constructor
     */
    public WicketApplication() {
    }

    @Override
    protected void init() {
        super.init();
        configureSpringInjection();

        // configure bookmarkable pages
        mountBookmarkablePage("/login", LoginPage.class);
        mountBookmarkablePage("/home", HomePage.class);
    }

    protected void configureSpringInjection() {
        addComponentInstantiationListener(new
 SpringComponentInjector(this));
    }

    @Override
    public Class<? extends Page> getHomePage() {
        return HomePage.class;
    }

    @Override
    public Session newSession(Request request, Response response) {
        return new WicketSession(request);
    }

 }


 Then I subclassed it for testing:

 public class MockWicketApplication extends WicketApplication {

    private AnnotApplicationContextMock mockContext;

    @Override
    protected void configureSpringInjection() {

        mockContext = new AnnotApplicationContextMock();

        addComponentInstantiationListener(new SpringComponentInjector(this,
                mockContext));
    }

    public AnnotApplicationContextMock getMockContext() {
        return mockContext;
    }

 }

 And defined an abstract Test class:

 public abstract class BaseWicketTest extends TestCase {

    protected WicketTester tester;

    protected AnnotApplicationContextMock mockContext;

    protected void setUp() throws Exception {

        MockWicketApplication webapp = new MockWicketApplication();

        tester = new WicketTester(webapp);

        mockContext = ((MockWicketApplication) tester.getApplication())
                .getMockContext();
    }
 }

 and finally the Test itself:

 public class TestHomePage extends BaseWicketTest
 {
    public void testRenderMyPage()
    {
        mockContext.putBean("userAuthenticationSrv", new
 MockUserAuthenticationSrv());

        //start and render the test page
        tester.startPage(HomePage.class);

        //assert rendered page class
        tester.assertRenderedPage(HomePage.class);

        //assert rendered label component
        tester.assertLabel("message", "Some text");
    }
 }

 but then when i try to run the test case the result is the following
 stacktrace:

 java.lang.IllegalStateException: No WebApplicationContext found: no
 ContextLoaderListener registered?
    at
 
org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:95)
    at
 
org.apache.wicket.spring.SpringWebApplication.internalInit(SpringWebApplication.java:77)
    at
 org.apache.wicket.protocol.http.WicketFilter.init(WicketFilter.java:523)
    at
 
org.apache.wicket.protocol.http.MockWebApplication.<init>(MockWebApplication.java:151)
    at
 
org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:205)
    at
 org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:308)
    at
 org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:291)
    at com.globant.web.page.BaseWicketTest.setUp(BaseWicketTest.java:19)
    at junit.framework.TestCase.runBare(TestCase.java:128)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:120)
    at junit.framework.TestSuite.runTest(TestSuite.java:230)
    at junit.framework.TestSuite.run(TestSuite.java:225)
    at
 
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    at
 org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at
 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at
 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at
 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at
 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

 I must be making a mistake somewhere, but i cant get it. I checked the
 examples, the wiki, everywhere.

 Any idea? Any thoughts? Will be greatly appreciated :)

 JG


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to