[ 
https://issues.apache.org/jira/browse/WICKET-6053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15354844#comment-15354844
 ] 

ASF GitHub Bot commented on WICKET-6053:
----------------------------------------

GitHub user duesenklipper opened a pull request:

    https://github.com/apache/wicket/pull/172

    WICKET-6053 Allow to reuse the same application instance in several t…

    …ests
    
    Cherry-pick the fix for WICKET-6053 for Wicket 6.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/duesenklipper/wicket wicket-6/WICKET-6053

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/wicket/pull/172.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #172
    
----
commit 8c3b6567852f60f68aa92cc77361f05d924af8b3
Author: Carl-Eric Menzel <cmen...@wicketbuch.de>
Date:   2016-06-28T20:38:25Z

    WICKET-6053 Allow to reuse the same application instance in several tests

----


> Allow to reuse the same application instance in several tests
> -------------------------------------------------------------
>
>                 Key: WICKET-6053
>                 URL: https://issues.apache.org/jira/browse/WICKET-6053
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-spring
>    Affects Versions: 7.1.0
>            Reporter: Marc G.
>            Assignee: Martin Grigorov
>              Labels: WicketTester, junit
>             Fix For: 7.3.0, 8.0.0-M1
>
>
> 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:
> {code:java}
> @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);
>       }
> {code}
> 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!
> {code:java}
> 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)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to