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

    Invalidating Session breaks JSFUnit Test Case

    danule

      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
          ssilvert

          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();)
           {
           session.removeAttribute((String)e.nextElement());
           }


          However this is not a long term solution, so I've opened the following jira task:
          https://jira.jboss.org/jira/browse/JSFUNIT-155

          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?

          Stan

          • 2. Re: Invalidating Session breaks JSFUnit Test Case
            danule

            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
              ssilvert

              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.

              Stan