never mind, i tinkered a little bit and read the API docs. if anyone
is interested, here's what i did.

ActionProxy proxy = getActionProxy("/dummy-action");
MyAction action = (MyAction)proxy.getAction();

MockHttpServletResponse response = new MockHttpServletResponse();
action.setServletResponse(response);

String result = action.dummyAction();
Assert.assertNull(result); //should always be null

String json = response.getContentAsString();
Assert.assertNotNull(json); //shouldn't be null

On Fri, May 13, 2011 at 2:58 PM, Jake Vang <vangj...@googlemail.com> wrote:
> hi,
>
> i am using struts v2.1.8.1 + spring 3.0 + junit 4.0. it should be
> noted that i am using convention plugin for spring.
>
> my action class extends ActionSupport and implements
> ServletRequestAware and ServletResponseAware. the method i am testing
> inside my action class never returns a string literal (i.e. succes,
> error, input, etc...), and always returns null. the reason is that i
> am not forwarding users to any JSP page, but instead, i am writing
> JSON results back out to the response stream.
>
> i need to test my action class, and i have a test class that extends
> StrutsSpringTestCase. i followed the example at
> http://struts.apache.org/2.1.8.1/docs/struts-2-junit-plugin-tutorial.html,
> which was very helpful. however, when my code writes JSON back out
> using ServletOutputStream, i get a NullPointerException. The
> NullPointerException happens because the HttpServletResponse is null.
> (i.e. null pointer happens on ServletOutputStream os =
> getHttpServletResponse().getOutputStream()).
>
> is there a step i am missing here that explains why the
> HttpServletResponse object/field is null?
>
> is there anyway to test action classes that do not return the usual
> string literals but the contents of the output stream?
>
> thank you in advance.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to