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 <[EMAIL PROTECTED]>:
>
> 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
> <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to