Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

UnitTest in Spring

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 66
VI Editor Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
VI Editor Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 23540
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic