Details
-
Improvement
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
7.1.0
Description
I'm working on an integration project of Spring Boot and Wicket. Currently I've problems with JUnits @Before method and the WicketTester when the WebApplication is a bean itself..
The WebApplication is Autowired in the test class and used as a constructor parameter for the WicketTester. With one test method there is no problem. But the second method throws an exception (see below). It seems that the WicketTester throws the exception on the second time cause the WebApplication is already initialized and the WicketTester expects a new one.
Pseudo Code:
@RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = WicketWebApplication.class) @WebAppConfiguration public class WicketBaseTest { private WicketTester tester; @Autowired private WicketWebApplication wicketApplication; private ApplicationContextMock applicationContextMock; @Before public void setUp() { applicationContextMock = new ApplicationContextMock(); ReflectionTestUtils.setField(wicketApplication, "applicationContext", applicationContextMock); //throws the error the second time tester = new WicketTester(wicketApplication); }
My solution was to mark the WicketTester as static and only initialize it the first time. I'dont know if it produce any side effects if the WicketTester is reused in multiple tests.
An alternative is to mark each test with Springs @DirtiesContext to reinitialize the WebApplication to that the WicketTester can initialize the WebApplication with a fresh new one but this solution is time consuming.
Is there a way to adapt the WicketTester that it accepts already initialized WebApplications? Has the WebApplication to be initialized for each test? Can a test change the behaviour of an existing WebApplication in a way that it affects other tests?
Thanks a lot!
java.lang.IllegalStateException: Application name can only be set once. at org.apache.wicket.Application.setName(Application.java:991) The current alternative is to reuse the WicketTester for all tests and don't create a new one for eacht test. This may affect tests among each other but it seems the only short-term solution. java.lang.IllegalStateException: Application name can only be set once. at org.apache.wicket.Application.setName(Application.java:991) at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:330) at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:266) at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:239) at org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:203) at com.giffing.wicket.spring.boot.example.web.WicketBaseTest.setUp(WicketBaseTest.java:58) at com.giffing.wicket.spring.boot.example.web.pages.customers.CustomerListPageTest.setUp(CustomerListPageTest.java:35) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Attachments
Issue Links
- is related to
-
WICKET-5816 Apps can't use Application.setName instead of WicketFilter for e.g. JMX names
- Resolved
- relates to
-
WICKET-5389 Allow continued processing with WicketTester after exception is thrown
- Resolved
- links to