Reputation: 860
I need to set real path for mockservletcontext so that I could access the path using
getServletContext().getRealPath("/").
This is the following code I used in Junit
MockServletContext context = new MockServletContext("/Users/pradeep/Desktop/", null);
SomeImpl userService = (SomeImpl) applicationContext.getBean("someBean");
userService.setServletContext(context);
but still getServletContext().getRealPath("/") returns me null.
Any suggestions to set path for a mockservlet?
Upvotes: 0
Views: 2775
Reputation: 53
In MockServletContext constructor, mention the absolute path to the location with 'file' as prefix.So that it understand it from the filesystem and not the virtual location.
Please refer this !
Upvotes: 1