You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Martin Grigorov (JIRA)" <ji...@apache.org> on 2015/06/25 10:21:04 UTC
[jira] [Resolved] (WICKET-5926) Arquillian Support with Container
ServletContext in BaseWicketTester/WicketTester.
[ https://issues.apache.org/jira/browse/WICKET-5926?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Martin Grigorov resolved WICKET-5926.
-------------------------------------
Resolution: Fixed
Fix Version/s: 7.0.0-M7
6.21.0
The PR has been merged to master branch (Wicket 7.x). The Arquillian test will serve as a demo and to catch regressions in (Base)WicketTester.
In 6.x I've merged only the improvements to (Base)WicketTester.
Many thanks for your contribution, Felipe!
> Arquillian Support with Container ServletContext in BaseWicketTester/WicketTester.
> ----------------------------------------------------------------------------------
>
> Key: WICKET-5926
> URL: https://issues.apache.org/jira/browse/WICKET-5926
> Project: Wicket
> Issue Type: Improvement
> Components: wicket
> Affects Versions: 6.10.0, 6.11.0, 6.12.0, 6.13.0, 6.14.0, 6.15.0, 6.16.0, 7.0.0-M2, 7.0.0-M3, 6.17.0, 6.18.0, 1.5.13, 7.0.0-M4, 7.0.0-M5, 6.19.0, 6.20.0
> Environment: Ubuntu 14.04, JDK 8/7/6
> Reporter: Felipe Campos de Almeida
> Assignee: Martin Grigorov
> Labels: automation, features, patch, test
> Fix For: 6.21.0, 7.0.0-M7
>
>
> Hello all,
> I'm wondering if BaseWicketTester could support an ServletContext and WicketFilter provided by an web.xml configured and the container reading and installing my XTestWebApplication.java instead of using Mock everytime.
> I'm using Arquillian from http://arquillian.org.
> And this improvement is going to help to run my tests with success using webapp/WEB-INF/ configuration (like web.xml and so on).
> I've already done the code and I'll commit (after some tests to maintain the legacy) to my github: https://github.com/felipecalmeida/wicket
> In my initial tests, the wicket-core tests are passing.
> For this first commit, I kept the mock on Session, request and respond, because it's not a problem yet.
> I don't have yet a sample test to help to understand better this modification, because I've to create a sample project using Arquillian in my github. But I can take some screenshots later and upload here or in my github, if it helps.
> I'll post here the full code before commit:
> {code:title=BaseWicketTester.java|borderStyle=solid}
> /**
> * Creates a <code>WicketTester</code>. Constructor to keep the legacy code.
> *
> * @param application
> * a <code>WicketTester</code> <code>WebApplication</code> object
> * @param servletCtx
> * the servlet context used as backend
> */
> public BaseWicketTester(final WebApplication application, final ServletContext servletCtx)
> {
> // Keeping legacy code.
> this(application, servletCtx, true);
> }
>
> /**
> * Creates a <code>WicketTester</code>.
> *
> * @param application
> * a <code>WicketTester</code> <code>WebApplication</code> object
> * @param servletCtx
> * the servlet context used as backend
> * @param initializeApplication
> * if don't have an application, initialize it
> */
> public BaseWicketTester(final WebApplication application, final ServletContext servletCtx, boolean initializeApplication)
> {
> // Default is to initialize the application.
> if(initializeApplication)
> {
>
> if(servletCtx == null)
> {
> servletContext = new MockServletContext(application, null);
> }
> else
> {
> servletContext = servletCtx;
> }
> }
> else
> {
> // Uses the servletContext provided by the container.
> servletContext = application.getServletContext();
> }
>
> // Container that don't provide a WicketFilter.
> if(application.getWicketFilter() == null)
> {
> final FilterConfig filterConfig = new TestFilterConfig();
> WicketFilter filter = new WicketFilter()
> {
> @Override
> public FilterConfig getFilterConfig()
> {
> return filterConfig;
> }
> };
>
> application.setWicketFilter(filter);
> }
>
> httpSession = new MockHttpSession(servletContext);
> ThreadContext.detach();
> this.application = application;
> if(initializeApplication)
> {
> // FIXME some tests are leaking applications by not calling destroy on them or overriding
> // teardown() without calling super, for now we work around by making each name unique
> application.setName("WicketTesterApplication-" + UUID.randomUUID());
> }
>
> ThreadContext.setApplication(application);
> if(initializeApplication)
> {
> application.setServletContext(servletContext);
> // initialize the application
> application.initApplication();
> }
> // We don't expect any changes during testing. In addition we avoid creating
> // ModificationWatcher threads tests.
> application.getResourceSettings().setResourcePollFrequency(getResourcePollFrequency());
> // reconfigure application for the test environment
> application.setPageRendererProvider(new LastPageRecordingPageRendererProvider(
> application.getPageRendererProvider()));
> application.setRequestCycleProvider(new TestRequestCycleProvider(
> application.getRequestCycleProvider()));
> // set a feedback message filter that will not remove any messages
> originalFeedbackMessageCleanupFilter = application.getApplicationSettings()
> .getFeedbackMessageCleanupFilter();
> application.getApplicationSettings().setFeedbackMessageCleanupFilter(
> IFeedbackMessageFilter.NONE);
> IPageManagerProvider pageManagerProvider = newTestPageManagerProvider();
> if (pageManagerProvider != null)
> {
> application.setPageManagerProvider(pageManagerProvider);
> }
> // create a new session when the old one is invalidated
> application.getSessionStore().registerUnboundListener(new UnboundListener()
> {
> @Override
> public void sessionUnbound(String sessionId)
> {
> newSession();
> }
> });
> // prepare session
> setupNextRequestCycle();
> }
> {code}
> {code:title=WicketTester.java|borderStyle=solid}
> /**
> * Creates a <code>WicketTester</code> to help unit testing. Constructor to keep the legacy code.
> *
> * @param application
> * a <code>WicketTester</code> <code>WebApplication</code> object
> * @param servletCtx
> * the servlet context used as backend
> */
> public WicketTester(WebApplication application, ServletContext servletCtx)
> {
> super(application, servletCtx);
> }
>
> /**
> * Creates a <code>WicketTester</code> to help unit testing.
> *
> * @param application
> * a <code>WicketTester</code> <code>WebApplication</code> object
> * @param servletCtx
> * the servlet context used as backend
> * @param initializeApplication
> * if don't have an application, initialize it
> */
> public WicketTester(WebApplication application, ServletContext servletCtx, boolean initializeApplication)
> {
> super(application, servletCtx, initializeApplication);
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)