Author: ozizka(a)redhat.com
Date: 2009-03-09 19:30:26 -0400 (Mon, 09 Mar 2009)
New Revision: 196
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java
Log:
Multiple login test passes.
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-09
22:31:36 UTC (rev 195)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java 2009-03-09
23:30:26 UTC (rev 196)
@@ -25,11 +25,20 @@
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.html.*;
+import java.io.BufferedReader;
+import java.io.FileReader;
import java.io.IOException;
+import java.io.StringReader;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.apache.xerces.xni.parser.XMLDocumentFilter;
+import org.apache.xerces.xni.parser.XMLInputSource;
+import org.cyberneko.html.HTMLConfiguration;
+import org.cyberneko.html.filters.DefaultFilter;
+import org.cyberneko.html.filters.Writer;
import org.jboss.jsfunit.framework.WebClientSpec;
import org.jboss.jsfunit.framework.WebConversationFactory;
import org.jboss.jsfunit.jsfsession.JSFClientSession;
@@ -59,7 +68,8 @@
}
private static final String LABEL_LOGOUT = "Logout";
- public void setUp() throws IOException
+
+ public void XsetUp() throws IOException
{
// Announce this test in the JBoss log.
@@ -122,37 +132,30 @@
* Logs in using several
* @throws java.io.IOException
*
- * Fails because the page header is missing for some reason.
- * TODO: Find out why.
+ * PASSED.
*/
public void testMultipleUsersLogin() throws IOException
{
-
+
// USER A.
- log.info("Logging in with first user, '"+USER_A+"'");
- SessionInstance sessA = new SessionInstance(USER_A, PASS_A);
+ String pageText = client.getPageAsText();
+ assertTrue("Page doesn't contain user's name.",
pageText.contains(USER_A) );
+ assertTrue("Page doesn't contain '"+LABEL_LOGOUT+"'.",
pageText.contains(LABEL_LOGOUT) );
- //DebugUtils.writeFile("target/asd.html", sessA.client.getPageAsText());///
+ assertEquals("JSF's '#{identity.username}' should be the user
name.",
+ USER_A, server.getManagedBeanValue("#{identity.username}") );
+
- 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.getServer().getManagedBeanValue("#{identity.username}") );
- DebugUtils.writeFile("target/multiuser1.html",
sessA.getClient().getPageAsText());///
-
-
// USER B.
final WebClient wc = new WebClient(BrowserVersion.FIREFOX_3);
wc.setThrowExceptionOnFailingStatusCode(false);
wc.setConfirmHandler(new SimpleConfirmHandler(true));
final WebClientTools sessBclient = new WebClientTools(wc);
-
+
final String userNameComponent = "login_form:name";
final String passwordComponent = "login_form:password";
final String submitComponent = "login_form:submit";
@@ -163,30 +166,34 @@
setValue(loginPage, passwordComponent, PASS_B);
clickSubmitComponent(loginPage, submitComponent);
- assertTrue("Page doesn't contain user's name.",
- sessBclient.getPageAsText().contains(USER_B) );
- assertTrue("Page doesn't contain '"+LABEL_LOGOUT+"'.",
- sessBclient.getPageAsText().contains(LABEL_LOGOUT) );
+ String pageBText = new WebClientTools(wc).getResponseBodyAsText();
+ assertTrue("Page doesn't contain user's name.",
pageBText.contains(USER_B) );
+ assertTrue("Page doesn't contain '"+LABEL_LOGOUT+"'.",
pageBText.contains(LABEL_LOGOUT) );
// Refresh and log USER_A out.
- ((HtmlPage) sessA.getClient().getContentPage()).refresh();
- DebugUtils.writeFile("target/multiuser2.html",
sessA.getClient().getPageAsText());///
+ ((HtmlPage) client.getContentPage()).refresh();
+ byte[] responseBBody = client.getContentPage().getWebResponse().getResponseBody();
- HtmlAnchor logoutLink = (HtmlAnchor)
sessA.getClient().getElement("logoutLink");
+ HtmlAnchor logoutLink = (HtmlAnchor) client.getElement("logoutLink");
logoutLink.click();
// Refresh sessB page Check that USER_B is still logged in.
- assertTrue("Page doesn't contain user's name.",
- sessBclient.getPageAsText().contains(USER_B) );
- assertTrue("Page doesn't contain '"+LABEL_LOGOUT+"'.",
- sessBclient.getPageAsText().contains(LABEL_LOGOUT) );
+ ((HtmlPage) new WebClientTools(wc).getContentPage()).refresh();
+ String pageBText2 = new WebClientTools(wc).getResponseBodyAsText();
+ assertTrue("Page doesn't contain user's name.",
pageBText2.contains(USER_B) );
+ assertTrue("Page doesn't contain '"+LABEL_LOGOUT+"'.",
pageBText2.contains(LABEL_LOGOUT) );
}
+
+
+
+
+
// These were taken from FomrAuthenticationStrategy.java; unfortunately not reusable
from there.
protected Page clickSubmitComponent(HtmlPage page, String elementName) throws
IOException
Show replies by date