Hi Per-Olof
You should checkout Wicket
Iolite(http://wicketstuff.org/confluence/display/STUFFWIKI/Wicket-Iolite),
or WicketTopia(http://wicketopia.sourceforge.net/). Both uses this
technique and has a snappy archetype for a swift start. The latter has
builtin profiles for misc conf-files using maven. And if you grab the
testing part from Wicket Iolite, you'll have what you want with
WicketTopia.. The heres the idea, although below are very rough and it's
much nicer in Wicket Iolite:
package zeuzgroup.application.test;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import
org.apache.wicket.spring.injection.annot.test.AnnotApplicationContextMock;
import org.apache.wicket.util.tester.WicketTester;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.jpa.AbstractJpaTests;
import zeuzgroup.application.ZeuzGroupApplication;
import zeuzgroup.core.localization.ITranslationService;
import zeuzgroup.core.provider.IDBDao;
import zeuzgroup.core.provider.TestFixtureProvider;
public abstract class BaseTest extends AbstractJpaTests {
protected WicketTester wicketTester;
protected IDBDao dbProvider;
protected TestFixtureProvider testFixtureProvider = new
TestFixtureProvider();
protected ITranslationService translations;
@Override
protected String[] getConfigLocations() {
return new String[] { "classpath:applicationContext.xml" };
}
protected BaseTest() {
super();
setDependencyCheck(false);
// To make inherited properties (like
// DataSource) not required.
}
@Override
protected void onSetUpBeforeTransaction() throws Exception {
super.onSetUpBeforeTransaction();
readyStuff();
}
@Override
protected boolean shouldUseShadowLoader() {
return false;
}
private void readyStuff() {
ApplicationContext appcxt = new ClassPathXmlApplicationContext(
"applicationContext.xml");
dbProvider = (IDBDao) appcxt.getBean("dBDao");
// 2. setup mock injection environment
AnnotApplicationContextMock appctx = new
AnnotApplicationContextMock();
appctx.putBean("dBDao", dbProvider);
appctx.putBean("translations", translations);
ZeuzGroupApplication zeuzGroupApplication = new
ZeuzGroupApplication();
zeuzGroupApplication
.setSpringComponentInjector(new SpringComponentInjector(
zeuzGroupApplication, appctx));
wicketTester = new WicketTester(zeuzGroupApplication);
}
protected IDBDao getAllInOneDao() {
return dbProvider;
}
public IDBDao getDbDao() {
return dbProvider;
}
@Required
public void setDbProvider(IDBDao dbProvider) {
this.dbProvider = dbProvider;
testFixtureProvider.setDbProvider(dbProvider);
}
}
Per-Olof Wallin wrote:
Hi
I am using Wicket with Spring and Hibernate. I am using Eclipse as IDE and
Maven 2 as build tool.
This is working fine.
Now, I want to use JUnit for unit testing. This is where I have some
problems.
1. I have set up a test specific spring context file in src/test/resources.
This should be copied to target/test-classes/.
If I do a build in Eclipse, this is done. However, when I do a Maven install
the resource files are not copied to the test-classes directory.
As I understand this should be done by default by maven.
Any suggestions?
2. Even if I get 1 above working (such as by just having Eclipse build
first) I still get an error with spring:
"java.lang.IllegalStateException: No WebApplicationContext found: no
ContextLoaderListener registered?"
I might have set things up wrong, I've used a Struts 2 project as template
and this might have something to do with it.
What I basically want is a setup where I can test (using junit) an
application with wicket, spring, hibernate (and a hibernate's in-memory
database, hsqldb).
The spring context for the tests should be different from the "real" spring
context.
Some help on this would be greatly appreciated.
Best regards,
Per-Olof Vallin
--
-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]