wood burning stoves 2.0*
The moose likes Servlets and the fly likes Working with Session in Mock Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Working with Session in Mock Objects" Watch "Working with Session in Mock Objects" New topic
Author

Working with Session in Mock Objects

Chad Cook
Greenhorn

Joined: Dec 02, 2004
Posts: 29
Hi all, I'm beating myself senseless trying to get my JUnit fired off that's using MockObjects, but after I set attributes in my session I can't retrieve them, I keeep getting an error saying that it can't find my FPASession (the object that I want to retrieve from the session).

So here's the code that I'm using (the line that fails is in bold):

MockHttpServletRequest mockRequest = new MockHttpServletRequest();

FPASession fpaSession = new FPASession();

MockHttpSession mockSession = new MockHttpSession();

mockSession.setAttribute(FPAUIConstants.FPA_SESSION, fpaSession);

FPASession testFPASession = (FPASession) mockSession.getAttribute(FPAUIConstants.FPA_SESSION);

mockRequest.setSession(mockSession);

Any ideas why I can't retrieve the FPASession object after I set it in the Mock Object session?
[ December 02, 2004: Message edited by: Chad Cook ]
Chad Cook
Greenhorn

Joined: Dec 02, 2004
Posts: 29
Never mind folks, I found the answer.

It turns out that you have to call setupGetAttribute() to set the attribute, rather than setAttribute().

All is working well now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Working with Session in Mock Objects