Menu

#33 getOutput() doesn't work for JSPs

closed
None
5
2008-06-27
2008-04-22
No

This is for Mockrunner 0.4 with Java 1.5 and Servlet API 2.4.

There is a bug somewhere in MockPageContext, MockJspWriter and the setup code for those two.

The problem: When I pass a JSP as servlet to BasicServletTestCaseAdapter.createServlet(), then a response is created which contains an MockServletOutputStream as output. The PageContext contains a MockJspWriter and those two are not connected: the MockJspWriter uses a simple StringWriter because it's constructor called without arguments in MockPageContext.

My quick fix was to set jspWriter to null in the constructor and in initialize() and change MockPageContext:getOut() like this:

public JspWriter getOut()
{
if (jspWriter == null)
{
try
{
jspWriter = new MockJspWriter (response.getWriter ());
}
catch (IOException e)
{
e.printStackTrace();
}
}

return jspWriter;
}

Discussion

  • Alwin Ibba

    Alwin Ibba - 2008-05-25

    Logged In: YES
    user_id=804648
    Originator: NO

    Thanks, will be fixed

     
  • Alwin Ibba

    Alwin Ibba - 2008-05-25
    • assigned_to: nobody --> aibba
     
  • Alwin Ibba

    Alwin Ibba - 2008-06-27
    • status: open --> closed
     
  • Aaron Optimizer Digulla

    Logged In: YES
    user_id=606
    Originator: YES

    Verified with 0.4.1.

     
  • Aaron Optimizer Digulla

    The bug is back with MockRunner 0.4.2.

    I really suggest to create the JspWriter as late as possible to avoid losing the synchronization between the response and the JspWriter.

     
  • Aaron Optimizer Digulla

    Sorry, ignore that comment. I wasn't aware that JspFactory is a global variable (which means all tests receive the same PageContext :-( )