Status: Open (View Workflow)
Affects Version/s: 2.2.0.GA
Fix Version/s: None
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())
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.