-
1. How to replace a Managed Bean on-fly?
ssilvert Mar 4, 2011 12:16 PM (in response to yegor256)I think this is the wrong approach. I doubt that you will ever get it to work that way even though if you could it might be a little cleaner than what I'm about to suggest.
Instead, add a ServletContextListener to your test WAR. The SCL would set up your mock authenticator. If you are using a Servlet 3.0 contianer then you could put this in its own jar and declare it with a web-fragment.xml. That would be a pretty clean way of doing it. You just include that jar when you are testing.
Stan
-
2. Re: How to replace a Managed Bean on-fly?
yegor256 Mar 4, 2011 12:44 PM (in response to ssilvert)Hm.. I have an impression that JSFUnit is going to let me control my context entirely, including getting and setting managed beans (and their properties). Isn't it true? If I have to deal directly with Servlets why would I need JSFUnit on top of HttpUnit than?
Are you sure that I can't do what I'm trying to do with JSFUnit only?
-
3. How to replace a Managed Bean on-fly?
ssilvert Mar 4, 2011 12:51 PM (in response to yegor256)I thought of another way. Use an InitialRequestStrategy. From an InitialRequestStrategy, the only server-side artifact you can get to is the HttpSession. You can get that via WebConversationFactory.getSessionFromThreadLocal(). From there you can call HttpSession.getServletContext().setAttribute() to insert your Mock.
Make sure you do this within the InitialRequestStrategy. You want this to happen before the call to new JSFSession().
Stan
-
4. How to replace a Managed Bean on-fly?
yegor256 Mar 13, 2011 11:51 AM (in response to yegor256)Stan, many thanks. Now it works perfectly: http://trac.fazend.com/rempl/browser/rempl/trunk/rempl/rempl-oss/src/test/java/com/rempl/oss/helpers/HomeXhtmlTest.java?rev=604&marks=36-59