You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Andrea Jahn <an...@googlemail.com> on 2008/06/18 10:23:59 UTC

Junit Wicket tests in Wasp/Swarm environment

Hi,

after the integration of the Wasp/Swarm framework (only basic functionality
at the moment) I have to adapt the wicket JUnit tests.

But I have the following problems:


public class LoginTest
{
  private WicketTester tester;
  private FormTester form;
  private PersonService personServiceMock;
  private final int personId = 2000000; //same id is used in whole test

  @Before
  public void setUp() throws Exception {
    tester = new MyWicketTester();       <--------------------------------

    personServiceMock = EasyMock.createStrictMock(PersonService.class);

    ApplicationContextMock appctx = new ApplicationContextMock();
    appctx.putBean("personService", personServiceMock);

    // setup WicketTester and injection for @SpringBean
    tester.getApplication().addComponentInstantiationListener
  (new SpringComponentInjector(tester.getApplication(), appctx));
  }

  @Test
  public void testLoginPageRender(){
    tester.startPage(Login.class);
    tester.assertRenderedPage(Login.class);

    tester.assertNoErrorMessage();

    form = tester.newFormTester("loginForm");
    assertNotNull(form);
    tester.assertComponent("loginForm:userName", TextField.class);
    tester.assertComponent("loginForm:password", TextField.class);
  }

...
}


public class MyWicketTester extends WicketTester
{
  public MyWicketTester()
  {
    super(new MyApplication());   <----------------
  }

  @SuppressWarnings("serial")
  @Override

  public WebSession getWicketSession() {
    MySession session =
 new MySession((MyApplication)getApplication(), getWicketRequest()) {
      public boolean isPersonLoggedIn() {
        return true;
      }
    };

    session.setPerson(HibernateTestHelper.createTestPerson( new Integer(123)
));
    return session;
  }
}


public class MyApplication extends SwarmWebApplication
{
  protected void init() {
    super.init();

    addComponentInstantiationListener(new SpringComponentInjector(this));
<-----------------------
  }

...
}

java.lang.IllegalStateException: No WebApplicationContext found: no
ContextLoaderListener registered?
 at
org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:86)
 at
org.apache.wicket.spring.injection.annot.SpringComponentInjector.<init>(SpringComponentInjector.java:74)
 at xxx.yyy.zzz.front.MyApplication.init(MyApplication.java:37)
 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:18)
 at test.front.LoginTest.setUp(LoginTest.java:34)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at
org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:122)
 at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:86)
 at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
 at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
 at
org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
 at
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
 at
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
 at
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
 at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
 at
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
 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 tried to override the init() method as described in the spring wiki:

http://cwiki.apache.org/WICKET/spring.html#Spring-UnitTestingtheProxyApproach



public class MyWicketTester extends WicketTester
{
  public MyWicketTester(final ApplicationContextMock appctx)
  {
    super(new MyApplication() {
      @Override
      protected void init() {
                addComponentInstantiationListener(new
SpringComponentInjector(this, appctx));
      };
    });
  }

  @SuppressWarnings("serial")
  @Override
  public WebSession getWicketSession() {
    MySession session = new MySession((MyApplication)getApplication(),
getWicketRequest()) {
      public boolean isPersonLoggedIn() {
        return true;
      }
    };

    session.setPerson(HibernateTestHelper.createTestPerson( new Integer(123)
));
    return session;
  }
}


But now the init() method of SwarmWebApplication, where the ActionFactory,
the Hive and the StrategyFactory are set up,
is not called and the following error is in init() of WaspSession.


public class MySession extends WaspSession
{
  // logged in user
  private Person person;

  public MySession(WaspApplication application, Request request){
    super(application, request);   <---------------------------------
  }

  public Person getPerson() {
    return person;
  }

  public void setPerson(Person person) {
    this.person = person;
  }
...
}


public class WaspSession extends WebSession
{
...
 public WaspSession(WaspApplication application, Request request)
 {
  super(request);
  securityStrategy = application.getStrategyFactory().newStrategy();
<-----------------------
 }
...
}


java.lang.NullPointerException
 at org.apache.wicket.security.WaspSession.<init>(WaspSession.java:48)
 at xxx.yyy.zzz.front.MySession.<init>(MySession.java:36)
 at xxx.yyy.zzz.front.MyApplication.newSession(MyApplication.java:67)
 at org.apache.wicket.Session.findOrCreate(Session.java:228)
 at org.apache.wicket.Session.findOrCreate(Session.java:211)
 at
org.apache.wicket.protocol.http.MockWebApplication.createRequestCycle(MockWebApplication.java:518)
 at
org.apache.wicket.protocol.http.MockWebApplication.<init>(MockWebApplication.java:199)
 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:22)
 at test.front.LoginTest.setUp(LoginTest.java:47)
 at junit.framework.TestCase.runBare(TestCase.java:132)
 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 not sure, if I'm on the right track here (trying to remove the
Wasp/Swarm dependencies from the test).

Is there a possibility to call addComponentInstantiationListener outside of
init() in MyApplication,
so that I don't have to override the init() method in MyWicketTester ?

Thanks
Andrea

Re: Junit Wicket tests in Wasp/Swarm environment

Posted by Andrea Jahn <an...@googlemail.com>.
Thanks a lot, I use now snapshop #69.

Andrea


2008/6/30, Maurice Marrink <ma...@gmail.com>:
>
> Apparently the junit tests in wicket 1.3.4 trigger a call to destroy
> twice. Since i am setting several fields to null this causes the
> second destroy to fail.
> As a quick fix i have put some nullchecks in the code. A new snapshot
> should be available shortly (see
> http://wicketstuff.org/teamcity/overview.html ). You can force maven
> to download this new snapshot by using the -U flag.
>
> I will check why wicket is now doing a dual destroy and correct this
> if possible.
>
> Maurice
>
> On Mon, Jun 30, 2008 at 12:48 PM, Andrea Jahn
> <an...@googlemail.com> wrote:
> > 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 <ma...@gmail.com>:
> >>
> >> In the teardown do tester.destroy() this will clean up everything.
> >>
> >> Maurice
> >>
> >> On Fri, Jun 20, 2008 at 10:16 AM, Andrea Jahn
> >> <an...@googlemail.com> 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 <ma...@gmail.com>:
> >> >>
> >> >> 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
> >> >> <an...@googlemail.com> 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: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Junit Wicket tests in Wasp/Swarm environment

Posted by Maurice Marrink <ma...@gmail.com>.
Apparently the junit tests in wicket 1.3.4 trigger a call to destroy
twice. Since i am setting several fields to null this causes the
second destroy to fail.
As a quick fix i have put some nullchecks in the code. A new snapshot
should be available shortly (see
http://wicketstuff.org/teamcity/overview.html ). You can force maven
to download this new snapshot by using the -U flag.

I will check why wicket is now doing a dual destroy and correct this
if possible.

Maurice

On Mon, Jun 30, 2008 at 12:48 PM, Andrea Jahn
<an...@googlemail.com> wrote:
> 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 <ma...@gmail.com>:
>>
>> In the teardown do tester.destroy() this will clean up everything.
>>
>> Maurice
>>
>> On Fri, Jun 20, 2008 at 10:16 AM, Andrea Jahn
>> <an...@googlemail.com> 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 <ma...@gmail.com>:
>> >>
>> >> 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
>> >> <an...@googlemail.com> 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: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Junit Wicket tests in Wasp/Swarm environment

Posted by Andrea Jahn <an...@googlemail.com>.
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 <ma...@gmail.com>:
>
> In the teardown do tester.destroy() this will clean up everything.
>
> Maurice
>
> On Fri, Jun 20, 2008 at 10:16 AM, Andrea Jahn
> <an...@googlemail.com> 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 <ma...@gmail.com>:
> >>
> >> 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
> >> <an...@googlemail.com> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Junit Wicket tests in Wasp/Swarm environment

Posted by Maurice Marrink <ma...@gmail.com>.
In the teardown do tester.destroy() this will clean up everything.

Maurice

On Fri, Jun 20, 2008 at 10:16 AM, Andrea Jahn
<an...@googlemail.com> 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 <ma...@gmail.com>:
>>
>> 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
>> <an...@googlemail.com> 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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Junit Wicket tests in Wasp/Swarm environment

Posted by Andrea Jahn <an...@googlemail.com>.
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 <ma...@gmail.com>:
>
> 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
> <an...@googlemail.com> 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
> >
> >
>

Re: Junit Wicket tests in Wasp/Swarm environment

Posted by Maurice Marrink <ma...@gmail.com>.
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
<an...@googlemail.com> 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
>
>
> 2008/6/19, Maurice Marrink <ma...@gmail.com>:
>>
>> In the above code you are showing 2 different codes for MyApplication,
>> both override the init method. one of them calls super.init the other
>> does not. your init should look like this:
>> protected void init() {
>>       super.init();
>>       addComponentInstantiationListener(new SpringComponentInjector(this));
>>       InjectorHolder.getInjector().inject(this);
>>       // optional other stuff by you
>>     };
>> Also you are overriding the wrong place to return a new custom session.
>> you are overriding WicketTester.getWicketSession() but you should be
>> overriding MyApplication.newSession(Request, Response)
>>
>> Hope this helps.
>>
>> Maurice
>>
>> On Thu, Jun 19, 2008 at 8:43 AM, Andrea Jahn <an...@googlemail.com>
>> wrote:
>> > Hi,
>> > Sorry, if this is a stupid Java question:
>> >
>> > But how can I call SwarmWebApplication.init() without calling
>> > MyApplication.init() ?
>> >
>> > Thanks
>> > Andrea
>> >
>> > public class MyWicketTester extends WicketTester
>> > {
>> >  public MyWicketTester(final ApplicationContextMock appctx)
>> >  {
>> >    super(new MyApplication() {
>> >      @Override
>> >      protected void init() {
>> >
>> >        super.init();  <--- MyApplication.init()
>> >      };
>> >    });
>> >  }
>> > }
>> >
>> >
>> > public class MyApplication extends SwarmWebApplication
>> > {
>> >  protected void init() {
>> >    super.init();
>> >  }
>> > }
>> >
>> >
>> >
>> >
>> >
>> > 2008/6/18, Maurice Marrink <ma...@gmail.com>:
>> >>
>> >> You need to call super.init(). that will fix your swarm problems. as
>> >> for spring i think you need:
>> >>
>> >> addComponentInstantiationListener(new SpringComponentInjector(this));
>> >> InjectorHolder.getInjector().inject(this);
>> >>
>> >> Maurice
>> >>
>> >>
>> >> On Wed, Jun 18, 2008 at 10:23 AM, Andrea Jahn
>> >> <an...@googlemail.com> wrote:
>> >> > Hi,
>> >> >
>> >> > after the integration of the Wasp/Swarm framework (only basic
>> >> functionality
>> >> > at the moment) I have to adapt the wicket JUnit tests.
>> >> >
>> >> > But I have the following problems:
>> >> >
>> >> >
>> >> > public class LoginTest
>> >> > {
>> >> >  private WicketTester tester;
>> >> >  private FormTester form;
>> >> >  private PersonService personServiceMock;
>> >> >  private final int personId = 2000000; //same id is used in whole test
>> >> >
>> >> >  @Before
>> >> >  public void setUp() throws Exception {
>> >> >    tester = new MyWicketTester();
>> <--------------------------------
>> >> >
>> >> >    personServiceMock = EasyMock.createStrictMock(PersonService.class);
>> >> >
>> >> >    ApplicationContextMock appctx = new ApplicationContextMock();
>> >> >    appctx.putBean("personService", personServiceMock);
>> >> >
>> >> >    // setup WicketTester and injection for @SpringBean
>> >> >    tester.getApplication().addComponentInstantiationListener
>> >> >  (new SpringComponentInjector(tester.getApplication(), appctx));
>> >> >  }
>> >> >
>> >> >  @Test
>> >> >  public void testLoginPageRender(){
>> >> >    tester.startPage(Login.class);
>> >> >    tester.assertRenderedPage(Login.class);
>> >> >
>> >> >    tester.assertNoErrorMessage();
>> >> >
>> >> >    form = tester.newFormTester("loginForm");
>> >> >    assertNotNull(form);
>> >> >    tester.assertComponent("loginForm:userName", TextField.class);
>> >> >    tester.assertComponent("loginForm:password", TextField.class);
>> >> >  }
>> >> >
>> >> > ...
>> >> > }
>> >> >
>> >> >
>> >> > public class MyWicketTester extends WicketTester
>> >> > {
>> >> >  public MyWicketTester()
>> >> >  {
>> >> >    super(new MyApplication());   <----------------
>> >> >  }
>> >> >
>> >> >  @SuppressWarnings("serial")
>> >> >  @Override
>> >> >
>> >> >  public WebSession getWicketSession() {
>> >> >    MySession session =
>> >> >  new MySession((MyApplication)getApplication(), getWicketRequest()) {
>> >> >      public boolean isPersonLoggedIn() {
>> >> >        return true;
>> >> >      }
>> >> >    };
>> >> >
>> >> >    session.setPerson(HibernateTestHelper.createTestPerson( new
>> >> Integer(123)
>> >> > ));
>> >> >    return session;
>> >> >  }
>> >> > }
>> >> >
>> >> >
>> >> > public class MyApplication extends SwarmWebApplication
>> >> > {
>> >> >  protected void init() {
>> >> >    super.init();
>> >> >
>> >> >    addComponentInstantiationListener(new
>> SpringComponentInjector(this));
>> >> > <-----------------------
>> >> >  }
>> >> >
>> >> > ...
>> >> > }
>> >> >
>> >> > java.lang.IllegalStateException: No WebApplicationContext found: no
>> >> > ContextLoaderListener registered?
>> >> >  at
>> >> >
>> >>
>> org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:86)
>> >> >  at
>> >> >
>> >>
>> org.apache.wicket.spring.injection.annot.SpringComponentInjector.<init>(SpringComponentInjector.java:74)
>> >> >  at xxx.yyy.zzz.front.MyApplication.init(MyApplication.java:37)
>> >> >  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:18)
>> >> >  at test.front.LoginTest.setUp(LoginTest.java:34)
>> >> >  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> >> >  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>> >> >  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>> >> >  at java.lang.reflect.Method.invoke(Unknown Source)
>> >> >  at
>> >> >
>> org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:122)
>> >> >  at
>> >> >
>> >>
>> org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:86)
>> >> >  at
>> org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
>> >> >  at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
>> >> >  at
>> >> >
>> >>
>> org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
>> >> >  at
>> >> >
>> >>
>> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
>> >> >  at
>> >> >
>> >>
>> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
>> >> >  at
>> >> >
>> >>
>> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
>> >> >  at
>> >> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
>> >> >  at
>> >> >
>> >>
>> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
>> >> >  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 tried to override the init() method as described in the spring wiki:
>> >> >
>> >> >
>> >>
>> http://cwiki.apache.org/WICKET/spring.html#Spring-UnitTestingtheProxyApproach
>> >> >
>> >> >
>> >> >
>> >> > public class MyWicketTester extends WicketTester
>> >> > {
>> >> >  public MyWicketTester(final ApplicationContextMock appctx)
>> >> >  {
>> >> >    super(new MyApplication() {
>> >> >      @Override
>> >> >      protected void init() {
>> >> >                addComponentInstantiationListener(new
>> >> > SpringComponentInjector(this, appctx));
>> >> >      };
>> >> >    });
>> >> >  }
>> >> >
>> >> >  @SuppressWarnings("serial")
>> >> >  @Override
>> >> >  public WebSession getWicketSession() {
>> >> >    MySession session = new MySession((MyApplication)getApplication(),
>> >> > getWicketRequest()) {
>> >> >      public boolean isPersonLoggedIn() {
>> >> >        return true;
>> >> >      }
>> >> >    };
>> >> >
>> >> >    session.setPerson(HibernateTestHelper.createTestPerson( new
>> >> Integer(123)
>> >> > ));
>> >> >    return session;
>> >> >  }
>> >> > }
>> >> >
>> >> >
>> >> > But now the init() method of SwarmWebApplication, where the
>> >> ActionFactory,
>> >> > the Hive and the StrategyFactory are set up,
>> >> > is not called and the following error is in init() of WaspSession.
>> >> >
>> >> >
>> >> > public class MySession extends WaspSession
>> >> > {
>> >> >  // logged in user
>> >> >  private Person person;
>> >> >
>> >> >  public MySession(WaspApplication application, Request request){
>> >> >    super(application, request);   <---------------------------------
>> >> >  }
>> >> >
>> >> >  public Person getPerson() {
>> >> >    return person;
>> >> >  }
>> >> >
>> >> >  public void setPerson(Person person) {
>> >> >    this.person = person;
>> >> >  }
>> >> > ...
>> >> > }
>> >> >
>> >> >
>> >> > public class WaspSession extends WebSession
>> >> > {
>> >> > ...
>> >> >  public WaspSession(WaspApplication application, Request request)
>> >> >  {
>> >> >  super(request);
>> >> >  securityStrategy = application.getStrategyFactory().newStrategy();
>> >> > <-----------------------
>> >> >  }
>> >> > ...
>> >> > }
>> >> >
>> >> >
>> >> > java.lang.NullPointerException
>> >> >  at org.apache.wicket.security.WaspSession.<init>(WaspSession.java:48)
>> >> >  at xxx.yyy.zzz.front.MySession.<init>(MySession.java:36)
>> >> >  at xxx.yyy.zzz.front.MyApplication.newSession(MyApplication.java:67)
>> >> >  at org.apache.wicket.Session.findOrCreate(Session.java:228)
>> >> >  at org.apache.wicket.Session.findOrCreate(Session.java:211)
>> >> >  at
>> >> >
>> >>
>> org.apache.wicket.protocol.http.MockWebApplication.createRequestCycle(MockWebApplication.java:518)
>> >> >  at
>> >> >
>> >>
>> org.apache.wicket.protocol.http.MockWebApplication.<init>(MockWebApplication.java:199)
>> >> >  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:22)
>> >> >  at test.front.LoginTest.setUp(LoginTest.java:47)
>> >> >  at junit.framework.TestCase.runBare(TestCase.java:132)
>> >> >  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 not sure, if I'm on the right track here (trying to remove the
>> >> > Wasp/Swarm dependencies from the test).
>> >> >
>> >> > Is there a possibility to call addComponentInstantiationListener
>> outside
>> >> of
>> >> > init() in MyApplication,
>> >> > so that I don't have to override the init() method in MyWicketTester ?
>> >> >
>> >> > Thanks
>> >> > Andrea
>> >> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> For additional commands, e-mail: users-help@wicket.apache.org
>> >>
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Junit Wicket tests in Wasp/Swarm environment

Posted by Andrea Jahn <an...@googlemail.com>.
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


2008/6/19, Maurice Marrink <ma...@gmail.com>:
>
> In the above code you are showing 2 different codes for MyApplication,
> both override the init method. one of them calls super.init the other
> does not. your init should look like this:
> protected void init() {
>       super.init();
>       addComponentInstantiationListener(new SpringComponentInjector(this));
>       InjectorHolder.getInjector().inject(this);
>       // optional other stuff by you
>     };
> Also you are overriding the wrong place to return a new custom session.
> you are overriding WicketTester.getWicketSession() but you should be
> overriding MyApplication.newSession(Request, Response)
>
> Hope this helps.
>
> Maurice
>
> On Thu, Jun 19, 2008 at 8:43 AM, Andrea Jahn <an...@googlemail.com>
> wrote:
> > Hi,
> > Sorry, if this is a stupid Java question:
> >
> > But how can I call SwarmWebApplication.init() without calling
> > MyApplication.init() ?
> >
> > Thanks
> > Andrea
> >
> > public class MyWicketTester extends WicketTester
> > {
> >  public MyWicketTester(final ApplicationContextMock appctx)
> >  {
> >    super(new MyApplication() {
> >      @Override
> >      protected void init() {
> >
> >        super.init();  <--- MyApplication.init()
> >      };
> >    });
> >  }
> > }
> >
> >
> > public class MyApplication extends SwarmWebApplication
> > {
> >  protected void init() {
> >    super.init();
> >  }
> > }
> >
> >
> >
> >
> >
> > 2008/6/18, Maurice Marrink <ma...@gmail.com>:
> >>
> >> You need to call super.init(). that will fix your swarm problems. as
> >> for spring i think you need:
> >>
> >> addComponentInstantiationListener(new SpringComponentInjector(this));
> >> InjectorHolder.getInjector().inject(this);
> >>
> >> Maurice
> >>
> >>
> >> On Wed, Jun 18, 2008 at 10:23 AM, Andrea Jahn
> >> <an...@googlemail.com> wrote:
> >> > Hi,
> >> >
> >> > after the integration of the Wasp/Swarm framework (only basic
> >> functionality
> >> > at the moment) I have to adapt the wicket JUnit tests.
> >> >
> >> > But I have the following problems:
> >> >
> >> >
> >> > public class LoginTest
> >> > {
> >> >  private WicketTester tester;
> >> >  private FormTester form;
> >> >  private PersonService personServiceMock;
> >> >  private final int personId = 2000000; //same id is used in whole test
> >> >
> >> >  @Before
> >> >  public void setUp() throws Exception {
> >> >    tester = new MyWicketTester();
> <--------------------------------
> >> >
> >> >    personServiceMock = EasyMock.createStrictMock(PersonService.class);
> >> >
> >> >    ApplicationContextMock appctx = new ApplicationContextMock();
> >> >    appctx.putBean("personService", personServiceMock);
> >> >
> >> >    // setup WicketTester and injection for @SpringBean
> >> >    tester.getApplication().addComponentInstantiationListener
> >> >  (new SpringComponentInjector(tester.getApplication(), appctx));
> >> >  }
> >> >
> >> >  @Test
> >> >  public void testLoginPageRender(){
> >> >    tester.startPage(Login.class);
> >> >    tester.assertRenderedPage(Login.class);
> >> >
> >> >    tester.assertNoErrorMessage();
> >> >
> >> >    form = tester.newFormTester("loginForm");
> >> >    assertNotNull(form);
> >> >    tester.assertComponent("loginForm:userName", TextField.class);
> >> >    tester.assertComponent("loginForm:password", TextField.class);
> >> >  }
> >> >
> >> > ...
> >> > }
> >> >
> >> >
> >> > public class MyWicketTester extends WicketTester
> >> > {
> >> >  public MyWicketTester()
> >> >  {
> >> >    super(new MyApplication());   <----------------
> >> >  }
> >> >
> >> >  @SuppressWarnings("serial")
> >> >  @Override
> >> >
> >> >  public WebSession getWicketSession() {
> >> >    MySession session =
> >> >  new MySession((MyApplication)getApplication(), getWicketRequest()) {
> >> >      public boolean isPersonLoggedIn() {
> >> >        return true;
> >> >      }
> >> >    };
> >> >
> >> >    session.setPerson(HibernateTestHelper.createTestPerson( new
> >> Integer(123)
> >> > ));
> >> >    return session;
> >> >  }
> >> > }
> >> >
> >> >
> >> > public class MyApplication extends SwarmWebApplication
> >> > {
> >> >  protected void init() {
> >> >    super.init();
> >> >
> >> >    addComponentInstantiationListener(new
> SpringComponentInjector(this));
> >> > <-----------------------
> >> >  }
> >> >
> >> > ...
> >> > }
> >> >
> >> > java.lang.IllegalStateException: No WebApplicationContext found: no
> >> > ContextLoaderListener registered?
> >> >  at
> >> >
> >>
> org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:86)
> >> >  at
> >> >
> >>
> org.apache.wicket.spring.injection.annot.SpringComponentInjector.<init>(SpringComponentInjector.java:74)
> >> >  at xxx.yyy.zzz.front.MyApplication.init(MyApplication.java:37)
> >> >  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:18)
> >> >  at test.front.LoginTest.setUp(LoginTest.java:34)
> >> >  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >> >  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> >> >  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> >> >  at java.lang.reflect.Method.invoke(Unknown Source)
> >> >  at
> >> >
> org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:122)
> >> >  at
> >> >
> >>
> org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:86)
> >> >  at
> org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
> >> >  at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
> >> >  at
> >> >
> >>
> org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
> >> >  at
> >> >
> >>
> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
> >> >  at
> >> >
> >>
> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
> >> >  at
> >> >
> >>
> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
> >> >  at
> >> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
> >> >  at
> >> >
> >>
> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
> >> >  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 tried to override the init() method as described in the spring wiki:
> >> >
> >> >
> >>
> http://cwiki.apache.org/WICKET/spring.html#Spring-UnitTestingtheProxyApproach
> >> >
> >> >
> >> >
> >> > public class MyWicketTester extends WicketTester
> >> > {
> >> >  public MyWicketTester(final ApplicationContextMock appctx)
> >> >  {
> >> >    super(new MyApplication() {
> >> >      @Override
> >> >      protected void init() {
> >> >                addComponentInstantiationListener(new
> >> > SpringComponentInjector(this, appctx));
> >> >      };
> >> >    });
> >> >  }
> >> >
> >> >  @SuppressWarnings("serial")
> >> >  @Override
> >> >  public WebSession getWicketSession() {
> >> >    MySession session = new MySession((MyApplication)getApplication(),
> >> > getWicketRequest()) {
> >> >      public boolean isPersonLoggedIn() {
> >> >        return true;
> >> >      }
> >> >    };
> >> >
> >> >    session.setPerson(HibernateTestHelper.createTestPerson( new
> >> Integer(123)
> >> > ));
> >> >    return session;
> >> >  }
> >> > }
> >> >
> >> >
> >> > But now the init() method of SwarmWebApplication, where the
> >> ActionFactory,
> >> > the Hive and the StrategyFactory are set up,
> >> > is not called and the following error is in init() of WaspSession.
> >> >
> >> >
> >> > public class MySession extends WaspSession
> >> > {
> >> >  // logged in user
> >> >  private Person person;
> >> >
> >> >  public MySession(WaspApplication application, Request request){
> >> >    super(application, request);   <---------------------------------
> >> >  }
> >> >
> >> >  public Person getPerson() {
> >> >    return person;
> >> >  }
> >> >
> >> >  public void setPerson(Person person) {
> >> >    this.person = person;
> >> >  }
> >> > ...
> >> > }
> >> >
> >> >
> >> > public class WaspSession extends WebSession
> >> > {
> >> > ...
> >> >  public WaspSession(WaspApplication application, Request request)
> >> >  {
> >> >  super(request);
> >> >  securityStrategy = application.getStrategyFactory().newStrategy();
> >> > <-----------------------
> >> >  }
> >> > ...
> >> > }
> >> >
> >> >
> >> > java.lang.NullPointerException
> >> >  at org.apache.wicket.security.WaspSession.<init>(WaspSession.java:48)
> >> >  at xxx.yyy.zzz.front.MySession.<init>(MySession.java:36)
> >> >  at xxx.yyy.zzz.front.MyApplication.newSession(MyApplication.java:67)
> >> >  at org.apache.wicket.Session.findOrCreate(Session.java:228)
> >> >  at org.apache.wicket.Session.findOrCreate(Session.java:211)
> >> >  at
> >> >
> >>
> org.apache.wicket.protocol.http.MockWebApplication.createRequestCycle(MockWebApplication.java:518)
> >> >  at
> >> >
> >>
> org.apache.wicket.protocol.http.MockWebApplication.<init>(MockWebApplication.java:199)
> >> >  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:22)
> >> >  at test.front.LoginTest.setUp(LoginTest.java:47)
> >> >  at junit.framework.TestCase.runBare(TestCase.java:132)
> >> >  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 not sure, if I'm on the right track here (trying to remove the
> >> > Wasp/Swarm dependencies from the test).
> >> >
> >> > Is there a possibility to call addComponentInstantiationListener
> outside
> >> of
> >> > init() in MyApplication,
> >> > so that I don't have to override the init() method in MyWicketTester ?
> >> >
> >> > Thanks
> >> > Andrea
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Junit Wicket tests in Wasp/Swarm environment

Posted by Maurice Marrink <ma...@gmail.com>.
In the above code you are showing 2 different codes for MyApplication,
both override the init method. one of them calls super.init the other
does not. your init should look like this:
protected void init() {
       super.init();
       addComponentInstantiationListener(new SpringComponentInjector(this));
       InjectorHolder.getInjector().inject(this);
       // optional other stuff by you
     };
Also you are overriding the wrong place to return a new custom session.
you are overriding WicketTester.getWicketSession() but you should be
overriding MyApplication.newSession(Request, Response)

Hope this helps.

Maurice

On Thu, Jun 19, 2008 at 8:43 AM, Andrea Jahn <an...@googlemail.com> wrote:
> Hi,
> Sorry, if this is a stupid Java question:
>
> But how can I call SwarmWebApplication.init() without calling
> MyApplication.init() ?
>
> Thanks
> Andrea
>
> public class MyWicketTester extends WicketTester
> {
>  public MyWicketTester(final ApplicationContextMock appctx)
>  {
>    super(new MyApplication() {
>      @Override
>      protected void init() {
>
>        super.init();  <--- MyApplication.init()
>      };
>    });
>  }
> }
>
>
> public class MyApplication extends SwarmWebApplication
> {
>  protected void init() {
>    super.init();
>  }
> }
>
>
>
>
>
> 2008/6/18, Maurice Marrink <ma...@gmail.com>:
>>
>> You need to call super.init(). that will fix your swarm problems. as
>> for spring i think you need:
>>
>> addComponentInstantiationListener(new SpringComponentInjector(this));
>> InjectorHolder.getInjector().inject(this);
>>
>> Maurice
>>
>>
>> On Wed, Jun 18, 2008 at 10:23 AM, Andrea Jahn
>> <an...@googlemail.com> wrote:
>> > Hi,
>> >
>> > after the integration of the Wasp/Swarm framework (only basic
>> functionality
>> > at the moment) I have to adapt the wicket JUnit tests.
>> >
>> > But I have the following problems:
>> >
>> >
>> > public class LoginTest
>> > {
>> >  private WicketTester tester;
>> >  private FormTester form;
>> >  private PersonService personServiceMock;
>> >  private final int personId = 2000000; //same id is used in whole test
>> >
>> >  @Before
>> >  public void setUp() throws Exception {
>> >    tester = new MyWicketTester();       <--------------------------------
>> >
>> >    personServiceMock = EasyMock.createStrictMock(PersonService.class);
>> >
>> >    ApplicationContextMock appctx = new ApplicationContextMock();
>> >    appctx.putBean("personService", personServiceMock);
>> >
>> >    // setup WicketTester and injection for @SpringBean
>> >    tester.getApplication().addComponentInstantiationListener
>> >  (new SpringComponentInjector(tester.getApplication(), appctx));
>> >  }
>> >
>> >  @Test
>> >  public void testLoginPageRender(){
>> >    tester.startPage(Login.class);
>> >    tester.assertRenderedPage(Login.class);
>> >
>> >    tester.assertNoErrorMessage();
>> >
>> >    form = tester.newFormTester("loginForm");
>> >    assertNotNull(form);
>> >    tester.assertComponent("loginForm:userName", TextField.class);
>> >    tester.assertComponent("loginForm:password", TextField.class);
>> >  }
>> >
>> > ...
>> > }
>> >
>> >
>> > public class MyWicketTester extends WicketTester
>> > {
>> >  public MyWicketTester()
>> >  {
>> >    super(new MyApplication());   <----------------
>> >  }
>> >
>> >  @SuppressWarnings("serial")
>> >  @Override
>> >
>> >  public WebSession getWicketSession() {
>> >    MySession session =
>> >  new MySession((MyApplication)getApplication(), getWicketRequest()) {
>> >      public boolean isPersonLoggedIn() {
>> >        return true;
>> >      }
>> >    };
>> >
>> >    session.setPerson(HibernateTestHelper.createTestPerson( new
>> Integer(123)
>> > ));
>> >    return session;
>> >  }
>> > }
>> >
>> >
>> > public class MyApplication extends SwarmWebApplication
>> > {
>> >  protected void init() {
>> >    super.init();
>> >
>> >    addComponentInstantiationListener(new SpringComponentInjector(this));
>> > <-----------------------
>> >  }
>> >
>> > ...
>> > }
>> >
>> > java.lang.IllegalStateException: No WebApplicationContext found: no
>> > ContextLoaderListener registered?
>> >  at
>> >
>> org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:86)
>> >  at
>> >
>> org.apache.wicket.spring.injection.annot.SpringComponentInjector.<init>(SpringComponentInjector.java:74)
>> >  at xxx.yyy.zzz.front.MyApplication.init(MyApplication.java:37)
>> >  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:18)
>> >  at test.front.LoginTest.setUp(LoginTest.java:34)
>> >  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> >  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>> >  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>> >  at java.lang.reflect.Method.invoke(Unknown Source)
>> >  at
>> > org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:122)
>> >  at
>> >
>> org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:86)
>> >  at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
>> >  at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
>> >  at
>> >
>> org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
>> >  at
>> >
>> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
>> >  at
>> >
>> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
>> >  at
>> >
>> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
>> >  at
>> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
>> >  at
>> >
>> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
>> >  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 tried to override the init() method as described in the spring wiki:
>> >
>> >
>> http://cwiki.apache.org/WICKET/spring.html#Spring-UnitTestingtheProxyApproach
>> >
>> >
>> >
>> > public class MyWicketTester extends WicketTester
>> > {
>> >  public MyWicketTester(final ApplicationContextMock appctx)
>> >  {
>> >    super(new MyApplication() {
>> >      @Override
>> >      protected void init() {
>> >                addComponentInstantiationListener(new
>> > SpringComponentInjector(this, appctx));
>> >      };
>> >    });
>> >  }
>> >
>> >  @SuppressWarnings("serial")
>> >  @Override
>> >  public WebSession getWicketSession() {
>> >    MySession session = new MySession((MyApplication)getApplication(),
>> > getWicketRequest()) {
>> >      public boolean isPersonLoggedIn() {
>> >        return true;
>> >      }
>> >    };
>> >
>> >    session.setPerson(HibernateTestHelper.createTestPerson( new
>> Integer(123)
>> > ));
>> >    return session;
>> >  }
>> > }
>> >
>> >
>> > But now the init() method of SwarmWebApplication, where the
>> ActionFactory,
>> > the Hive and the StrategyFactory are set up,
>> > is not called and the following error is in init() of WaspSession.
>> >
>> >
>> > public class MySession extends WaspSession
>> > {
>> >  // logged in user
>> >  private Person person;
>> >
>> >  public MySession(WaspApplication application, Request request){
>> >    super(application, request);   <---------------------------------
>> >  }
>> >
>> >  public Person getPerson() {
>> >    return person;
>> >  }
>> >
>> >  public void setPerson(Person person) {
>> >    this.person = person;
>> >  }
>> > ...
>> > }
>> >
>> >
>> > public class WaspSession extends WebSession
>> > {
>> > ...
>> >  public WaspSession(WaspApplication application, Request request)
>> >  {
>> >  super(request);
>> >  securityStrategy = application.getStrategyFactory().newStrategy();
>> > <-----------------------
>> >  }
>> > ...
>> > }
>> >
>> >
>> > java.lang.NullPointerException
>> >  at org.apache.wicket.security.WaspSession.<init>(WaspSession.java:48)
>> >  at xxx.yyy.zzz.front.MySession.<init>(MySession.java:36)
>> >  at xxx.yyy.zzz.front.MyApplication.newSession(MyApplication.java:67)
>> >  at org.apache.wicket.Session.findOrCreate(Session.java:228)
>> >  at org.apache.wicket.Session.findOrCreate(Session.java:211)
>> >  at
>> >
>> org.apache.wicket.protocol.http.MockWebApplication.createRequestCycle(MockWebApplication.java:518)
>> >  at
>> >
>> org.apache.wicket.protocol.http.MockWebApplication.<init>(MockWebApplication.java:199)
>> >  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:22)
>> >  at test.front.LoginTest.setUp(LoginTest.java:47)
>> >  at junit.framework.TestCase.runBare(TestCase.java:132)
>> >  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 not sure, if I'm on the right track here (trying to remove the
>> > Wasp/Swarm dependencies from the test).
>> >
>> > Is there a possibility to call addComponentInstantiationListener outside
>> of
>> > init() in MyApplication,
>> > so that I don't have to override the init() method in MyWicketTester ?
>> >
>> > Thanks
>> > Andrea
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Junit Wicket tests in Wasp/Swarm environment

Posted by Andrea Jahn <an...@googlemail.com>.
Hi,
Sorry, if this is a stupid Java question:

But how can I call SwarmWebApplication.init() without calling
MyApplication.init() ?

Thanks
Andrea

public class MyWicketTester extends WicketTester
{
  public MyWicketTester(final ApplicationContextMock appctx)
  {
    super(new MyApplication() {
      @Override
      protected void init() {

        super.init();  <--- MyApplication.init()
      };
    });
  }
}


public class MyApplication extends SwarmWebApplication
{
  protected void init() {
    super.init();
  }
}





2008/6/18, Maurice Marrink <ma...@gmail.com>:
>
> You need to call super.init(). that will fix your swarm problems. as
> for spring i think you need:
>
> addComponentInstantiationListener(new SpringComponentInjector(this));
> InjectorHolder.getInjector().inject(this);
>
> Maurice
>
>
> On Wed, Jun 18, 2008 at 10:23 AM, Andrea Jahn
> <an...@googlemail.com> wrote:
> > Hi,
> >
> > after the integration of the Wasp/Swarm framework (only basic
> functionality
> > at the moment) I have to adapt the wicket JUnit tests.
> >
> > But I have the following problems:
> >
> >
> > public class LoginTest
> > {
> >  private WicketTester tester;
> >  private FormTester form;
> >  private PersonService personServiceMock;
> >  private final int personId = 2000000; //same id is used in whole test
> >
> >  @Before
> >  public void setUp() throws Exception {
> >    tester = new MyWicketTester();       <--------------------------------
> >
> >    personServiceMock = EasyMock.createStrictMock(PersonService.class);
> >
> >    ApplicationContextMock appctx = new ApplicationContextMock();
> >    appctx.putBean("personService", personServiceMock);
> >
> >    // setup WicketTester and injection for @SpringBean
> >    tester.getApplication().addComponentInstantiationListener
> >  (new SpringComponentInjector(tester.getApplication(), appctx));
> >  }
> >
> >  @Test
> >  public void testLoginPageRender(){
> >    tester.startPage(Login.class);
> >    tester.assertRenderedPage(Login.class);
> >
> >    tester.assertNoErrorMessage();
> >
> >    form = tester.newFormTester("loginForm");
> >    assertNotNull(form);
> >    tester.assertComponent("loginForm:userName", TextField.class);
> >    tester.assertComponent("loginForm:password", TextField.class);
> >  }
> >
> > ...
> > }
> >
> >
> > public class MyWicketTester extends WicketTester
> > {
> >  public MyWicketTester()
> >  {
> >    super(new MyApplication());   <----------------
> >  }
> >
> >  @SuppressWarnings("serial")
> >  @Override
> >
> >  public WebSession getWicketSession() {
> >    MySession session =
> >  new MySession((MyApplication)getApplication(), getWicketRequest()) {
> >      public boolean isPersonLoggedIn() {
> >        return true;
> >      }
> >    };
> >
> >    session.setPerson(HibernateTestHelper.createTestPerson( new
> Integer(123)
> > ));
> >    return session;
> >  }
> > }
> >
> >
> > public class MyApplication extends SwarmWebApplication
> > {
> >  protected void init() {
> >    super.init();
> >
> >    addComponentInstantiationListener(new SpringComponentInjector(this));
> > <-----------------------
> >  }
> >
> > ...
> > }
> >
> > java.lang.IllegalStateException: No WebApplicationContext found: no
> > ContextLoaderListener registered?
> >  at
> >
> org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:86)
> >  at
> >
> org.apache.wicket.spring.injection.annot.SpringComponentInjector.<init>(SpringComponentInjector.java:74)
> >  at xxx.yyy.zzz.front.MyApplication.init(MyApplication.java:37)
> >  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:18)
> >  at test.front.LoginTest.setUp(LoginTest.java:34)
> >  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> >  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> >  at java.lang.reflect.Method.invoke(Unknown Source)
> >  at
> > org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:122)
> >  at
> >
> org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:86)
> >  at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
> >  at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
> >  at
> >
> org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
> >  at
> >
> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
> >  at
> >
> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
> >  at
> >
> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
> >  at
> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
> >  at
> >
> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
> >  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 tried to override the init() method as described in the spring wiki:
> >
> >
> http://cwiki.apache.org/WICKET/spring.html#Spring-UnitTestingtheProxyApproach
> >
> >
> >
> > public class MyWicketTester extends WicketTester
> > {
> >  public MyWicketTester(final ApplicationContextMock appctx)
> >  {
> >    super(new MyApplication() {
> >      @Override
> >      protected void init() {
> >                addComponentInstantiationListener(new
> > SpringComponentInjector(this, appctx));
> >      };
> >    });
> >  }
> >
> >  @SuppressWarnings("serial")
> >  @Override
> >  public WebSession getWicketSession() {
> >    MySession session = new MySession((MyApplication)getApplication(),
> > getWicketRequest()) {
> >      public boolean isPersonLoggedIn() {
> >        return true;
> >      }
> >    };
> >
> >    session.setPerson(HibernateTestHelper.createTestPerson( new
> Integer(123)
> > ));
> >    return session;
> >  }
> > }
> >
> >
> > But now the init() method of SwarmWebApplication, where the
> ActionFactory,
> > the Hive and the StrategyFactory are set up,
> > is not called and the following error is in init() of WaspSession.
> >
> >
> > public class MySession extends WaspSession
> > {
> >  // logged in user
> >  private Person person;
> >
> >  public MySession(WaspApplication application, Request request){
> >    super(application, request);   <---------------------------------
> >  }
> >
> >  public Person getPerson() {
> >    return person;
> >  }
> >
> >  public void setPerson(Person person) {
> >    this.person = person;
> >  }
> > ...
> > }
> >
> >
> > public class WaspSession extends WebSession
> > {
> > ...
> >  public WaspSession(WaspApplication application, Request request)
> >  {
> >  super(request);
> >  securityStrategy = application.getStrategyFactory().newStrategy();
> > <-----------------------
> >  }
> > ...
> > }
> >
> >
> > java.lang.NullPointerException
> >  at org.apache.wicket.security.WaspSession.<init>(WaspSession.java:48)
> >  at xxx.yyy.zzz.front.MySession.<init>(MySession.java:36)
> >  at xxx.yyy.zzz.front.MyApplication.newSession(MyApplication.java:67)
> >  at org.apache.wicket.Session.findOrCreate(Session.java:228)
> >  at org.apache.wicket.Session.findOrCreate(Session.java:211)
> >  at
> >
> org.apache.wicket.protocol.http.MockWebApplication.createRequestCycle(MockWebApplication.java:518)
> >  at
> >
> org.apache.wicket.protocol.http.MockWebApplication.<init>(MockWebApplication.java:199)
> >  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:22)
> >  at test.front.LoginTest.setUp(LoginTest.java:47)
> >  at junit.framework.TestCase.runBare(TestCase.java:132)
> >  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 not sure, if I'm on the right track here (trying to remove the
> > Wasp/Swarm dependencies from the test).
> >
> > Is there a possibility to call addComponentInstantiationListener outside
> of
> > init() in MyApplication,
> > so that I don't have to override the init() method in MyWicketTester ?
> >
> > Thanks
> > Andrea
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Junit Wicket tests in Wasp/Swarm environment

Posted by Maurice Marrink <ma...@gmail.com>.
You need to call super.init(). that will fix your swarm problems. as
for spring i think you need:

addComponentInstantiationListener(new SpringComponentInjector(this));
InjectorHolder.getInjector().inject(this);

Maurice


On Wed, Jun 18, 2008 at 10:23 AM, Andrea Jahn
<an...@googlemail.com> wrote:
> Hi,
>
> after the integration of the Wasp/Swarm framework (only basic functionality
> at the moment) I have to adapt the wicket JUnit tests.
>
> But I have the following problems:
>
>
> public class LoginTest
> {
>  private WicketTester tester;
>  private FormTester form;
>  private PersonService personServiceMock;
>  private final int personId = 2000000; //same id is used in whole test
>
>  @Before
>  public void setUp() throws Exception {
>    tester = new MyWicketTester();       <--------------------------------
>
>    personServiceMock = EasyMock.createStrictMock(PersonService.class);
>
>    ApplicationContextMock appctx = new ApplicationContextMock();
>    appctx.putBean("personService", personServiceMock);
>
>    // setup WicketTester and injection for @SpringBean
>    tester.getApplication().addComponentInstantiationListener
>  (new SpringComponentInjector(tester.getApplication(), appctx));
>  }
>
>  @Test
>  public void testLoginPageRender(){
>    tester.startPage(Login.class);
>    tester.assertRenderedPage(Login.class);
>
>    tester.assertNoErrorMessage();
>
>    form = tester.newFormTester("loginForm");
>    assertNotNull(form);
>    tester.assertComponent("loginForm:userName", TextField.class);
>    tester.assertComponent("loginForm:password", TextField.class);
>  }
>
> ...
> }
>
>
> public class MyWicketTester extends WicketTester
> {
>  public MyWicketTester()
>  {
>    super(new MyApplication());   <----------------
>  }
>
>  @SuppressWarnings("serial")
>  @Override
>
>  public WebSession getWicketSession() {
>    MySession session =
>  new MySession((MyApplication)getApplication(), getWicketRequest()) {
>      public boolean isPersonLoggedIn() {
>        return true;
>      }
>    };
>
>    session.setPerson(HibernateTestHelper.createTestPerson( new Integer(123)
> ));
>    return session;
>  }
> }
>
>
> public class MyApplication extends SwarmWebApplication
> {
>  protected void init() {
>    super.init();
>
>    addComponentInstantiationListener(new SpringComponentInjector(this));
> <-----------------------
>  }
>
> ...
> }
>
> java.lang.IllegalStateException: No WebApplicationContext found: no
> ContextLoaderListener registered?
>  at
> org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:86)
>  at
> org.apache.wicket.spring.injection.annot.SpringComponentInjector.<init>(SpringComponentInjector.java:74)
>  at xxx.yyy.zzz.front.MyApplication.init(MyApplication.java:37)
>  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:18)
>  at test.front.LoginTest.setUp(LoginTest.java:34)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>  at java.lang.reflect.Method.invoke(Unknown Source)
>  at
> org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:122)
>  at
> org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:86)
>  at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
>  at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
>  at
> org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
>  at
> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
>  at
> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
>  at
> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
>  at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
>  at
> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
>  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 tried to override the init() method as described in the spring wiki:
>
> http://cwiki.apache.org/WICKET/spring.html#Spring-UnitTestingtheProxyApproach
>
>
>
> public class MyWicketTester extends WicketTester
> {
>  public MyWicketTester(final ApplicationContextMock appctx)
>  {
>    super(new MyApplication() {
>      @Override
>      protected void init() {
>                addComponentInstantiationListener(new
> SpringComponentInjector(this, appctx));
>      };
>    });
>  }
>
>  @SuppressWarnings("serial")
>  @Override
>  public WebSession getWicketSession() {
>    MySession session = new MySession((MyApplication)getApplication(),
> getWicketRequest()) {
>      public boolean isPersonLoggedIn() {
>        return true;
>      }
>    };
>
>    session.setPerson(HibernateTestHelper.createTestPerson( new Integer(123)
> ));
>    return session;
>  }
> }
>
>
> But now the init() method of SwarmWebApplication, where the ActionFactory,
> the Hive and the StrategyFactory are set up,
> is not called and the following error is in init() of WaspSession.
>
>
> public class MySession extends WaspSession
> {
>  // logged in user
>  private Person person;
>
>  public MySession(WaspApplication application, Request request){
>    super(application, request);   <---------------------------------
>  }
>
>  public Person getPerson() {
>    return person;
>  }
>
>  public void setPerson(Person person) {
>    this.person = person;
>  }
> ...
> }
>
>
> public class WaspSession extends WebSession
> {
> ...
>  public WaspSession(WaspApplication application, Request request)
>  {
>  super(request);
>  securityStrategy = application.getStrategyFactory().newStrategy();
> <-----------------------
>  }
> ...
> }
>
>
> java.lang.NullPointerException
>  at org.apache.wicket.security.WaspSession.<init>(WaspSession.java:48)
>  at xxx.yyy.zzz.front.MySession.<init>(MySession.java:36)
>  at xxx.yyy.zzz.front.MyApplication.newSession(MyApplication.java:67)
>  at org.apache.wicket.Session.findOrCreate(Session.java:228)
>  at org.apache.wicket.Session.findOrCreate(Session.java:211)
>  at
> org.apache.wicket.protocol.http.MockWebApplication.createRequestCycle(MockWebApplication.java:518)
>  at
> org.apache.wicket.protocol.http.MockWebApplication.<init>(MockWebApplication.java:199)
>  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:22)
>  at test.front.LoginTest.setUp(LoginTest.java:47)
>  at junit.framework.TestCase.runBare(TestCase.java:132)
>  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 not sure, if I'm on the right track here (trying to remove the
> Wasp/Swarm dependencies from the test).
>
> Is there a possibility to call addComponentInstantiationListener outside of
> init() in MyApplication,
> so that I don't have to override the init() method in MyWicketTester ?
>
> Thanks
> Andrea
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org