You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mf...@apache.org on 2010/07/12 11:36:19 UTC

svn commit: r963221 - /myfaces/portlet-bridge/tck/trunk_2.0.x/src/test/java/org/apache/myfaces/portlet/faces/tckharness/TckTestCase.java

Author: mfreedman
Date: Mon Jul 12 09:36:18 2010
New Revision: 963221

URL: http://svn.apache.org/viewvc?rev=963221&view=rev
Log:
Merged changes from 301 version, mainly exclusion file support and formatting changes.

Modified:
    myfaces/portlet-bridge/tck/trunk_2.0.x/src/test/java/org/apache/myfaces/portlet/faces/tckharness/TckTestCase.java

Modified: myfaces/portlet-bridge/tck/trunk_2.0.x/src/test/java/org/apache/myfaces/portlet/faces/tckharness/TckTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/tck/trunk_2.0.x/src/test/java/org/apache/myfaces/portlet/faces/tckharness/TckTestCase.java?rev=963221&r1=963220&r2=963221&view=diff
==============================================================================
--- myfaces/portlet-bridge/tck/trunk_2.0.x/src/test/java/org/apache/myfaces/portlet/faces/tckharness/TckTestCase.java (original)
+++ myfaces/portlet-bridge/tck/trunk_2.0.x/src/test/java/org/apache/myfaces/portlet/faces/tckharness/TckTestCase.java Mon Jul 12 09:36:18 2010
@@ -57,46 +57,52 @@ public class TckTestCase
   private static String MAX_WAIT = "30000";
 
   protected static Selenium sSelenium;
-  
+
   private String mPageName, mTestName;
 
-  private static final String TEST_RESULT_NAME_XPATH
-    = "//span[@id=\"{0}-test-name\"]";
-  private static final String TEST_RESULT_STATUS_XPATH
-    = "//span[@id=\"{0}-result-status\"]";
-  private static final String TEST_RESULT_DETAIL_XPATH
-    = "//span[@id=\"{0}-result-detail\"]";
-
-  private static final String[] ACTION_XPATHS
-    = {"//input[@type=\"submit\" and @value=\"Run Test\"]",
-       "//a[text()=\"Run Test\"]"};
-
-  private static final String TEST_PASSED_XPATH
-    = "//span[@id=\"{0}-result-status\" and text()=\"SUCCESS\"]";
-  private static final String TEST_FAILED_XPATH
-    = "//span[@id=\"{0}-result-status\" and text()=\"FAILED\"]";
+  private static final String TEST_RESULT_NAME_XPATH = 
+    "//span[@id=\"{0}-test-name\"]";
+  private static final String TEST_RESULT_STATUS_XPATH = 
+    "//span[@id=\"{0}-result-status\"]";
+  private static final String TEST_RESULT_DETAIL_XPATH = 
+    "//span[@id=\"{0}-result-detail\"]";
+
+  private static final String[] ACTION_XPATHS =
+  { "//input[@type=\"submit\" and @value=\"Run Test\"]", 
+    "//a[text()=\"Run Test\"]" };
+
+  private static final String TEST_PASSED_XPATH = 
+    "//span[@id=\"{0}-result-status\" and text()=\"SUCCESS\"]";
+  private static final String TEST_FAILED_XPATH = 
+    "//span[@id=\"{0}-result-status\" and text()=\"FAILED\"]";
 
-  private static final String TCK_HOME = "BRIDGE_TCK_HOME";
+  private static final String TCK_HOME = "BRIDGE_301_TCK_HOME";
   private static final String PROPS_FILE = "bridge.tck.properties";
   private static final String LOGIN_FILE = "bridge.tck.login.properties";
   private static final String LOGIN_FILE_KEY = "bridge.tck.login.file";
 
-  private static final String CLIENT_BASE_URL_KEY = "bridge.tck.test.base-url";
+  private static final String CLIENT_BASE_URL_KEY = 
+    "bridge.tck.test.base-url";
   private static final String TEST_FILE_KEY = "bridge.tck.test.file";
   private static final String TEST_FILTER_KEY = "bridge.tck.test.filter";
+  private static final String TEST_EXCLUSIONS_FILE_KEY = 
+    "bridge.tck.test.exclusions.file";
   private static final String SELENIUM_BROWSER_KEY = "bridge.tck.browser";
-  private static final String SELENIUM_HOST_KEY = "bridge.tck.host";
-  private static final String SELENIUM_PORT_KEY = "bridge.tck.port";
+  private static final String SELENIUM_HOST_KEY = 
+    "bridge.tck.selenium.host";
+  private static final String SELENIUM_PORT_KEY = 
+    "bridge.tck.selenium.port";
 
   private static final String DEFAULT_SELENIUM_BROWSER = "*firefox";
   private static final String DEFAULT_SELENIUM_HOST = "localhost";
   private static final String DEFAULT_SELENIUM_PORT = "4444";
-  
+
   private static String sClientBaseUrl;
   private static String sTestFile;
+  private static String sTestExclusionsFile;
   private static String sTestFilter;
   private static String sSeleniumBrowser; // = DEFAULT_SELENIUM_BROWSER;
-  private static String sSeleniumHost;  // = DEFAULT_SELENIUM_HOST;
+  private static String sSeleniumHost; // = DEFAULT_SELENIUM_HOST;
   private static int sSeleniumPort; // = DEFAULT_SELENIUM_PORT;
 
   // Name value pairs for fields in login page
@@ -107,29 +113,25 @@ public class TckTestCase
 
   public static void log(String msg)
   {
-    //System.out.println(msg);
     Logger.getLogger("global").log(Level.INFO, msg);
   }
- 
+
   public static void errLog(String msg)
   {
-    // System.out.println("ERR: " + msg);
     Logger.getLogger("global").log(Level.SEVERE, msg);
   }
 
-  private static String getProperty(Properties fileProperties,
-                                    String key,
-                                    String defaultValue,
-                                    boolean required)
+  private static String getProperty(Properties fileProperties, String key, 
+                                    String defaultValue, boolean required)
   {
     boolean checkFirst = (defaultValue != null);
     if (System.getProperty(key) != null)
     {
       return System.getProperty(key);
     }
-    if (fileProperties != null &&  (String)fileProperties.get(key) != null)
+    if (fileProperties != null && (String) fileProperties.get(key) != null)
     {
-      return (String)fileProperties.get(key);
+      return (String) fileProperties.get(key);
     }
     if (defaultValue != null)
     {
@@ -143,15 +145,14 @@ public class TckTestCase
     return defaultValue;
   }
 
-  static
-  {
+  static {
     log("static block");
     String tckHomeDir = System.getenv(TCK_HOME);
     if (tckHomeDir == null)
     {
       // Default value for the TCK home.
-      tckHomeDir = System.getProperty("user.home")
-                   + File.separator + "BridgeTckHome";
+      tckHomeDir = 
+          System.getProperty("user.home") + File.separator + "BridgeTckHome";
     }
 
     File propsFile = new File(tckHomeDir, PROPS_FILE);
@@ -160,7 +161,7 @@ public class TckTestCase
     {
       log("Home dir: " + tckHomeDir);
       FileInputStream fis = null;
-      
+
       fis = new FileInputStream(propsFile);
       fileProps = new Properties();
       fileProps.load(fis);
@@ -177,14 +178,23 @@ public class TckTestCase
       System.exit(1);
     }
 
-    sClientBaseUrl = getProperty(fileProps, CLIENT_BASE_URL_KEY, null, true);
+    sClientBaseUrl = 
+        getProperty(fileProps, CLIENT_BASE_URL_KEY, null, true);
     sTestFilter = getProperty(fileProps, TEST_FILTER_KEY, null, false);
     sTestFile = getProperty(fileProps, TEST_FILE_KEY, null, true);
-  
-    sSeleniumHost = getProperty(fileProps, SELENIUM_HOST_KEY, DEFAULT_SELENIUM_HOST, false);
-    sSeleniumPort = Integer.parseInt(getProperty(fileProps, SELENIUM_PORT_KEY, DEFAULT_SELENIUM_PORT, false));
-    
-    sSeleniumBrowser = getProperty(fileProps, SELENIUM_BROWSER_KEY, DEFAULT_SELENIUM_BROWSER, false);
+    sTestExclusionsFile = 
+        getProperty(fileProps, TEST_EXCLUSIONS_FILE_KEY, null, true);
+
+    sSeleniumHost = 
+        getProperty(fileProps, SELENIUM_HOST_KEY, DEFAULT_SELENIUM_HOST, 
+                    false);
+    sSeleniumPort = 
+        Integer.parseInt(getProperty(fileProps, SELENIUM_PORT_KEY, 
+                                     DEFAULT_SELENIUM_PORT, false));
+
+    sSeleniumBrowser = 
+        getProperty(fileProps, SELENIUM_BROWSER_KEY, DEFAULT_SELENIUM_BROWSER, 
+                    false);
 
     // Login properties file
     try
@@ -205,7 +215,7 @@ public class TckTestCase
       Enumeration propsNameList = props.propertyNames();
       while (propsNameList.hasMoreElements())
       {
-        String loginProp = (String)propsNameList.nextElement();
+        String loginProp = (String) propsNameList.nextElement();
         if (props.get(loginProp).equals(""))
         {
           // A button login property is defined as name only
@@ -217,7 +227,8 @@ public class TckTestCase
           {
             sLoginFields = new ArrayList<String[]>();
           }
-          sLoginFields.add(new String[]{loginProp, (String)props.get(loginProp)});
+          sLoginFields.add(new String[]
+              { loginProp, (String) props.get(loginProp) });
         }
       }
     }
@@ -227,7 +238,8 @@ public class TckTestCase
     }
     catch (IOException ioe)
     {
-      errLog("Error loading login properties file, " + propsFile.getName());
+      errLog("Error loading login properties file, " + 
+             propsFile.getName());
       System.exit(1);
     }
 
@@ -235,16 +247,16 @@ public class TckTestCase
     log("test filter: " + sTestFilter);
     log("End of static block");
   }
- 
+
   public TckTestCase(String pageName, String testName)
   {
-    log("----- Constructor -------");
     mPageName = pageName;
     mTestName = testName;
   }
 
   @BeforeClass
-  public static void setUpSession() throws Exception
+  public static void setUpSession()
+    throws Exception
   {
     log("setUpSession");
     try
@@ -253,7 +265,9 @@ public class TckTestCase
       log("SeleniumPort: " + sSeleniumPort);
       log("SeleniumBrowser: " + sSeleniumBrowser);
       log("ClientBaseUrl: " + sClientBaseUrl);
-      sSelenium = new DefaultSelenium(sSeleniumHost, sSeleniumPort, sSeleniumBrowser, sClientBaseUrl);
+      sSelenium = 
+          new DefaultSelenium(sSeleniumHost, sSeleniumPort, sSeleniumBrowser, 
+                              sClientBaseUrl);
       sSelenium.start();
       sSelenium.setTimeout(MAX_WAIT);
     }
@@ -276,7 +290,8 @@ public class TckTestCase
   }
 
   @Before
-  public void runBeforeEachTest() throws Exception
+  public void runBeforeEachTest()
+    throws Exception
   {
     sSelenium.open(mPageName);
     sSelenium.waitForPageToLoad(MAX_WAIT);
@@ -284,7 +299,7 @@ public class TckTestCase
 
   @Test
   public void testPage()
-  { 
+  {
     login();
 
     performActions();
@@ -296,18 +311,24 @@ public class TckTestCase
     String bodyText = sSelenium.getBodyText();
     try
     {
-      testName = sSelenium.getText
-        (MessageFormat.format(TEST_RESULT_NAME_XPATH, new Object[]{mTestName}));
-      testStatus = sSelenium.getText
-        (MessageFormat.format(TEST_RESULT_STATUS_XPATH, new Object[]{mTestName}));
-      testDetails = sSelenium.getText
-        (MessageFormat.format(TEST_RESULT_DETAIL_XPATH, new Object[]{mTestName}));
+      testName = 
+          sSelenium.getText(MessageFormat.format(TEST_RESULT_NAME_XPATH, 
+                                                 new Object[]
+              { mTestName }));
+      testStatus = 
+          sSelenium.getText(MessageFormat.format(TEST_RESULT_STATUS_XPATH, 
+                                                 new Object[]
+              { mTestName }));
+      testDetails = 
+          sSelenium.getText(MessageFormat.format(TEST_RESULT_DETAIL_XPATH, 
+                                                 new Object[]
+              { mTestName }));
     }
     catch (SeleniumException se)
     {
       // If any of the tags are missing from the portlet content the full screen mark-up
       // will be returned.
-       failMsg = bodyText;
+      failMsg = bodyText;
     }
 
     if (failMsg == null)
@@ -315,13 +336,11 @@ public class TckTestCase
       if ("FAILED".equals(testStatus))
       {
         // The portlet content is valid but the test has failed so display details
-        failMsg = new StringBuilder()
-                    .append(testStatus)
-                    .append("\n")
-                    .append(testDetails).toString();
+        failMsg = 
+            new StringBuilder().append(testStatus).append("\n").append(testDetails).toString();
       }
     }
-    
+
     assertTrue(failMsg, "SUCCESS".equals(testStatus));
   }
 
@@ -342,28 +361,28 @@ public class TckTestCase
         }
       }
       actionsLeftToPerform = false;
-    }  
+    }
   }
 
   public void login()
   {
     if (sLoginFields != null)
     {
-       for (String[] field: sLoginFields)
-       {
-         if (!sSelenium.isElementPresent("//input[@name='" + field[0] + "']"))
-         {
-           // Not a login page
-           return;
-         }
-       }
-       for (String[] field: sLoginFields)
-       {
-         log("---- " + field[0] +  " ---- " + field[1] + " ----" + sLoginButton);
-         sSelenium.type(field[0], field[1]);
-       }
-       sSelenium.click(sLoginButton);
-       sSelenium.waitForPageToLoad(MAX_WAIT);
+      for (String[] field: sLoginFields)
+      {
+        if (!sSelenium.isElementPresent("//input[@name='" + field[0] + 
+                                        "']"))
+        {
+          // Not a login page
+          return;
+        }
+      }
+      for (String[] field: sLoginFields)
+      {
+        sSelenium.type(field[0], field[1]);
+      }
+      sSelenium.click(sLoginButton);
+      sSelenium.waitForPageToLoad(MAX_WAIT);
     }
   }
 
@@ -377,44 +396,83 @@ public class TckTestCase
   {
     log("testData()");
     List testList = new ArrayList<String[]>(200);
+    FileInputStream exIs = null;
+    FileInputStream tis = null;
+    Pattern filterPattern = null;
+
+    if ((sTestFilter != null) && (sTestFilter.length() > 0))
+    {
+      filterPattern = Pattern.compile(sTestFilter);
+    }
+
+    try
+    {
+      exIs = new FileInputStream(sTestExclusionsFile);
+    }
+    catch (Exception e)
+    {
+      errLog("Unable to acccess test exclusions file, " + 
+             sTestExclusionsFile + " Exception thrown: " + e.getMessage());
+      System.exit(1);
+    }
+    Properties exProps = new Properties();
+    try
+    {
+      exProps.loadFromXML(exIs);
+    }
+    catch (Exception e)
+    {
+      errLog("Unable to parse test exclusions file, " + 
+             sTestExclusionsFile + " Exception thrown: " + e.getMessage());
+      System.exit(1);
+    }
 
     try
     {
-      // Test properties
-      Pattern filterPattern = null;
+      tis = new FileInputStream(sTestFile);
+    }
+    catch (Exception e)
+    {
+      errLog("Unable to acccess test description file, " + sTestFile + 
+             " Exception thrown: " + e.getMessage());
+      System.exit(1);
+    }
+
+
+    Properties testProps = new Properties();
+    try
+    {
+      testProps.loadFromXML(tis);
+    }
+    catch (Exception e)
+    {
+      errLog("Unable to parse test description file, " + sTestFile + 
+             " Exception thrown: " + e.getMessage());
+      System.exit(1);
+    }
+
+    Enumeration tests = testProps.propertyNames();
+    while (tests.hasMoreElements())
+    {
+      String page = (String) tests.nextElement();
+      String testName = testProps.getProperty(page);
+      boolean filterMatch = true;
+      if (filterPattern != null)
       {
-        if ((sTestFilter != null) && (sTestFilter.length() > 0))
-        {
-          filterPattern = Pattern.compile(sTestFilter);
-        }
+        Matcher m = filterPattern.matcher(testName);
+        filterMatch = m.matches();
       }
 
-      FileInputStream fis = new FileInputStream(sTestFile);
-      Properties testProps = new Properties();
-      testProps.loadFromXML(fis);
-      Enumeration names = testProps.propertyNames();
-      while (names.hasMoreElements())
+      if (filterMatch)
       {
-        String page = (String)names.nextElement();
-        String testName = testProps.getProperty(page);
-        boolean useTestCase = true;
-        if (filterPattern != null)
-        {
-          Matcher m = filterPattern.matcher(testName);
-          useTestCase = m.matches();
-        }
-
-        if (useTestCase)
+        if (exProps.getProperty(testName) == null)
         {
-          testList.add(new String[]{page, testName});
+          testList.add(new String[]
+              { page, testName });
         }
       }
     }
-    catch (IOException ioe)
-    {
-      errLog("Error while reading test definition file, " + sTestFile);
-      System.exit(1);
-    }
+
     return testList;
   }