Re: WicketTester: how to mock off EJB's

2007-11-17 Thread Timo Rantalaiho
On Fri, 16 Nov 2007, Andy Barlow [Deftex] wrote:
 I guess what I really need to do mock off the getEJBService() of  
 MainApplication to return a mock object that serves the data to the  
 test pages.
 
 Problem is, I'm not sure how to achieve that without initialising  
 WicketTester with a mock MainApplication, which will then fail with a  
 ClassCastException, as before.

WicketTester wicket = new WicketTester(new MainTestApplication());

...

public class MainTestApplication extends MainApplication {
...
@Override public EjbService getEjbService() {
return fakeEjbService;
}
}

Though if you use EJB 3 I think that you could have
some kind of dependency injection instead of a service
locator.

Best wishes,
Timo

-- 
Timo Rantalaiho   
Reaktor Innovations OyURL: http://www.ri.fi/ 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: WicketTester: how to mock off EJB's

2007-11-16 Thread Alex Objelean


In order to avoid ClassCastException, when constructing a new instance of
WicketTester,  initialize it with your MainApplication:

WicketTester tester = new WicketTester(new MainApplication());



Andy Barlow [Deftex] wrote:
 
 I have an application which used Session EJB's to deliver data to  
 Wicket pages.
 
 These are looked up using JNDI in the main application class: for the  
 sake of argument let's call it MainApplication.java.
 
 I then have a BasePage.java from which all other pages that use these  
 EJB's inherit, in which there is a getter that returns the EJB service  
 as follows:
 
public EJBLocal getEJBService() {
  return ((MainApplication)this.getApplication()).  
 getEJBService();
  }
 
 It all works nicely, but I want to (retrospectively, slap on the  
 wrist) write a test harness to validate the application.
 
 My problem is I get a ClassCastException in BasePage.java because the  
 MockWebApplication that WicketTester creates/uses cannot be cast to  
 MainApplication.
 
 I've seen examples where Spring beans are mocked off, so I'm sure it's  
 possible.
 
 Has anyone got any ideas or suggestions?
 
 Regards,
 Andy Barlow
 
 
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 

-- 
View this message in context: 
http://www.nabble.com/WicketTester%3A-how-to-mock-off-EJB%27s-tf4822609.html#a13798080
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]