Hi,

I tried to make PageTester work with our application. The problem is that the application needs Spring where Tapestry5 pages and modules accesses Spring beans and Spring beans accesses Tapestry services. This works fine within the Web container. but not with page tester (even not with the change described in the wiki http://wiki.apache.org/tapestry/Tapestry5-TestWithTapestry-Spring). The application also requires some custom filters (e.g. OpenSessionInView filter) and stuff like a Spring ContextCustomizer which are completely ignored by the pagetester.

I tried a lot to get it work but everytime i solved a problem I found a new one. So I started a completely different approach which allowes testing of the unchanged application which I'd like to discuss.

1. Emulate the whole servlet container
This sounds more heavy than it is. I simply parse the web.xml and create Servlets and Filters+FilterChains from it using MockServletConfig and such from spring testing. So I simply need to set up a MockHttpServletRequest + a Response and pass it to the FilterChain. This allows me to start the whole application with all filters including Tapestry with a few lines of code. Surprisingly the started application works out of the box including all the Spring/Filter stuff.

2. Capture the RenderedDocument "in container"
ATM I just did some tests if it is possible. Here's how I imagine that it could work. This approach would also allow real In-Container-Tests using the famous PageTester: - a special marker will be added to the ServletRequest that identifies it as test request (e.g. a special header) - A special filter in the servlet filter chain (1st filter) looks for this marker. If pressent, it creates a special ThreadLocal object that signals the application that this is a test request. This ThreadLocal object will later holt the rendered Document. Request and Response are replaces by some wrappers. - A tapestry markup filter similar to the one provided by the pagetester module looks for the ThreadLocal object and puts the rendered document to it - after all processing, the special filter takes the rendered document and returns it as serialized object to the servlet's output stream.

3. Modularize PageTester
- Since PageTester always tries to instanciate teh application, it's not possible to extend it. There should be a PageTesterBase class that holds the pagetester logic and delegates everything that is required for conneting to the application to abstract methods.

I'm looking forward for your comments to this approach.

Regards,
Michael.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to