This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes getRemoteAddr Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "getRemoteAddr" Watch "getRemoteAddr" New topic


Rowan Chattaway
Ranch Hand

Joined: Jan 18, 2002
Posts: 75

I'm implementing the StrutsTestCase into my current project to provide a suite of JUnit tests for the core Struts actions.

However, the ProcessLoginAction implements ipaddress checking for screening of dubious users. This uses HttpServletrequest.getRemoteAddr().

For my JUnit test - because it's run within my IDE and therefore outside the servlet container, this isn't set and returns null. Because of this the struts action forwards to failure.

Obvioulsy I don't want to change to project code to suit the test.
Can I set remoteAddr someway? or get around this?

Any help would be much appreciated.

The early bird may get the worm, but the second mouse gets the cheese.........<br /> <br />Sun Certified Programmer for Java 2 Platform<br />Sun Certified Web-Component Developer for J2EE Platform
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
You can always decorate it yourself .. or use some mock object framework. Fun stuff.

I agree. Here's the link:
subject: getRemoteAddr
Similar Threads
JUnit 4 and @RunAs annotation
Cactus plugin ???
Run as Junit Test case
how set working directory for eclipse plugin
How to Report/log test result before a test case is finished