JSFUnit and HttpSession
jkva Sep 7, 2007 6:24 PMHi,
I am trying JSFUnit and it is actually very nice. I have already tested some navigation rules and a bit of logic. However I think I have ran into something that is not yet supported (or I am doing something horribly wrong :-) ).
My test application has a simple login screen, followed by a dummy landing page, which contains the name of the user that just logged in. It also contains a back button to go back to page 1.
The problem is that session scoped variables (Managed Beans, SessionMap) are not stored for later use. This results in null values on later pages.
For example, the username of the logged in user is shown on the first page after login, but when I try to retrieve it, another request later, it is null.
The same is true for component tree variables, like the rendered attribute (rendered="#{sessionScopedBean.loggedIn}") I use in my test cases.
Is this a fault of JSFUnit, Cactus, HttpUnit, or me?
Below: A session test script and my cactus.properties. If necessary, I'll post my beans and JSP's...
cactus.properties:
cactus.contextURL=http://localhost:8080/jsfunittest cactus.servletRedirectorName=JSFUnitRedirector
Test script:
public class SessionTest extends ServletTestCase{ private ClientFacade client; private ServerFacade server; protected void setUp() throws Exception { super.setUp(); client = new ClientFacade("/login.faces"); server = new ServerFacade(); } public void testInitialPage() throws IOException, SAXException { FacesContext facesContext = FacesContextBridge.getCurrentInstance(); assertEquals("/login.jsp", server.getCurrentViewId()); server.getFacesContext().getExternalContext().getSessionMap().put("var", "value"); } public void testNavigation() throws IOException, SAXException { WebForm form = client.getForm(); form.setParameter("form:username", "user"); form.setParameter("form:password", "pass"); client.submit(); assertEquals("/loggedin.jsp", server.getCurrentViewId()); String var = (String)server.getFacesContext().getExternalContext().getSessionMap().get("var"); System.out.println(var); assertEquals("value", var); } }