View Full Version : MockServletContext needs a resourceLoader
jwindberg
Jan 4th, 2006, 03:08 PM
I'm trying to write a test case for a tag.
The tag uses:
pageContext.getServletContext().getRealPath(filePa th);
which is null from MockServletContext.
The api doc says to configure it with a resourceloader.
Anyone know how?
I've been trying to create a DefaultResourceLoader, which wants a servletContext, which wants a ResourceLoader.
I'm soooo confused.
Cowboy Bob
Jan 4th, 2006, 05:59 PM
getRealPath returns null if you don't give it a path even on some real servers. Have you tried pageContext.getServletContext().getRealPath("/")?
Bob
jwindberg
Jan 6th, 2006, 10:34 AM
Actually, I've been trying something specific:
pageContext.getServletContext().getRealPath("WEB-INF/data/files/file.txt")
The tag I want to test is supposed to open a file found relative to the home dir of the web app. I just can't figure out how to define the home dir of the web app to the mock classes in a way that getRealPath will actually work.
leo.m
Feb 15th, 2006, 01:23 PM
Have you tried, when instantiating your MockServletContext, passing in the home directory of the webapp?
like:
ServletContext sc = new MockServletContext("/path/to/web_home");
janning
Jun 28th, 2007, 02:58 PM
just for further reference as i came across this thread:
it must be IMHO:
ServletContext sc =
new MockServletContext("file:/path/to/web_home");
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.