From: Jeff D. <Jef...@no...> - 2003-04-30 22:47:10
|
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. |
From: Jeff D. <Jef...@no...> - 2003-04-30 23:55:13
|
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 |
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...> |
From: Jeff D. <Jef...@no...> - 2003-05-01 19:46:29
|
Jeff, thanks for the changes. Now, I have a whole bunch of questions, and comments. I'm breaking them into several emails. Comments on the Build process. Here is a summary of what I've tried to do. I checked out the current code out of source control. It took a while to figure while why the said build said it work, but I had no jar file. The ant build is successful even when the j2ee.jar file is missing. I think it should fail, because otherwise you end up searching all over the place to figure out what is wrong. I also would have preferred to see the j2ee.jar included in CVS, so when I check out the project I have everything that I need to build the current head. Is there a legal reason you don't include the various version j2ee.jar in the lib folder in CVS? I see little point having the Python script to build a Java project. I'd much rather this function be included into the Ant build.xml. Or I'd even accept the use something like Maven, if it would make easy to support. Regards, Jeff Duska |
From: Jeff M. <je...@mk...> - 2003-05-02 08:47:11
|
On Thu, 2003-05-01 at 20:59, Jeff Duska wrote: > Jeff, thanks for the changes. > > Now, I have a whole bunch of questions, and comments. I'm breaking them into > several emails. > > Comments on the Build process. > Here is a summary of what I've tried to do. I checked out the current code out > of source control. It took a while to figure while why the said build said it > work, but I had no jar file. The ant build is successful even when the j2ee.jar > file is missing. I think it should fail, because otherwise you end up searching > all over the place to figure out what is wrong. May be we should make the lack of j2ee.jar (and the fact that the mocks j2ee mocks won't be built) more obvious but the build should not fail as the j2ee mocks are optional. > I also would have preferred to > see the j2ee.jar included in CVS, so when I check out the project I have > everything that I need to build the current head. Is there a legal reason you > don't include the various version j2ee.jar in the lib folder in CVS? Not totally sure what the j2ee license is, but as far as I know it's not like other sun jars it's not freely distributable. Also since there are different version of the j2ee api there is no single version of the jar to include. > I see > little point having the Python script to build a Java project. I'd much rather > this function be included into the Ant build.xml. Or I'd even accept the use > something like Maven, if it would make easy to support. The pythong script is just a convinentent wrapped around the ant build script which allows me to test the build against different combinations of JDK and J2EE. If you know of a way to do this in ant/maven/gump/whatever and are willing to replace the python script I'd be happy to include it. Normal build process is just to type "ant" ;) > > Regards, > > Jeff Duska > > > > ------------------------------------------------------- > 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...> |