[prev in list] [next in list] [prev in thread] [next in thread] 

List:       tapestry-user
Subject:    Re: NPE from unit testing with equanda-tapestry5
From:       Josh Canfield <joshcanfield () gmail ! com>
Date:       2010-07-28 14:17:15
Message-ID: AANLkTikCpBXbsc2uuHr3RE+=S9j7bqb_whKBMuCCsGoQ () mail ! gmail ! com
[Download RAW message or body]

I found this on the list some time ago. You can add the
HttpServletRequest/Response in a test module.

public class PageTesterModule {
    // Ensure that there are valid HTTP request/response objects in the test

    public static void contributeRequestHandler(
            final OrderedConfiguration<RequestFilter> config,
            final RequestGlobals requestGlobals) {

        RequestFilter filter = new RequestFilter() {
            public boolean service(Request request, Response response,
RequestHandler handler) throws IOException {
                requestGlobals.storeServletRequestResponse(
                        EasyMock.createMock(HttpServletRequest.class),
                        EasyMock.createMock(HttpServletResponse.class)
                );
                return handler.service(request, response);
            }
        };
        config.add("EnsureNonNullHttpRequestAndResponse", filter, "before:*");
    }
}


If you are using PageTester you can add the module this way:


 @BeforeClass
    public void setupPageTester() {
        String appPackage = "com.bodylab.gymserver";
        String appName = "app";
        _pageTester = new PageTester(appPackage, appName,
"src/main/webapp", PageTesterModule.class);
    }


Josh

On Tue, Jul 27, 2010 at 11:02 PM, Dongmei Cao <dongmei.cao@icann.org> wrote:
> Hi,
> 
> I use the equanda/Tabs in my web application. It actually works pretty well except \
> it throws NPE in unit testing: 
> ERROR] TapestryModule.RequestExceptionHandler Processing of request failed with \
> uncaught exception: java.lang.NullPointerException java.lang.NullPointerException
> at org.equanda.tapestry5.services.EquandaModule$1.service(EquandaModule.java:83)
> 
> Here is the code from EquandaModule.java that fails:
> 
> public static RequestFilter buildUtf8Filter(
> @InjectService( "RequestGlobals" ) final RequestGlobals requestGlobals )
> {
> return new RequestFilter()
> {
> public boolean service( Request request, Response response, RequestHandler handler \
> ) throws IOException
> {
> requestGlobals.getHTTPServletRequest().setCharacterEncoding( "UTF-8" );  // \
> <---------------------- NPE on this line due to null HttpServletRequest return \
> handler.service( request, response ); }
> };
> }
> 
> Anyone has any idea how to get around this in unit testing?
> 
> Thanks in advance!
> 
> -D
> 



-- 
--
http://www.bodylabgym.com - a private, by appointment only, one-on-one
health and fitness facility.
--
http://www.ectransition.com - Quality Electronic Cigarettes at a
reasonable price!
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic