JSFUnit logout test problem (spring-security ?!?)
stefanorg Mar 21, 2011 10:05 AMHi all,
i'm trying to do some base test for my application.
I've a secure login form (handled by spring-security) and i want to test login and logout. My problem is that when clicking in the logout button the application do nothing.
This is my code:
WebClientSpec wcSpec = new WebClientSpec("/pages/login.jsf",BrowserVersion.FIREFOX_3);
FormAuthenticationStrategy formAuth = new FormAuthenticationStrategy("amministratore", "test", "submitBtn");
wcSpec.setInitialRequestStrategy(formAuth);
JSFSession jsfSession = new JSFSession(wcSpec);
JSFClientSession client = jsfSession.getJSFClientSession();
HtmlAnchor logoutLink = (HtmlAnchor) client.getElement("logoutLink");
assertNotNull(logoutLink);
assertEquals(true, client.getContentPage().getWebResponse().getContentAsString().contains("amministratore"));
log.debug(client.getPageAsText());
assertEquals(true, client.getPageAsText().contains("amministratore"));
//the assertions before are true, loginBean.username has to be 'amministratore'
//but is null
//assertEquals("amministratore", server.getManagedBeanValue("#{loginBean.username}"));
HtmlAnchor link = (HtmlAnchor) client.getElement("logoutLink");
Page p = link.click();// <-- i can reach the following logout() action
log.debug("url dopo logout:"+p.getUrl());
When the event click is fired (link.click()) i'm able to reach the server side code that execute the logout action:
public String logout() throws IOException{
FacesContext fc = FacesContext.getCurrentInstance();
fc.getExternalContext().getSessionMap().put("loginBean", null);
HttpSession session = (HttpSession)fc.getExternalContext().getSession(false);
session.invalidate();
//id="j_spring_security_logout"
ExternalContext ec = fc.getExternalContext();
ec.dispatch("/logout"); // <-- It stops here
fc.responseComplete();
//return "login";
return null;
}
Another strange thing is that the server side check of managed bean doesn't work...
any idea?!?
Thanks