Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

realPath for MockHttpServletRequest

I am writing a Spring based Test case for my Spring Controller, in my controller we are using like this "request.getSession().getServletContext().getRealPath("/myFolderName");" Its working fine for normal requests, but for unit test cases like MockHttpServletRequest it is the above method call is giving null. how can i get realPath for MockHttpServletRequest.

Thanks, Praneeth.

like image 759
user1350672 Avatar asked Nov 22 '25 14:11

user1350672


1 Answers

By default MockHttpServletRequest acts as if root webapp folder is a classpath, therefore you should be able to use getRealPath() for classpath resources.

Alternatively, you can supply MockHttpServletRequest with MockServletContext, and MockServletContext can be configured with specific root folder for getRealPath(), etc.

like image 171
axtavt Avatar answered Nov 25 '25 11:11

axtavt