[seam-commits] Seam SVN: r14073 - in branches/enterprise/JBPAPP_5_0/src/test/ftest: examples and 2 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Apr 7 05:59:45 EDT 2011


Author: mgencur at redhat.com
Date: 2011-04-07 05:59:45 -0400 (Thu, 07 Apr 2011)
New Revision: 14073

Added:
   branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/booking/jboss5-cluster-booking.xml
   branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/booking/jboss5-cluster-slink.xml
   branches/enterprise/JBPAPP_5_0/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/selenium/SLinkTest.java
Removed:
   branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/booking/jboss5cluster.xml
Modified:
   branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/build.xml
   branches/enterprise/JBPAPP_5_0/src/test/ftest/readme.txt
Log:
add slink test for booking in cluster

Added: branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/booking/jboss5-cluster-booking.xml
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/booking/jboss5-cluster-booking.xml	                        (rev 0)
+++ branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/booking/jboss5-cluster-booking.xml	2011-04-07 09:59:45 UTC (rev 14073)
@@ -0,0 +1,26 @@
+<!--
+		JBoss, Home of Professional Open Source Copyright 2008, Red Hat
+		Middleware LLC, and individual contributors by the @authors tag. See
+		the copyright.txt 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.
+--> 
+<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
+<suite name="Booking example" verbose="2" parallel="false">
+	<test name="booking_jboss5_cluster">
+		<parameter name="PROPERTY_FILE"
+			value="/org/jboss/seam/example/booking/test/selenium/booking.properties" />
+		<classes>
+			<class name="org.jboss.seam.example.common.test.booking.cluster.selenium.FailoverTest" />
+		</classes>
+	</test>
+</suite>

Added: branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/booking/jboss5-cluster-slink.xml
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/booking/jboss5-cluster-slink.xml	                        (rev 0)
+++ branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/booking/jboss5-cluster-slink.xml	2011-04-07 09:59:45 UTC (rev 14073)
@@ -0,0 +1,26 @@
+<!--
+		JBoss, Home of Professional Open Source Copyright 2008, Red Hat
+		Middleware LLC, and individual contributors by the @authors tag. See
+		the copyright.txt 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.
+--> 
+<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
+<suite name="Booking example" verbose="2" parallel="false">
+	<test name="booking_jboss5_cluster">
+		<parameter name="PROPERTY_FILE"
+			value="/org/jboss/seam/example/booking/test/selenium/booking.properties" />
+		<classes>
+			<class name="org.jboss.seam.example.common.test.booking.cluster.selenium.SLinkTest" />
+		</classes>
+	</test>
+</suite>

Deleted: branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/booking/jboss5cluster.xml
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/booking/jboss5cluster.xml	2011-04-05 14:47:22 UTC (rev 14072)
+++ branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/booking/jboss5cluster.xml	2011-04-07 09:59:45 UTC (rev 14073)
@@ -1,26 +0,0 @@
-<!--
-		JBoss, Home of Professional Open Source Copyright 2008, Red Hat
-		Middleware LLC, and individual contributors by the @authors tag. See
-		the copyright.txt 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.
---> 
-<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
-<suite name="Booking example" verbose="2" parallel="false">
-	<test name="booking_jboss5_cluster">
-		<parameter name="PROPERTY_FILE"
-			value="/org/jboss/seam/example/booking/test/selenium/booking.properties" />
-		<classes>
-			<class name="org.jboss.seam.example.common.test.booking.cluster.selenium.FailoverTest" />
-		</classes>
-	</test>
-</suite>

Modified: branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/build.xml
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/build.xml	2011-04-05 14:47:22 UTC (rev 14072)
+++ branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/build.xml	2011-04-07 09:59:45 UTC (rev 14073)
@@ -99,14 +99,21 @@
 	<target name="selenium.test" depends="build, container.properties" description="Run Tests">
 		<taskdef resource="testngtasks" classpathref="classpath.test" />
 		<mkdir dir="${test.output.dir}" />
-		
-		<condition property="clusterxml" value="cluster">
-		      <equals arg1="${cluster}" arg2="true"/>
+		<condition property="clusterxml" value="-cluster-booking">
+			<equals arg1="${test-booking}" arg2="true"/>
 		</condition>
+		<condition property="clusterxml" value="-cluster-slink">
+			<equals arg1="${test-slink}" arg2="true"/>
+		</condition>
 		<condition property="clusterxml" value="">
-			  <not>
-			  	<equals arg1="${cluster}" arg2="true"/>
-			  </not>				
+			<and>
+				<not>
+					<equals arg1="${cluster-booking}" arg2="true"/>
+				</not>
+				<not>
+					<equals arg1="${cluster-slink}" arg2="true"/>
+				</not>
+			</and>
 		</condition>
 		<!-- execute testng tests -->
 		<testng haltonfailure="false" outputdir="${test.output.dir}" classpathref="classpath.test" listener="${functional.listener}">

Modified: branches/enterprise/JBPAPP_5_0/src/test/ftest/readme.txt
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/ftest/readme.txt	2011-04-05 14:47:22 UTC (rev 14072)
+++ branches/enterprise/JBPAPP_5_0/src/test/ftest/readme.txt	2011-04-07 09:59:45 UTC (rev 14073)
@@ -55,9 +55,17 @@
 * jboss.service.binding.set=ports-default) and the application is deployed to server/all/farm 
 * directory at "jboss5.home" location specified in ftest.properties
  
-To run cluster test for booking example:
-ant test -Dtest=booking -Dcluster=true
+There are two cluster tests for the Booking application in the distribution. Before running any of them, you have
+to start both (master and slave) JBoss AS instances manually.
+ 
+1) simple booking with failover
 
+    ant test -Dtest=booking -Dcluster=true -Dtest-booking=true
+
+2) s:link test after failover
+    
+    ant test -Dtest=booking -Dcluster=true -Dtest-slink=true
+
 Known Limitations:
 ---------------------
 * Only tested on Firefox and IE

Added: branches/enterprise/JBPAPP_5_0/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/selenium/SLinkTest.java
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/selenium/SLinkTest.java	                        (rev 0)
+++ branches/enterprise/JBPAPP_5_0/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/selenium/SLinkTest.java	2011-04-07 09:59:45 UTC (rev 14073)
@@ -0,0 +1,256 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.seam.example.common.test.booking.cluster.selenium;
+
+import java.io.IOException;
+import java.text.MessageFormat;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import static org.testng.AssertJUnit.*;
+
+import org.jboss.seam.example.common.test.selenium.SeamSelenium;
+import org.jboss.seam.example.common.test.selenium.SeamSeleniumTest;
+
+import com.thoughtworks.selenium.Wait;
+
+/**
+ * This class tests functionality of an s:link component in cluster. 
+ * Two instances of JBoss AS are used. First part of the test is executed at first 
+ * (master) instance. Then the first instance is killed and the second (slave) instance
+ * takes over execution of the application. This behavior simulates recovery from breakdown.
+ * 
+ * @author mgencur
+ * 
+ */
+public class SLinkTest extends SeamSeleniumTest 
+{
+    private final String HOTEL_NAME = "W Hotel";
+    private final String DEFAULT_USERNAME = "demo";
+    private final String DEFAULT_PASSWORD = "demo";
+//    private final String EXPECTED_NAME = "Demo User";
+//    private final String CREDIT_CARD = "0123456789012345";
+//    private final String CREDIT_CARD_NAME = "visa";
+    private final long JBOSS_SHUTDOWN_TIMEOUT = 20000;
+    private final int SECOND_BROWSER_PORT = 8180;
+    private final String SECOND_INSTANCE_BROWSER_URL = "http://localhost:" + SECOND_BROWSER_PORT;
+       
+    private SeamSelenium browser2;
+    
+    @Override
+    @BeforeMethod
+    public void setUp() 
+    {
+        super.setUp();        
+        deleteCookies(browser);
+        browser2 = startSecondBrowser();
+        deleteCookies(browser2);
+        assertTrue("Login failed.", login(browser));
+    }
+
+    @Override
+    @AfterMethod
+    public void tearDown() 
+    {
+        logout(browser2);
+        super.tearDown();
+        stopSecondBrowser();
+    }    
+    
+    /**
+     * Test s:link functionality with failover
+     */
+    @Test
+    public void testSLinkFunctionality() 
+    {        
+        preFailurePart(browser);
+        
+        String newAddress = getAddressForSecondInstance(browser);
+        
+        shutdownMasterJBossInstance();     
+                              
+        postFailurePart(browser2, newAddress);
+    }
+    
+    public void shutdownMasterJBossInstance()
+    {
+      String command = JBOSS_HOME + "/bin/shutdown.sh -s localhost:1099 -S";
+      try
+      {
+         Process process = Runtime.getRuntime().exec(command);
+         process.waitFor();
+         Thread.sleep(JBOSS_SHUTDOWN_TIMEOUT);
+      }
+      catch (IOException e)
+      {
+         throw new RuntimeException(e.getCause());
+      }
+      catch (InterruptedException e)
+      {
+      }
+    }
+
+    public void preFailurePart(SeamSelenium browser)
+    {
+      if (!isLoggedIn(browser))
+          fail();
+      if (!browser.isElementPresent(getProperty("SEARCH_SUBMIT"))) 
+      {
+          browser.open(CONTEXT_PATH + getProperty("MAIN_PAGE"));
+          browser.waitForPageToLoad(TIMEOUT);
+      }
+      enterSearchQueryUsingAJAX(browser, HOTEL_NAME);
+      browser.clickAndWait(getProperty("SEARCH_RESULT_TABLE_FIRST_ROW_LINK"));  //s:link
+      assertTrue(browser.isTextPresent(HOTEL_NAME));
+      assertTrue(browser.isElementPresent(getProperty("BOOKING_BOOK")));
+      browser.goBackAndWait();
+      assertTrue(browser.isElementPresent(getProperty("SEARCH_SUBMIT")));
+    }
+    
+    
+    public void postFailurePart(SeamSelenium browser, String newAddress)
+    {
+      browser2.open(newAddress);
+      
+      //a jsessionid cookie has to be deleted because at this moment there already exists one
+      deleteCookies(browser);
+      
+      browser2.clickAndWait(getProperty("SEARCH_SUBMIT"));
+      browser2.clickAndWait(getProperty("SEARCH_RESULT_TABLE_FIRST_ROW_LINK"));  //s:link
+      assertTrue(browser.isTextPresent(HOTEL_NAME));
+      assertTrue(browser.isElementPresent(getProperty("BOOKING_BOOK")));
+    }
+    
+    public SeamSelenium startSecondBrowser() 
+    {
+       BROWSER_URL = SECOND_INSTANCE_BROWSER_URL;
+       return super.startBrowser();
+    }    
+    
+    public void stopSecondBrowser()
+    {
+       browser2.stop();
+    }
+    
+    public String getAddressForSecondInstance(SeamSelenium browser)
+    {
+       String[] parsedStrings = browser.getLocation().split("/");
+       StringBuilder sb = new StringBuilder();
+       for (int i = 3; i != parsedStrings.length; i++){
+          sb.append("/").append(parsedStrings[i]);
+       }      
+       String sid = browser.getCookieByName("JSESSIONID");
+       String newAddress = sb.toString();
+       String firstPart = newAddress.substring(0, newAddress.indexOf("?"));
+       String secondPart = newAddress.substring(newAddress.indexOf("?") , newAddress.length());
+
+       newAddress = firstPart + ";jsessionid=" + sid + secondPart;
+    
+       return newAddress;      
+    }
+    
+    private void deleteCookies(SeamSelenium browser)
+    {
+       browser.deleteCookie("JSESSIONID", "path=" + CONTEXT_PATH + ", domain=localhost, recurse=true");
+    }     
+   
+    public boolean login(SeamSelenium browser) 
+    {
+        return login(browser, DEFAULT_USERNAME, DEFAULT_PASSWORD);
+    }
+   
+    public boolean login(SeamSelenium browser, String username, String password) 
+    {
+         if (isLoggedIn(browser)) 
+         {
+             fail("User already logged in.");
+         }
+         
+         browser.open(CONTEXT_PATH + getProperty("HOME_PAGE"));
+         browser.waitForPageToLoad(TIMEOUT);
+         
+         if (!browser.getTitle().equals(getProperty("PAGE_TITLE"))) 
+         {
+             return false;
+         }
+         
+         browser.type(getProperty("LOGIN_USERNAME_FIELD"), username);
+         browser.type(getProperty("LOGIN_PASSWORD_FIELD"), password);
+         browser.click(getProperty("LOGIN_SUBMIT"));
+         browser.waitForPageToLoad(TIMEOUT);
+         
+         return isLoggedIn(browser);
+    }
+   
+    public void logout(SeamSelenium browser) 
+    {
+        if (isLoggedIn(browser)) 
+        {
+             browser.click(getProperty("LOGOUT"));
+             browser.waitForPageToLoad(TIMEOUT);
+        }
+    }
+   
+    public boolean isLoggedIn(SeamSelenium browser) 
+    {
+        return browser.isElementPresent(getProperty("LOGOUT"));
+    }    
+   
+    public void enterSearchQueryUsingAJAX(final SeamSelenium browser, String query) 
+    {
+       browser.type(getProperty("SEARCH_STRING_FIELD"), "");
+       browser.type(getProperty("SEARCH_STRING_FIELD"), query.substring(0, query.length() - 1));
+       browser.typeKeys(getProperty("SEARCH_STRING_FIELD"), query.substring(query.length() - 1));
+       
+       browser.click(getProperty("SEARCH_SUBMIT"));
+      
+       // wait for javascript to show spinner
+       try 
+       {
+           Thread.sleep(1000);
+       } 
+       catch (InterruptedException e)
+       {
+       }
+       
+       // wait for page to get updated
+       new Wait() 
+       {
+           @Override
+           public boolean until() 
+           {
+               return !browser.isVisible(getProperty("SPINNER"));
+           }
+       }.wait("Spinner hasn't come out.");
+       
+       new Wait() 
+       {
+           @Override
+           public boolean until() 
+           {
+               return (browser.isElementPresent(getProperty("SEARCH_RESULT_TABLE")) || 
+                       browser.isElementPresent(getProperty("NO_HOTELS_FOUND")));
+           }
+       }.wait("Search results not found.");
+    }    
+}



More information about the seam-commits mailing list