I have a question on understanding/using MockServletContext - I have to test a servlet which contains loads of getServletContext().getRealPath(String) method calls in its init() method. Unfortunately, this value is for some reason null, which of course causes a bunch of problems. I've tried to figure out how this can be done by going thru your examples with no success.
Now, to the question: To mock the servlet, I need to set/mock the path to the app by setting the path with MockServletContext.setRealPath() to a certain value - right? If so, how can this be done?
I'm fairly new to using MockRunner, so please forgive me if I trouble you with this rookie question.
Thanks in advance,
Sascha.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
so if the servlet calls getRealPath("path") it gets "realpath" as return value. There's no other way than setting all real path values you want to test manually at the moment. Otherwise you get null.
Kind regards,
Alwin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I have a question on understanding/using MockServletContext - I have to test a servlet which contains loads of getServletContext().getRealPath(String) method calls in its init() method. Unfortunately, this value is for some reason null, which of course causes a bunch of problems. I've tried to figure out how this can be done by going thru your examples with no success.
Now, to the question: To mock the servlet, I need to set/mock the path to the app by setting the path with MockServletContext.setRealPath() to a certain value - right? If so, how can this be done?
I'm fairly new to using MockRunner, so please forgive me if I trouble you with this rookie question.
Thanks in advance,
Sascha.
Hi Sascha,
Yes you are right. You have to set the real path using setRealPath, e.g.
getWebMockObjectFactory().getMockServletContext().setRealPath("path", "realpath");
so if the servlet calls getRealPath("path") it gets "realpath" as return value. There's no other way than setting all real path values you want to test manually at the moment. Otherwise you get null.
Kind regards,
Alwin
Hi Alwin,
thank you for such a lightning fast response! You really helped me a lot.
Regards,
Sascha.