This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

Working with Session in Mock Objects

Chad Cook

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);


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

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.
Have you checked out Aspose?
subject: Working with Session in Mock Objects
It's not a secret anymore!