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
> >
> >
>

Reply via email to