Pradeep
Pradeep

Reputation: 860

how to set real path for mockservletcontext in junit

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

Answers (1)

Muzzammil Ayyubi
Muzzammil Ayyubi

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

Related Questions