Hi,
I was using Wicket 1.3.3 and tester.destroy() worked fine.
But I had to change to Wicket 1.3.4 (because of WICKET-1558) and now I get
the
following Exception when tester.destroy() is called:
java.lang.NullPointerException
at
org.apache.wicket.security.swarm.actions.SwarmActionFactory.destroy(SwarmActionFactory.java:502)
at
org.apache.wicket.security.WaspWebApplication.onDestroy(WaspWebApplication.java:107)
at org.apache.wicket.Application.internalDestroy(Application.java:890)
at
org.apache.wicket.protocol.http.WebApplication.internalDestroy(WebApplication.java:448)
at
org.apache.wicket.protocol.http.MockWebApplication.destroy(MockWebApplication.java:674)
at test.front.LoginTest.tearDown(LoginTest.java:65)
at junit.framework.TestCase.runBare(TestCase.java:140)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at
org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
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'm using Wasp/Swarm 1.3-SNAPSHOT.
Thanks
Andrea
2008/6/20, Maurice Marrink <[EMAIL PROTECTED]>:
>
> In the teardown do tester.destroy() this will clean up everything.
>
> Maurice
>
> On Fri, Jun 20, 2008 at 10:16 AM, Andrea Jahn
> <[EMAIL PROTECTED]> wrote:
> > Hi,
> > Thank you very much for the Java solution :) !
> > I have also corrected the place to return a new custom session :).
> >
> > Now the first test case runs without problems,
> > but in the second and third test case I get the following exception:
> >
> > java.lang.IllegalArgumentException: Another ActionFactory is already
> > registered with the following key:
> test.front.MyWicketTester$1:MyAppl-login
> > at
> >
> org.apache.wicket.security.actions.Actions.registerActionFactory(Actions.java:80)
> > at
> >
> org.apache.wicket.security.swarm.actions.SwarmActionFactory.<init>(SwarmActionFactory.java:86)
> > at
> >
> xxx.yyy.zzz.front.security.MyActionFactory.<init>(MyActionFactory.java:28)
> > at
> >
> xxx.yyy.zzz.front.MyApplication.setupActionFactory(MyApplication.java:177)
> > at
> >
> org.apache.wicket.security.swarm.SwarmWebApplication.init(SwarmWebApplication.java:96)
> > at xxx.yyy.zzz.front.MyApplication.init(MyApplication.java:38)
> > at
> org.apache.wicket.protocol.http.WicketFilter.init(WicketFilter.java:526)
> > 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 test.front.MyWicketTester.<init>(MyWicketTester.java:27)
> > at test.front.LoginTest.setUp(LoginTest.java:50)
> > at junit.framework.TestCase.runBare(TestCase.java:132)
> >
> >
> > I tried to unregister the hive, but anyway the exception is thrown.
> > How can I remove the ActionFactory ? Or can I avoid, that it is
> registered
> > again ?
> >
> > Thanks again
> > Andrea
> >
> >
> >
> > public class MyWicketTester extends WicketTester
> > {
> > public MyWicketTester(final ApplicationContextMock appctx)
> > {
> > super(new MyApplication() {
> > @Override
> > protected void initSpring() {
> >
> > addComponentInstantiationListener(new
> SpringComponentInjector(this,
> > appctx));
> > InjectorHolder.getInjector().inject(this);
> > };
> >
> > @Override
> > public Session newSession(final Request request, Response response)
> {
> > ...
> > }
> > });
> > }
> > }
> >
> >
> > public class LoginTest extends TestCase
> > {
> > private WicketTester tester;
> > private FormTester form;
> > private PersonService personServiceMock;
> > private LocationService locationServiceMock;
> >
> > @Before
> > public void setUp() throws Exception {
> >
> > personServiceMock = EasyMock.createStrictMock(PersonService.class);
> > locationServiceMock =
> EasyMock.createStrictMock(LocationService.class);
> >
> > ApplicationContextMock appctx = new ApplicationContextMock();
> > appctx.putBean("personService", personServiceMock);
> > appctx.putBean("locationService", locationServiceMock);
> >
> > tester = new MyWicketTester(appctx);
> > }
> >
> > @After
> > public void tearDown() {
> >
> > // unregister factory
> >
> >
> HiveMind.unregisterHive(((MyApplication)tester.getApplication()).getHiveKey());
> > }
> >
> >
> > @Test
> > public void testLoginPageRender(){
> > ...
> > }
> >
> > @Test
> > public void testInvalidLogin(){
> > ...
> >
> > }
> >
> > @Test
> > public void testValidLogin(){
> > ...
> >
> > }
> >
> >
> >
> >
> > 2008/6/19, Maurice Marrink <[EMAIL PROTECTED]>:
> >>
> >> Sorry never done much with spring, but according to this
> >>
> >>
> http://cwiki.apache.org/WICKET/spring.html#Spring-UnitTestingtheProxyApproach
> >> you were on the right track.
> >> So if you do your spring config in a protected method which is called
> >> by your application.init. you can override that method in your junit
> >> tests to use the mock springcontext.
> >>
> >> Maurice
> >>
> >> On Thu, Jun 19, 2008 at 11:44 AM, Andrea Jahn
> >> <[EMAIL PROTECTED]> wrote:
> >> > My initial problem was, that I have different application contexts in
> the
> >> > test environment
> >> > and in the Web application and therefore different calls of
> >> > addComponentInstantiationListener.
> >> >
> >> > In my test environment I have a ApplicationContextMock, which I have
> to
> >> add
> >> > as second parameter:
> >> > addComponentInstantiationListener(*new*
> SpringComponentInjector(*this*,
> >> > appctx));
> >> >
> >> > In the Web application the application context for the Spring beans is
> >> > configured in
> >> > application-context.xml.
> >> >
> >> > So when I call MyApplication.init() from the test environment I get
> the
> >> > exception
> >> > "No WebApplicationContext found: noContextLoaderListener registered?",
> >> > when addComponentInstantiationListener(new
> SpringComponentInjector(this))
> >> is
> >> > called.
> >> >
> >> > Perhaps is there another possibility to add the appctx in the test
> >> > environment
> >> > or another place to call addComponentInstantiationListener(new
> >> > SpringComponentInjector(this))
> >> > in the Web application ??
> >> >
> >> > Thanks
> >> > Andrea
> >> >
> >> >
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>