Re: Wicket and Spring - mocking a particular bean when Wicket is in development mode?
Liam Clarke-Hutchinson-3 wrote: > > how can I provide this bean instead of the real bean, > based on the value of WebApplication.getConfigurationType()? > Take a look at http://wicketpagetest.sourceforge.net. Even though it was designed to support unit testing in mind, there is no reason why it can't be used in system tests. - -- Kent Tong Better way to unit test Wicket pages (http://wicketpagetest.sourceforge.net) Books on CXF, Axis2, Wicket, JSF (http://http://agileskills2.org) -- View this message in context: http://old.nabble.com/Wicket-and-Spring---mocking-a-particular-bean-when-Wicket-is-in--development-mode--tp27067859p27085762.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket and Spring - mocking a particular bean when Wicket is in development mode?
Hmmm, I seem to have inserted that "Hi Liam" in entirely wrong place! Hope it doesn't distract you from the content of the message though ;o) 2010/1/8 Stijn Maller > I assume you're actually talking about stubbing rather then mocking. Mock > frameworks belong more in unit testing then in integration testing. > If you are in fact talking about stubs then Ilja is right, just use a > different applicationContext to inject the stubbed version of your > validation service. > > Hi Liam, > > I recommend you read up on the Spring TestContext framework. (See the > relevent section in your Spring Reference) > > Basically you will have to: > > 1) create a second applicationContext which only contains your stubbed > version of the service. (With the same beanname as the real service) > 2) Add the following annotations to your integration test (If it uses the > TestContext framework) > > @RunWith(SpringJUnit4ClassRunner.class) > @ContextConfiguration(locations={"/applicationContext.xml", > "/applicationContext-test.xml"}) > > This way your test will used the stubbed version and your normal code will > use the real version. If you were on the other hand talking about unit tests > and mock objects then none of the above applies. :o) > > Kind regards, > Stijn >
Re: Wicket and Spring - mocking a particular bean when Wicket is in development mode?
I assume you're actually talking about stubbing rather then mocking. Mock frameworks belong more in unit testing then in integration testing. If you are in fact talking about stubs then Ilja is right, just use a different applicationContext to inject the stubbed version of your validation service. Hi Liam, I recommend you read up on the Spring TestContext framework. (See the relevent section in your Spring Reference) Basically you will have to: 1) create a second applicationContext which only contains your stubbed version of the service. (With the same beanname as the real service) 2) Add the following annotations to your integration test (If it uses the TestContext framework) @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"/applicationContext.xml", "/applicationContext-test.xml"}) This way your test will used the stubbed version and your normal code will use the real version. If you were on the other hand talking about unit tests and mock objects then none of the above applies. :o) Kind regards, Stijn
Re: Wicket and Spring - mocking a particular bean when Wicket is in development mode?
Guice has a concept of providers, I cant remember if spring has the same. You could in that provider ask what kind of mode wicket were in and then return the appropriate service. Im not sure this is a desired way togo since it will impact performance in production.. However resource filtering in maven as IIja writes are better and does not impact production performance. regards Nino 2010/1/7 Liam Clarke-Hutchinson : > Hi all, > > This is probably more of a Spring question than a Wicket question, but I'm > asking here in the hopes that someone else has done this before. Basically, > we have a page that uses the @SpringBean annotation to inject a credit card > validation service. At the moment, when we're developing, it's injecting the > actual service, that then goes off to our card processor and validates the > card etc. For integration testing etc. I want to avoid this, so I've created > a simple implementation of the validation service that always returns true. > Question I have, is how can I provide this bean instead of the real bean, > based on the value of WebApplication.getConfigurationType()? > > The obvious solution for me would be to do it in the initialization of our > WicketApplication - we already have a "if we're in development mode" section > where we output component paths and turn on request logging and session size > recording etc. is there a way I can programmatically provide my bean at this > point? Or am I going about this entirely the wrong way? > > Many thanks for any advice offered, > > Regards, > > Liam Clarke > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket and Spring - mocking a particular bean when Wicket is in development mode?
Hi, use a different applicationContext.xml that is used for integration testing. (use maven profiles for using different resource path pointing to different applicationContext.xml files). You cannot use WebApplication.getConfigurationType() as you need a preloaded spring configuration before your WebApplication is instantiated. Best Regards, Ilja Pavkovic Am Donnerstag, 7. Januar 2010 23:05:23 schrieb Liam Clarke-Hutchinson: > Hi all, > > This is probably more of a Spring question than a Wicket question, but I'm > asking here in the hopes that someone else has done this before. Basically, > we have a page that uses the @SpringBean annotation to inject a credit card > validation service. At the moment, when we're developing, it's injecting > the actual service, that then goes off to our card processor and validates > the card etc. For integration testing etc. I want to avoid this, so I've > created a simple implementation of the validation service that always > returns true. Question I have, is how can I provide this bean instead of > the real bean, based on the value of > WebApplication.getConfigurationType()? > > The obvious solution for me would be to do it in the initialization of our > WicketApplication - we already have a "if we're in development mode" > section where we output component paths and turn on request logging and > session size recording etc. is there a way I can programmatically provide > my bean at this point? Or am I going about this entirely the wrong way? > > Many thanks for any advice offered, > > Regards, > > Liam Clarke > -- binaere bauten gmbh · tempelhofer ufer 1a · 10961 berlin +49 · 171 · 9342 465 Handelsregister: HRB 115854 - Amtsgericht Charlottenburg Geschäftsführer: Dipl.-Inform. Ilja Pavkovic, Dipl.-Inform. Jost Becker - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Wicket and Spring - mocking a particular bean when Wicket is in development mode?
Hi all, This is probably more of a Spring question than a Wicket question, but I'm asking here in the hopes that someone else has done this before. Basically, we have a page that uses the @SpringBean annotation to inject a credit card validation service. At the moment, when we're developing, it's injecting the actual service, that then goes off to our card processor and validates the card etc. For integration testing etc. I want to avoid this, so I've created a simple implementation of the validation service that always returns true. Question I have, is how can I provide this bean instead of the real bean, based on the value of WebApplication.getConfigurationType()? The obvious solution for me would be to do it in the initialization of our WicketApplication - we already have a "if we're in development mode" section where we output component paths and turn on request logging and session size recording etc. is there a way I can programmatically provide my bean at this point? Or am I going about this entirely the wrong way? Many thanks for any advice offered, Regards, Liam Clarke