|
From: Jeff M. <je...@mk...> - 2003-05-01 09:28:16
|
You've caught me on a good day. I've just added a
setExpectedCreateSession method to the request for ya.
On Thu, 2003-05-01 at 01:08, Jeff Duska wrote:
> How do I write a unit test for code where I create the Session in the code
> I'm testing with _request.getSession(true) ?
>
> I'm getting a notImplemented Exception. I figure that this is a pretty
> basic thing that there is some type of workaround.
>
> Thanks,
>
> Jeff
>
> Jeff Duska wrote:
>
> > I'm using MockHttpSession in a unit test I bit confused on the proper
> > usage.
> >
> > In here is my setUp method
> >
> > public void setUp() throws Exception {
> > super.setUp();
> > _request = new MockHttpServletRequest();
> > _response = new MockHttpServletResponse();
> > _session = new MockHttpSession();
> > _request.setSession(_session);
> > _context = new VelocityContext();
> > }
> >
> > Here is my unitTest
> >
> > public void testFreeUserStandByPage() throws ExecuteCommandException {
> >
> > IUser user = new MockFreeUser();
> > assertNotNull("We must have a user for our test to work", user);
> >
> > _request.setupAddParameter("VARVALUE", "1880-10");
> >
> > // Add User to the session
> > _session.setAttribute("user", user);
> >
> > // our expected session attributes to be used by validate
> > _session.setExpectedAttribute("VARVALUE", "1880-10");
> > _session.setExpectedAttribute("noStandby", Boolean.TRUE);
> > _session.setExpectedAttribute("user", user);
> >
> > // run the command
> > Command command = new CreateWssrdPdfDocumentCommand(_request,
> > _response);
> > String templateName = command.exec(_context);
> >
> > // check the results
> > IUser testUser = (IUser) _context.get(IUser.USER_KEY);
> > assertEquals(user, testUser);
> > _session.verify();
> > assertEquals("Make sure we are getting the standby page
> > template",
> > templateName, "standby.vm");
> > }
> >
> > What is weird is that the order of setAttibute and setExpectAttribute
> > effect the success of my test. In the previous code the test fails,
> > because user object is not found in the session during the verify()
> > process. My test succeeds when I move the
> > _session.setAttribute("user,user) statement after the
> > setExecptedAttribute methods.
> >
> > This would be fine, but my next test fails both ways. The problem is
> > that I have to send the session attribute noStandby to Boolean.TRUE.
> > When command is completed I had expect that the attribute would not be
> > in the session, but this failed in the test. jUnit was always seeing the
> > attribute. Thus, I refactored my code to change it to the attribute
> > noStandby to be Boolean.TRUE. The problem is that I get an exception in
> > my test code on my _session.setAttribute("noStandby", Boolean.FALSE)
> > saying that is unexpected. I confused.
> >
> > Any help or suggestions would be appreciated.
> >
> > -------------------------------------------------------
> > This sf.net email is sponsored by:ThinkGeek
> > Welcome to geek heaven.
> > http://thinkgeek.com/sf
> > _______________________________________________
> > Mockobjects-java-users mailing list
> > Moc...@li...
> > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-users
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Mockobjects-java-users mailing list
> Moc...@li...
> https://lists.sourceforge.net/lists/listinfo/mockobjects-java-users
--
Jeff Martin <je...@mk...>
|