aspose file tools*
The moose likes Spring and the fly likes UnitTest in Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "UnitTest in Spring" Watch "UnitTest in Spring" New topic
Author

UnitTest in Spring

praneeth ram
Ranch Hand

Joined: Sep 21, 2009
Posts: 60
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

Joined: Oct 16, 2009
Posts: 66

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.


Googling doesn't make you a genius. But not Googling makes you dumber.
praneeth ram
Ranch Hand

Joined: Sep 21, 2009
Posts: 60
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

Joined: Oct 16, 2009
Posts: 66

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

Joined: Sep 21, 2009
Posts: 60
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

Joined: Sep 21, 2009
Posts: 60
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

Joined: Jun 25, 2001
Posts: 16308
    
  22

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: UnitTest in Spring