Uploaded image for project: 'Seam 2'
  1. Seam 2
  2. JBSEAM-4728

NPE involving o.j.s.mock.AbstractSeamTest.Request.init() and o.j.s.ui.facelet.RendererRequest.cleanup()

    Details

    • Steps to Reproduce:
      Hide

      Simply create and method that calls

      Renderer.instance().render("mail.xhtml") twice and write a test that invoke this method.

      Show
      Simply create and method that calls Renderer.instance().render("mail.xhtml") twice and write a test that invoke this method.
    • Estimated Difficulty:
      High

      Description

      I'm trying to come up with a solution to integrate Wiser (http://code.google.com/p/subethasmtp/wiki/Wiser) and Seam Mail (so that I can create tests asserting that the e-mail is actually sent) but I stumbled into a problem.

      Seam Mail uses the "o.j.s.ui.facelet.RendererRequest" which sets up some mock objects to be able to render a XHTML in a String and send the e-mail.
      This works fine in production, I can call it several times during a single request. It works like a charm.

      The problems happens when trying to test the given method using SeamTest and its infrastructure.

      What happens is, during o.j.s.mock.AbstractSeamTest.Request.init() it creates a new MockFacesContext and saves it so that whenever you call FacesContext.getInstance() or MockFacesContextFactory.getFacesContext() this same instance will be returned.

      That's ok... for now.

      Things get messier now.

      Below code is extracted from RendererRequest.init()
      .....
      originalFacesContext = FacesContext.getCurrentInstance();
      facesContext = RendererFacesContextFactory.instance().getFacesContext(request, response);
      ....

      Problem here is that, due to AbstractSeamTest.Request.init() 'originalFacesContext == facesContext' and when RendererRequest.cleanup() is eventually called 'facesContext.release()' what happens is:

      (Extracted from MockFacesContext.release())
      setCurrentInstance(null);
      MockFacesContextFactory.setFacesContext(null);

      The next time someone calls MockFacesContext.getInstance() or MockFacesContextFactory.getFacesContext() they will return null and eventually this will result in a NPE.

      Which is exactly what happens with me due to the fact that I call "Renderer.instance().render("mail.xhtml")" multiple times inside a method.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                pmuir Pete Muir
                Reporter:
                fr0w Flavio Costa
              • Votes:
                3 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated: