Author: ozizka(a)redhat.com
Date: 2009-03-05 18:24:39 -0500 (Thu, 05 Mar 2009)
New Revision: 187
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java
Log:
* Multiuser login test update
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java
===================================================================
---
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java 2009-03-05
23:09:10 UTC (rev 186)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java 2009-03-05
23:24:39 UTC (rev 187)
@@ -23,6 +23,9 @@
package org.jboss.jopr.jsfunit;
import com.gargoylesoftware.htmlunit.BrowserVersion;
+import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
+import com.gargoylesoftware.htmlunit.html.HtmlDivision;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.io.IOException;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -52,6 +55,7 @@
public static Test suite() {
return new TestSuite( MultipleUserLoginTest.class );
}
+ private static final String LABEL_LOGOUT = "Logout";
public void setUp() throws IOException
{
@@ -73,7 +77,7 @@
log.info("Detected AS version: " + version);
isJBoss4 = version.startsWith("4");
- // Contrary to super class, skip the session creation in setUp().
+ // Contrary to super class, this test skips the session creation in setUp().
}
@@ -82,8 +86,9 @@
*/
class SessionInstance {
- protected JSFClientSession client;
- protected JSFServerSession server;
+ protected JSFSession jsfSession;
+ protected JSFClientSession client_;
+ protected JSFServerSession server_;
protected String user;
protected String pass;
@@ -96,13 +101,15 @@
wcSpec.getWebClient().setThrowExceptionOnFailingStatusCode(false);
wcSpec.getWebClient().setConfirmHandler(new SimpleConfirmHandler(true));
wcSpec.setInitialRequestStrategy(new JoprLoginStrategy(user, pass)); // logs in
- JSFSession jsfSession = new JSFSession(wcSpec);
- this.client = jsfSession.getJSFClientSession();
- this.server = jsfSession.getJSFServerSession();
+ this.jsfSession = new JSFSession(wcSpec);
+ this.client_ = jsfSession.getJSFClientSession();
+ this.server_ = jsfSession.getJSFServerSession();
}
- public JSFClientSession getClient() { return client; }
- public JSFServerSession getServer() { return server; }
+ //public JSFClientSession getClient() { return this.client_; }
+ //public JSFServerSession getServer() { return this.server_; }
+ public JSFClientSession getClient() { return
this.jsfSession.getJSFClientSession(); }
+ public JSFServerSession getServer() { return
this.jsfSession.getJSFServerSession(); }
public String getUser() { return user; }
public String getPass() { return pass; }
@@ -112,6 +119,8 @@
/**
* Logs in using several
* @throws java.io.IOException
+ *
+ * Fails. TODO: Add user/pass for 2nd user.
*/
public void testMultipleUsersLogin() throws IOException
{
@@ -119,31 +128,66 @@
// USER A.
log.info("Logging in with first user, '"+USER_A+"'");
-
SessionInstance sessA = new SessionInstance(USER_A, PASS_A);
- assertTrue( sessA.client.getPageAsText().contains(USER_A) );
- assertTrue( sessA.client.getPageAsText().contains("Logout") );
+ //DebugUtils.writeFile("target/asd.html", sessA.client.getPageAsText());///
+
+ assertTrue("Page doesn't contain user's name.",
+ sessA.getClient().getPageAsText().contains(USER_A) );
+ assertTrue("Page doesn't contain '"+LABEL_LOGOUT+"'.",
+ sessA.getClient().getPageAsText().contains(LABEL_LOGOUT) );
+
assertEquals("JSF's '#{identity.username}' should be the user
name.",
- USER_A, sessA.server.getManagedBeanValue("#{identity.username}") );
+ USER_A, sessA.getServer().getManagedBeanValue("#{identity.username}") );
+ HtmlAnchor logoutLink_ = (HtmlAnchor)
sessA.getClient().getElement("logoutLink");
+
// USER B.
log.info("Logging in with second user, '"+USER_B+"'");
-
SessionInstance sessB = new SessionInstance(USER_B, PASS_B);
- assertTrue("Page doesn't contain user's name.",
sessB.client.getPageAsText().contains(USER_B) );
- assertTrue("Page doesn't contain 'Logout'.",
sessB.client.getPageAsText().contains("Logout") );
+ assertTrue("Page doesn't contain user's name.",
+ sessB.getClient().getPageAsText().contains(USER_B) );
+ assertTrue("Page doesn't contain '"+LABEL_LOGOUT+"'.",
+ sessB.getClient().getPageAsText().contains(LABEL_LOGOUT) );
+
assertEquals("JSF's '#{identity.username}' should be the user
name.",
- USER_B, sessB.server.getManagedBeanValue("#{identity.username}") );
+ USER_B, sessB.getServer().getManagedBeanValue("#{identity.username}") );
+
+ // Log USER_A out.
+
+ /*HtmlDivision headerDiv =
(HtmlDivision)sessA.getClient().getElement("pageheader");
+ HtmlAnchor logoutLink = (HtmlAnchor) headerDiv
+ .getByXPath("a[normalize-string() =
'"+LABEL_LOGOUT+"']"); /**/
+
+ HtmlAnchor logoutLink = (HtmlAnchor)
sessA.getClient().getElement("logoutLink");
+ logoutLink.click();
+
+
+ // Refresh sessB page Check that USER_B is still logged in.
+
+ HtmlPage page = (HtmlPage) sessB.getClient().getContentPage();
+ page.refresh();
+
+ assertTrue("Page doesn't contain user's name.",
+ sessB.getClient().getPageAsText().contains(USER_B) );
+ assertTrue("Page doesn't contain '"+LABEL_LOGOUT+"'.",
+ sessB.getClient().getPageAsText().contains(LABEL_LOGOUT) );
+
+ assertEquals("JSF's '#{identity.username}' should be the user
name.",
+ USER_B, sessB.getServer().getManagedBeanValue("#{identity.username}") );
+
}
-}
\ No newline at end of file
+}// class
+
+
+
Show replies by date