I solved the problem with this code on the setUp method:

List resourceLoaders = application.getResourceSettings
().getStringResourceLoaders();
List copy = new ArrayList(resourceLoaders);
Collections.copy(copy,resourceLoaders);
application.getResourceSettings().addStringResourceLoader(new
ClassStringResourceLoader(application, MyApplication.class));
for (Iterator iterator = copy.iterator(); iterator.hasNext();) {
IStringResourceLoader object = (IStringResourceLoader) iterator.next();
application.getResourceSettings().addStringResourceLoader(object);
}

This solution is based on this mail:

Re: Loading global resources in test?

Erik Underbjerg
Wed, 22 Aug 2007 08:04:49 -0700
I figured it out. Guess I didn't read the documentation properly afterall.
In the documentation for addStringResourceLoader is says:

   Description copied from interface: IResourceSettings

Add a string resource loader to the chain of loaders. If this is the first
call to this method since the creation of the application settings then the
existing chain is cleared before the new loader is added.

So the solution was to:

1. retrieve and save all the existing resource loaders
2. add them again
3. add the extra resource loader as below.

Then it worked.

Sorry for the trouble, and thanks for your time.

/Erik
On Feb 6, 2008 2:51 PM, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
> dont know about 1.2, but in 1.3 there is a constructor that takes an
> instance of application, so you would do new WicketTester(new
> MyApplication());
>
> -igor
>
>
>
> On Feb 6, 2008 9:11 AM, Marco Aurélio Silva <[EMAIL PROTECTED]> wrote:
> > How to make it use my application subclass?
> > WicketTester.set(Application application) trow this exception:
> >
> > wicket.WicketRuntimeException: Use Application.init() method for
> > configuring your application object
> >         at wicket.Application.getSettings(Application.java:606)
> >         at wicket.Application.getDebugSettings(Application.java:449)
> >         at wicket.protocol.http.HttpSessionStore.setAttribute(
HttpSessionStore.java:51)
> >         at wicket.protocol.http.AbstractHttpSessionStore.bind(
AbstractHttpSessionStore.java:165)
> >         at
wicket.protocol.http.MockWebApplication.setupRequestAndResponse(
MockWebApplication.java:411)
> >         at wicket.util.tester.WicketTester.startPage(WicketTester.java
:230)
> >         at AppTester.testHome(AppTester.java:56)
> >         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:324)
> >         at junit.framework.TestCase.runTest(TestCase.java:164)
> >         at junit.framework.TestCase.runBare(TestCase.java:130)
> >         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)
> >
> >
> >
> >
> > On Feb 6, 2008 1:55 PM, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
> > > you have to make wicket tester use _your_ application subclass
> > >
> > > -igor
> > >
> > >
> > >
> > > On Feb 6, 2008 8:50 AM, Marco Aurélio Silva <[EMAIL PROTECTED]> wrote:
> > > > Hi all
> > > >
> > > > I'm writing test cases for my wicket application (1.2.6), and I'm
> > > > having problems with the ResourceModel and StringResourceModel. It
> > > > seems like when loaded by a WicketTester (with startPage method)
these
> > > > components doesn't load the global resource file
> > > > "MyApplication.properties". If I put the key on a property file with
> > > > the same name of the page, it works. When I run the same page in
> > > > tomcat, it works fine.
> > > >
> > > >
> > > > Thank you
> > > > Marco
> > > >
> > > >
---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to