3 Replies Latest reply on Aug 12, 2008 7:14 PM by Stan Silvert

    Invalidating Session breaks JSFUnit Test Case

    Dan Le Newbie

      One of my test cases verifies the logout behavior of our application, which invalidates the session and redirects the user back to the login screen. Problem is, when I invalidate the session, I get the following exception thrown:

      com.meterware.httpunit.HttpInternalErrorException: Error on HTTP request: 500 Internal Error
      at com.meterware.httpunit.WebClient.validateHeaders(WebClient.java:573)
      at com.meterware.httpunit.WebClient.updateClient(WebClient.java:464)
      at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:139)
      at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:130)
      at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:121)
      at com.meterware.httpunit.WebClient.getResponse(WebClient.java:113)

      Even if I set the HttpUnitOptions to not thrown exceptions on errors, I am still left with a null FacesContext and can't continue the test. Am I doing something incorrectly? or is there a workaround for this problem? Thanks.

        • 1. Re: Invalidating Session breaks JSFUnit Test Case
          Stan Silvert Master

          I'm pretty sure this is a bug in JSFUnit. The problem is that JSFUnit uses the HttpSession as a conduit for passing the FacesContext to JUnit. When you blow the session away with invalidate(), JSFUnit will break.

          If you change your code to clear the session instead of invalidating it, then it will probably work.

          for (Enumeration e = session.getAttributeNames(); e.hasMoreElements();)

          However this is not a long term solution, so I've opened the following jira task:

          Under the covers, I could easily make HttpSession.invalidate() clear the session during a JSFUnit test. But clearing the session is not exactly the same thing as invalidating it. I'm wondering if that solution would break developers' tests that wanted to be strict about making sure that the HttpSession is blown away.

          Any thoughts?


          • 2. Re: Invalidating Session breaks JSFUnit Test Case
            Dan Le Newbie

            Thanks for the quick reply Stan.

            If JSFUnit were to clear the session for HttpSession.invalidate() under the covers as you say, for our purposes, it would be adequate in covering our test case, without breaking it.

            In our own code, I would be more comfortable invalidating the session, than merely clearing it.

            • 3. Re: Invalidating Session breaks JSFUnit Test Case
              Stan Silvert Master

              It's now fixed. If you want to try it out you can build from subversion. Or you can wait a couple of weeks for Beta 3.