Re: Wicket tests with Spring Boot
Not sure if it helps or it is what are you looking for but this is how I do it. I have abstract base class that - sets Wicket application into Spring ApplicationContext - creates WicketTester - uses static configuration class to create mocks of required Spring components in ApplicationContext that are in turn injected into Wicket components using @SpringBean @RunWith(SpringRunner.class) @ContextConfiguration @ImportAutoConfiguration(WicketAutoConfiguration.class) public abstract class BaseWicketTest { @Autowired protected WebApplication wicketApplication; @Autowired protected ApplicationContext applicationContextMock; protected WicketTester wicketTester; @Before public void baseSetUp() { ReflectionTestUtils.setField(wicketApplication, "applicationContext", applicationContextMock); wicketTester = new WicketTester(wicketApplication); } @Configuration @ComponentScan({"my.package"}) @Import(AnotherConfiguration.class) public static class Config { @Bean UserDetailsService userDetailsService() { return mock(MyUserDetailsService.class); } } } Then all test classes extend this abstract base class. @RunWith(SpringRunner.class) public class WicketComponentTest extends BaseWicketTest { // autowired mock @Autowired private UserDetailsService userDetailsServiceMock; @Test public void testSomething() { // stub userDetailsServiceMock using Mockito when() // perform wicket component initialization and do tests (submit form, perform ajax etc) // validate userDetailsServiceMock using Mockito verify() } } Does everything I need and seems pretty clear to me but maybe someone here has a better setup. Zbynek On Wed, Jul 10, 2019 at 11:41 AM Tom Götz wrote: > We have both, a service layer and a persistence layer (each in it's own > maven module). We use Spring Data Jpa repositories for the persistence > layer and Liquibase for managing DB changes. When testing the Wicket layer > I don't want the complete persistence and service layer to be initialized > by Spring (e.g. no need for persistence context initialization and > Liquibase), but would prefer to work with mocks. Is that enough information > for you or what else should I provide? > Tom > > > Am 10.07.2019 um 11:00 schrieb Andrei Kondratev < > andrei.kondra...@unimarket.com>: > > > > Hi Tom! > > > > It depends on the implementation. If you have a service level it's not > necessary to mock persistence, but enough to mock services and inject them > (if you use @Autowired annotation). > > > > Could you please give a bit more examples of what you're trying to test? > > > > > >> On Wed, 10 Jul 2019 at 20:56, "Tom Götz" wrote: > >> Hi there, > >> > >> we have a Spring Boot based webapp (Wicket 8.4 with wicket-spring-boot > 2.1.6) and would like to create a base test class for our Wicket tests. For > testing, we would like to mock the service and persistence layer (e.g. with > Mockito). Is there a good example for that purpose? > >> > >> Cheers > >> Tom > >> > >> > >> - > >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > >> For additional commands, e-mail: users-h...@wicket.apache.org > >> > > -- > > ANDREW KONDRATEV > > TECHNICAL LEAD > > > > > > > > MOB +64 210 492 674 > > EMAIL andrei.kondra...@unimarket.com > > www.unimarket.com > > > > Simple and easy-to-use software that brings all your procurement into > one place. >
AW: Re: Wicket tests with Spring Boot
Have you tried @MockBean from Spring Boot. Alternative with @ContextConfiguration you can assign configuration classes and export custom mocks. Stephan Von meinem gesendet Tom Götz schrieb >We have both, a service layer and a persistence layer (each in it's own maven >module). We use Spring Data Jpa repositories for the persistence layer and >Liquibase for managing DB changes. When testing the Wicket layer I don't want >the complete persistence and service layer to be initialized by Spring (e.g. >no need for persistence context initialization and Liquibase), but would >prefer to work with mocks. Is that enough information for you or what else >should I provide? >Tom > >> Am 10.07.2019 um 11:00 schrieb Andrei Kondratev >> : >> >> Hi Tom! >> >> It depends on the implementation. If you have a service level it's not >> necessary to mock persistence, but enough to mock services and inject them >> (if you use @Autowired annotation). >> >> Could you please give a bit more examples of what you're trying to test? >> >> >>> On Wed, 10 Jul 2019 at 20:56, "Tom Götz" wrote: >>> Hi there, >>> >>> we have a Spring Boot based webapp (Wicket 8.4 with wicket-spring-boot >>> 2.1.6) and would like to create a base test class for our Wicket tests. For >>> testing, we would like to mock the service and persistence layer (e.g. with >>> Mockito). Is there a good example for that purpose? >>> >>> Cheers >>> Tom >>> >>> >>> - >>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >>> For additional commands, e-mail: users-h...@wicket.apache.org >>> >> -- >> ANDREW KONDRATEV >> TECHNICAL LEAD >> >> >> >> MOB +64 210 492 674 >> EMAIL andrei.kondra...@unimarket.com >> www.unimarket.com >> >> Simple and easy-to-use software that brings all your procurement into one >> place.
Re: Wicket tests with Spring Boot
We have both, a service layer and a persistence layer (each in it's own maven module). We use Spring Data Jpa repositories for the persistence layer and Liquibase for managing DB changes. When testing the Wicket layer I don't want the complete persistence and service layer to be initialized by Spring (e.g. no need for persistence context initialization and Liquibase), but would prefer to work with mocks. Is that enough information for you or what else should I provide? Tom > Am 10.07.2019 um 11:00 schrieb Andrei Kondratev > : > > Hi Tom! > > It depends on the implementation. If you have a service level it's not > necessary to mock persistence, but enough to mock services and inject them > (if you use @Autowired annotation). > > Could you please give a bit more examples of what you're trying to test? > > >> On Wed, 10 Jul 2019 at 20:56, "Tom Götz" wrote: >> Hi there, >> >> we have a Spring Boot based webapp (Wicket 8.4 with wicket-spring-boot >> 2.1.6) and would like to create a base test class for our Wicket tests. For >> testing, we would like to mock the service and persistence layer (e.g. with >> Mockito). Is there a good example for that purpose? >> >> Cheers >> Tom >> >> >> - >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> For additional commands, e-mail: users-h...@wicket.apache.org >> > -- > ANDREW KONDRATEV > TECHNICAL LEAD > > > > MOB +64 210 492 674 > EMAIL andrei.kondra...@unimarket.com > www.unimarket.com > > Simple and easy-to-use software that brings all your procurement into one > place.
Re: Wicket tests with Spring Boot
Hi Tom! It depends on the implementation. If you have a service level it's not necessary to mock persistence, but enough to mock services and inject them (if you use @Autowired annotation). Could you please give a bit more examples of what you're trying to test? On Wed, 10 Jul 2019 at 20:56, "Tom Götz" wrote: > Hi there, > > we have a Spring Boot based webapp (Wicket 8.4 with wicket-spring-boot > 2.1.6) and would like to create a base test class for our Wicket tests. For > testing, we would like to mock the service and persistence layer (e.g. with > Mockito). Is there a good example for that purpose? > > Cheers > Tom > > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > -- *ANDREW KONDRATEV* TECHNICAL LEAD [image: cid:BCFC90CC-ECC8-433C-AA3E-F8FA38DA99DB] MOB +64 210 492 674 <%2B64%2021%20049%202674> EMAIL andrei.kondra...@unimarket.com www.unimarket.com Simple and easy-to-use software that brings all your procurement into one place.