You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Justin Robbins <ju...@gmail.com> on 2011/04/29 19:35:58 UTC

NPE in StrutsTestCase after enabling Tiles

Hi Folks,

This is my first post to user@struts.apache.org.  I yesterday posed
this same question on stackoverflow but haven't garnered any responses
so I figured I'd give this list a try.  Hope that's cool.

http://stackoverflow.com/questions/5823709/npe-in-strutstestcase-after-enabling-tiles

<begin question>

I developed some JUnit tests that extend
org.apache.struts2.StrutsTestCase. I used the tutorial
(http://struts.apache.org/2.x/struts-2-junit-plugin-tutorial.html) on
struts.apache.org as my starting point.

Everything was working fine until I modified my simple web application
to use Tiles. I have Tiles working fine in the app but now my Struts
Action test cases have stopped working.

I'm getting NullPointerException at
org.apache.struts2.views.tiles.TilesResult.doExecute when I run the
following line of code:

ActionProxy proxy = getActionProxy("/displaytag.action");

The log shows the Struts 2 Action is executing succesfully until it
tries to hand it off to TilesResult.doExecute.

I suspect it is because the tests run outside of the container and the
tiles.xml is only referenced in the web.xml and therefore my
StrutsTestCase tests don't know where to find the definitions in
tiles.xml.

Is this making sense?

I'm using Struts 2.2.1.1 and the tiles related jars (v. 2.0.6)
included in the Struts distribution.

I'll include a code snippet from my StrutsTestCase but please note
everything runs successfully when I run the app from the browser in
Tomcat, it only fails when I run the StrutsTestCase outside of Tomcat.
And the test cases ran successfully before I added Tiles.

public class TagActionTest extends StrutsTestCase {

static Logger logger = Logger.getLogger(TagActionTest.class);

public void testCreateTagFail() throws Exception {

    try {
        request.setParameter("name", "");

        ActionProxy proxy = getActionProxy("/createtag.action");

        TagAction tagAction = (TagAction) proxy.getAction();

        proxy.execute();

        assertTrue("Problem There were no errors present in
fieldErrors but there should have been one error present",
tagAction.getFieldErrors().size() == 1);
        assertTrue("Problem field 'name' not present in fieldErrors
but it should have been",
                tagAction.getFieldErrors().containsKey("name") );
    } catch (Exception e) {
        logger.debug("Error running testCreateTagFail()");
        e.printStackTrace();

        assertTrue("Error running testCreateTagFail()", false);
    }
}

Partial stack trace:

java.lang.NullPointerException
at org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:105)
at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)

Lastly, can anyone explain what the deal is with StrutsTestCase?
There's a tutorial page for using it with Struts 2 on
struts.apache.org but the SourceForge page
(http://strutstestcase.sourceforge.net/) for it hasn't been updated
since Struts 1.3 Also, what's the difference between StrutsTestCase
and MockStrutsTestCase

</end question>

--
Regards,
Justin Robbins

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


Re: NPE in StrutsTestCase after enabling Tiles

Posted by Justin Robbins <ju...@gmail.com>.
Ah, ok.  So the SourceForge one is not the one I'm using then.  I'm
extending org.apache.struts2.StrutsTestCase in the test I'm having
problems with.  Thanks for your input!

On Fri, Apr 29, 2011 at 1:47 PM, Dave Newton <da...@gmail.com> wrote:
> On Fri, Apr 29, 2011 at 1:35 PM, Justin Robbins wrote:
>> Lastly, can anyone explain what the deal is with StrutsTestCase?
>> There's a tutorial page for using it with Struts 2 on
>> struts.apache.org but the SourceForge page
>> (http://strutstestcase.sourceforge.net/) for it hasn't been updated
>> since Struts 1.3
>
> "StrutsTestCase" is a generic name. You're looking at an old,
> third-party StrutsTestCase on sourceforge; the one for Struts 2 is
> part of Struts 2.
>
> Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Regards,
Justin Robbins
973.479.0448
JustinHRobbins@gmail.com

Learn more about me by viewing my professional profile on LinkedIn
http://www.linkedin.com/in/justinhrobbins

View my professional blog
http://javadeveloperjournal.blogspot.com/

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


Re: NPE in StrutsTestCase after enabling Tiles

Posted by Dave Newton <da...@gmail.com>.
On Fri, Apr 29, 2011 at 1:35 PM, Justin Robbins wrote:
> Lastly, can anyone explain what the deal is with StrutsTestCase?
> There's a tutorial page for using it with Struts 2 on
> struts.apache.org but the SourceForge page
> (http://strutstestcase.sourceforge.net/) for it hasn't been updated
> since Struts 1.3

"StrutsTestCase" is a generic name. You're looking at an old,
third-party StrutsTestCase on sourceforge; the one for Struts 2 is
part of Struts 2.

Dave

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