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....@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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org