Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

UnitTest in Spring

 
praneeth ram
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Spring Controller having bla bla code along with the bellow line of code.. i wrote a TestCase for the respected Spring Controller by using MockHttpServletRequest,response,session. every thing is working fine except the bellow line.
I am getting "null" in my controller when i call it from the TestCase class.

How to get the "realPath" through the MockHttpServletRequest.
If any body know about it please give me a response... thanks in advance...


Praneeth.
 
Prabaharan Gopalan
Ranch Hand
Posts: 66
Java Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly is null? session or servletContext? I'd say the latter. Are you using MockServletContext? In which case, your context will change and you might not have a"pages" directory under the mock context root.
 
praneeth ram
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly is null?
my answer is like bellow

if the above line executes as a normal request through application no issues.
if the above line executes through the Spring Unit Testing MockHttpServletRequest i am getting null.
still if you are not getting my problem. i am very sorry please refer this url

Thanks,
Praneeth.
 
Prabaharan Gopalan
Ranch Hand
Posts: 66
Java Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked the URL and i agree with skaffman's comments. I guess, you need to check that as well.. that's the recent update i'm talking about.
 
praneeth ram
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gopalan,

Bellow is my code in controller.



and my Unit test code is something like this.



I am getting "null" in my controller for the "somePath" variable. if you understand my situation could you please suggest me a solution.

Thanks a lot in advance,

Praneeth.
 
praneeth ram
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

This is issue is resolved i kept "file:" while creating a string. observe the above mentioned code and edit like bellow



Thanks,
Praneeth
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getRealPath is a very dangerous function. It will return null anytime that there's no filesystem path to the requested resource. If you deploy a webapp on a server that doesn't "explode" the WAR (unzip it), the "files" in the WAR won't be actual filesystem files and they won't have realPaths.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic