[embjopr-commits] EMBJOPR SVN: r177 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit.
embjopr-commits at lists.jboss.org
embjopr-commits at lists.jboss.org
Thu Mar 5 13:37:15 EST 2009
Author: ozizka at redhat.com
Date: 2009-03-05 13:37:15 -0500 (Thu, 05 Mar 2009)
New Revision: 177
Added:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java
Log:
* Multiple login test; JBQA-1939
Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java 2009-03-05 18:37:15 UTC (rev 177)
@@ -0,0 +1,149 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jopr.jsfunit;
+
+import com.gargoylesoftware.htmlunit.BrowserVersion;
+import java.io.IOException;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.jboss.jsfunit.framework.WebClientSpec;
+import org.jboss.jsfunit.jsfsession.JSFClientSession;
+import org.jboss.jsfunit.jsfsession.JSFServerSession;
+import org.jboss.jsfunit.jsfsession.JSFSession;
+
+/**
+ * Test of multiple user parallel login.
+ *
+ * @author Ondrej Zizka
+ */
+public class MultipleUserLoginTest extends EmbjoprTestCase
+{
+
+ // Credentials
+ private static final String USER_A = "admin";
+ private static final String PASS_A = "admin";
+ private static final String USER_B = "admin2";
+ private static final String PASS_B = "admin2";
+
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite() {
+ return new TestSuite( MultipleUserLoginTest.class );
+ }
+
+ public void setUp() throws IOException
+ {
+
+ // Announce this test in the JBoss log.
+ log.info("========================================================================================");
+ log.info(" Setting up test "+this.getClass().getName()+"#"+this.getName());
+ log.info("========================================================================================");
+
+
+ // JVM version
+ log.info("Java version: "+System.getProperty("java.version") + "," +
+ " vendor: " +System.getProperty("java.vendor"));
+ log.info("Java home: " +System.getProperty("java.home"));
+
+ // JBoss AS version
+ String version = Package.getPackage("org.jboss.system.server")
+ .getImplementationVersion();
+ log.info("Detected AS version: " + version);
+ isJBoss4 = version.startsWith("4");
+
+ // Contrary to super class, skip the session creation in setUp().
+
+ }
+
+ /**
+ * Instance of JSF session. Keeps server and client session parts, and user's name and pass.
+ */
+ class SessionInstance {
+
+ protected JSFClientSession client;
+ protected JSFServerSession server;
+ protected String user;
+ protected String pass;
+
+ /** Creates new JSF session, using JoprLoginStrategy. */
+ public SessionInstance(String user, String pass) throws IOException {
+
+ // Code taken from EmbJoprTestCase.java.
+ // Initial JSF request
+ WebClientSpec wcSpec = new WebClientSpec("/", BrowserVersion.FIREFOX_3);
+ 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();
+ }
+
+ public JSFClientSession getClient() { return client; }
+ public JSFServerSession getServer() { return server; }
+ public String getUser() { return user; }
+ public String getPass() { return pass; }
+
+ }
+
+
+ /**
+ * Logs in using several
+ * @throws java.io.IOException
+ */
+ public void testMultipleUsersLogin() throws IOException
+ {
+
+ // 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") );
+
+ assertEquals("JSF's '#{identity.username}' should be the user name.",
+ USER_A, sessA.server.getManagedBeanValue("#{identity.username}") );
+
+
+ // 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") );
+
+ assertEquals("JSF's '#{identity.username}' should be the user name.",
+ USER_B, sessB.server.getManagedBeanValue("#{identity.username}") );
+
+ }
+
+
+
+
+}
\ No newline at end of file
More information about the embjopr-commits
mailing list