I think you also need to put your beans in there aswell:
ApplicationContext appcxt = new ClassPathXmlApplicationContext(
"applicationContext.xml");
generalDao = (GeneralDao) appcxt.getBean("GeneralDao");
// 2. setup mock injection environment
AnnotApplicationContextMock appctx = new
AnnotApplicationContextMock();
appctx.putBean("GeneralDao", generalDao);
WicketApplication wicketPersistanceApplication = new
WicketApplication();
wicketPersistanceApplication
.setSpringComponentInjector(new SpringComponentInjector(
wicketPersistanceApplication, appctx));
wicketTester = new WicketTester(wicketPersistanceApplication);
// or this way:
protected IAllInOneDao getDao() {
allInOneDaoCtrl = EasyMock.createControl();
return allInOneDaoCtrl.createMock(IAllInOneDao.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
allInOneDao = getDao();
// 2. setup mock injection environment
AnnotApplicationContextMock appctx = new
AnnotApplicationContextMock();
appctx.putBean("allInOneDao", allInOneDao);
wicketTester = new WicketTester(WicketApplication.class);
WebApplication app = wicketTester.getApplication();
app.addComponentInstantiationListener(new
SpringComponentInjector(app,
appctx));
allInOneDaoCtrl.reset();
}
Check out the blog tutorial(uses easymock to test in someplaces) or
wicket persistence template(just uses injected beans):
http://cwiki.apache.org/WICKET/blog-tutorial.html
https://wicket-stuff.svn.sourceforge.net/svnroot/wicket-stuff/trunk/wicket-persistence-template
Jorge Gallardo 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
--
-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]