[seam-issues] [JBoss JIRA] (JBSEAM-4728) NPE involving o.j.s.mock.AbstractSeamTest.Request.init() and o.j.s.ui.facelet.RendererRequest.cleanup()
Dave Sunerton-Burl (JIRA)
jira-events at lists.jboss.org
Tue Oct 9 05:56:03 EDT 2012
[ https://issues.jboss.org/browse/JBSEAM-4728?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Dave Sunerton-Burl updated JBSEAM-4728:
---------------------------------------
Attachment: TestRenderer.java
I hit this problem and had to find a workaround very quickly. I've attached a class, which you can include in your test classes, that overrides (in a Seam component kind of way!) the normal Renderer. This class retains the FacesContext so you don't get the NPE on multiple calls to render() within a single test. It may be a bit of a dirty hack, but it works for me (using Seam 2.2.2.Final).
> NPE involving o.j.s.mock.AbstractSeamTest.Request.init() and o.j.s.ui.facelet.RendererRequest.cleanup()
> -------------------------------------------------------------------------------------------------------
>
> Key: JBSEAM-4728
> URL: https://issues.jboss.org/browse/JBSEAM-4728
> Project: Seam 2
> Issue Type: Bug
> Components: Mail, Test Harness
> Affects Versions: 2.2.0.GA
> Environment: java version "1.6.0_22"
> Seam 2.2.0.GA
> Reporter: Flavio Costa
> Assignee: Pete Muir
> Labels: faces, mail, mock, seam, wiser
> Attachments: TestRenderer.java
>
>
> 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.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the seam-issues
mailing list