You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jan Ferko <ju...@gmail.com> on 2011/10/03 13:16:32 UTC

Unit Testing Application with custom HttpServletResponse

Hi everyone,

We use proxy around HttpServletResponse in our application. I would like 
to test components/pages using WicketTester, but when WicketTester tries 
to startPage it throws following exception:

java.lang.ClassCastException: myPackage.HttpServletResponseProxy cannot 
be cast to org.apache.wicket.protocol.http.MockHttpServletResponse
     at 
org.apache.wicket.protocol.http.MockWebApplication.postProcessRequestCycle(MockWebApplication.java:555)
     at 
org.apache.wicket.protocol.http.MockWebApplication.processRequestCycle(MockWebApplication.java:507)
     at 
org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:319)

This is of course correct because our proxy implementation is not 
MockHttpServletResponse. Is there any workaround this problem?

Thanks for help.

Jan

Re: Unit Testing Application with custom HttpServletResponse

Posted by Jan Ferko <ju...@gmail.com>.
I found out solution for this by overriding createRequestCycle() in 
WicketTester.

@Override
public WebRequestCycle createRequestCycle() {
       final WebRequestCycle mockCycle = super.createRequestCycle();

       final MockHttpServletRequest mockRequest = new 
MockHttpServletRequest(getApplication(), //
               getServletSession(), getApplication().getServletContext());
       final MockHttpServletResponse mockResponse = new 
MockHttpServletResponse(mockRequest);

       final WebRequest request = new ServletWebRequest(mockRequest);
       final WebResponse response = new WebResponse(mockResponse);

       mockCycle.setRequest(request);
       mockCycle.setResponse(response);
       return mockCycle;
}


On 10/03/2011 01:16 PM, Jan Ferko wrote:
> Hi everyone,
>
> We use proxy around HttpServletResponse in our application. I would 
> like to test components/pages using WicketTester, but when 
> WicketTester tries to startPage it throws following exception:
>
> java.lang.ClassCastException: myPackage.HttpServletResponseProxy 
> cannot be cast to org.apache.wicket.protocol.http.MockHttpServletResponse
>     at 
> org.apache.wicket.protocol.http.MockWebApplication.postProcessRequestCycle(MockWebApplication.java:555)
>     at 
> org.apache.wicket.protocol.http.MockWebApplication.processRequestCycle(MockWebApplication.java:507)
>     at 
> org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:319)
>
> This is of course correct because our proxy implementation is not 
> MockHttpServletResponse. Is there any workaround this problem?
>
> Thanks for help.
>
> Jan