Author: hlship
Date: Tue Oct 19 18:34:41 2010
New Revision: 1024349
URL: http://svn.apache.org/viewvc?rev=1024349&view=rev
Log:
TAP5-1315: Eliminate the need for SeleniumLauncher; allow a TestCase to set up
Selenium RC & Jetty by itself
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng-limited.xml
tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumLauncher.java
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/TapestryTestConstants.java
tapestry/tapestry5/trunk/tapestry-test/src/test/conf/testng.xml
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng-limited.xml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng-limited.xml?rev=1024349&r1=1024348&r2=1024349&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng-limited.xml
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng-limited.xml Tue
Oct 19 18:34:41 2010
@@ -10,11 +10,6 @@
<packages>
<package name="org.apache.tapestry5.integration.app1"/>
</packages>
-
- <classes>
- <class name="org.apache.tapestry5.test.SeleniumLauncher"/>
-
- </classes>
</test>
</suite>
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml?rev=1024349&r1=1024348&r2=1024349&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml Tue Oct 19
18:34:41 2010
@@ -1,18 +1,14 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
- <!--
- Copyright 2008, 2009 The Apache Software Foundation Licensed under the
Apache License, Version
- 2.0 (the "License"); you may not use this file except in compliance with
the License. You may
- obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by
- applicable law or agreed to in writing, software distributed under the
License is distributed on
- an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See
- the License for the specific language governing permissions and
limitations under the License.
- -->
-
- <!--
- The suite may no longer be run in parallel, because of some tricky issues
related to locking of
- class loaders. Running in parallel causes thread deadlocks, when unmanaged
tests run at the same
- time as Selenium-based integration tests. See TAPESTRY-2561.
- -->
+<!-- Copyright 2008, 2009 The Apache Software Foundation Licensed under the
Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with the
License. You may obtain a copy
+ of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
by applicable law or agreed
+ to in writing, software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES
+ OR CONDITIONS OF ANY KIND, either express or implied. See the License for
the specific language governing
+ permissions and limitations under the License. -->
+
+<!-- The suite may no longer be run in parallel, because of some tricky issues
related to locking of
+ class loaders. Running in parallel causes thread deadlocks, when unmanaged
tests run at the same time
+ as Selenium-based integration tests. See TAPESTRY-2561. -->
<suite name="Tapestry Core" annotations="1.5" verbose="2">
<test name="Component Unit Tests" enabled="true">
<packages>
@@ -51,16 +47,13 @@
</packages>
</test>
- <!-- We break these out by which of the test applications they apply to.
We have a bunch. -->
+ <!-- We break these out by which of the test applications they apply to. We
have a bunch. -->
<test name="Core Integration Tests" enabled="true">
<parameter name="tapestry.web-app-folder" value="src/test/app1"/>
<packages>
<package name="org.apache.tapestry5.integration.app1"/>
</packages>
- <classes>
- <class name="org.apache.tapestry5.test.SeleniumLauncher"/>
- </classes>
</test>
<test name="Additional Integration Tests" enabled="true">
@@ -69,9 +62,6 @@
<packages>
<package name="org.apache.tapestry5.integration.app3"/>
</packages>
- <classes>
- <class name="org.apache.tapestry5.test.SeleniumLauncher"/>
- </classes>
</test>
<test name="Immediate Mode Integration Tests" enabled="true">
@@ -80,9 +70,6 @@
<packages>
<package name="org.apache.tapestry5.integration.app4"/>
</packages>
- <classes>
- <class name="org.apache.tapestry5.test.SeleniumLauncher"/>
- </classes>
</test>
<test name="URL Rewriter Tests" enabled="true">
@@ -91,18 +78,12 @@
<packages>
<package name="org.apache.tapestry5.urlrewriter"/>
</packages>
- <classes>
- <class name="org.apache.tapestry5.test.SeleniumLauncher"/>
- </classes>
</test>
<test name="Live Reload Tests" enabled="true">
<packages>
<package name="org.apache.tapestry5.integration.reload"/>
</packages>
- <classes>
- <class name="org.apache.tapestry5.test.SeleniumLauncher"/>
- </classes>
</test>
<test name="LinkTransformer Tests" enabled="true">
@@ -110,9 +91,6 @@
<packages>
<package name="org.apache.tapestry5.integration.linktrans"/>
</packages>
- <classes>
- <class name="org.apache.tapestry5.test.SeleniumLauncher"/>
- </classes>
</test>
<test name="PageTester Tests" enabled="true">
Modified:
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumLauncher.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumLauncher.java?rev=1024349&r1=1024348&r2=1024349&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumLauncher.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumLauncher.java
Tue Oct 19 18:34:41 2010
@@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,212 +14,25 @@
package org.apache.tapestry5.test;
-import java.io.File;
-import java.util.Map;
-
-import org.openqa.selenium.server.RemoteControlConfiguration;
-import org.openqa.selenium.server.SeleniumServer;
import org.testng.ITestContext;
-import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Optional;
-import org.testng.annotations.Parameters;
-import org.testng.xml.XmlTest;
-
-import com.thoughtworks.selenium.CommandProcessor;
-import com.thoughtworks.selenium.DefaultSelenium;
-import com.thoughtworks.selenium.HttpCommandProcessor;
-import com.thoughtworks.selenium.Selenium;
/**
- * Base class for launching the Selenium test stack, which consists of an
- * instance of {...@link SeleniumServer}, and instance of {...@link Selenium}
RC (the
- * client), and a web server (by default, an instance of Jetty 7).
- * <p>
- * This class contains configuration methods to launch the servers (before
<em>test</em>) and shut
- * them down (after <em>test</em>). In addition, the Selenium instance is
stored as an attribute of
- * the {...@link ITestContext} where it can be pulled out by {...@link
SeleniumTestCase}.
- * <p>
- * To create selenium tests, include SeleniumLauncher as part of your TestNG
configuration and
- * (optionally) configure properties. Create a subclass of {...@link
SeleniumTestCase} to contain your
- * tests.
- * <p>
- * It is rarely necessary to subclass SeleniumLauncher, except if the default
Jetty server instance
- * needs to be configured specially (or replaced with an alternate server such
as Tomcat or Resin).
- * <p>
- * To use this as part of a set of tests, you must configure the class inside
your testng.xml:
- *
- * <pre>
- * <test name="My Integration Tests">
- * <!-- parameters go here, if needed -->
- * <packages>
- * <!-- list of packages containing test suites goes here -->
- * </packages>
- * <classes>
- * <class name="org.apache.tapestry5.test.SeleniumLauncher"/>
- * </classes>
- * </test>
- * </pre>
+ * This class is no longer necessary (as part of the TAP5-1315 fix) and the
reference to it inside testng.xml
+ * may be removed.
*
* @since 5.2.0
+ * @deprecated To be removed in Tapestry 5.3.
*/
+...@deprecated
public class SeleniumLauncher
{
- private SeleniumServer seleniumServer;
-
- private Selenium selenium;
-
- private Runnable stopWebServer;
-
- /**
- * Starts up the servers. By placing <parameter> elements inside the
appropriate
- * <test> (of your testng.xml configuration
- * file), you can change the configuration or behavior of the servers. It
is common to have two
- * or more identical tests that differ only in terms of the
- * <code>tapestry.browser-start-command</code> parameter, to run tests
- * against multiple browsers.
- * <table>
- * <tr>
- * <th>Parameter</th>
- * <th>Name</th>
- * <th>Default</th>
- * <th>Description</th>
- * </tr>
- * <tr>
- * <td>webAppFolder</td>
- * <td>tapestry.web-app-folder</td>
- * <td>src/main/webapp</td>
- * <td>Location of web application context</td>
- * </tr>
- * <tr>
- * <td>contextPath</td>
- * <td>tapestry.context-path</td>
- * <td><em>empty string</em></td>
- * <td>Context path (defaults to root). As elsewhere, the context path
should be blank, or start
- * with a slash (but not end with one).</td>
- * </tr>
- * <tr>
- * <td>port</td>
- * <td>tapestry.port</td>
- * <td>9090</td>
- * <td>Port number for web server to listen to</td>
- * </tr>
- * <tr>
- * <td>sslPort</td>
- * <td>tapestry.ssl-port</td>
- * <td>8443</td>
- * <td>Port number for web server to listen to for secure requests</td>
- * </tr>
- * <tr>
- * <td>browserStartCommand</td>
- * <td>tapestry.browser-start-command</td>
- * <td>*firefox</td>
- * <td>Command string used to launch the browser, as defined by
Selenium</td>
- * </tr>
- * </table>
- *
- * Tests in the <em>beforeStartup</em> group will be run before the start
of Selenium. This
- * can be used to programmatically override the above parameter values.
For an example see
- * {...@link
org.apache.tapestry5.integration.reload.ReloadTests#beforeStartup}.
- *
- * @param webAppFolder
- * @param contextPath
- * @param port
- * @param browserStartCommand
- * @param testContext
- * Used to share objects between the launcher and the test
suites
- * @throws Exception
- */
- // Note: Made this method synchronized since there's no guarantee the same
thread that invokes
- // setup() will invoke
- // shutdown(). Best to be safe!
- @Parameters(
- { TapestryTestConstants.WEB_APP_FOLDER_PARAMETER,
TapestryTestConstants.CONTEXT_PATH_PARAMTER,
- TapestryTestConstants.PORT_PARAMETER,
TapestryTestConstants.SSL_PORT_PARAMETER,
- TapestryTestConstants.BROWSER_START_COMMAND_PARAMETER })
- @BeforeTest(dependsOnGroups = { "beforeStartup" })
- public synchronized void startup(
-
- @Optional("src/main/webapp")
- String webAppFolder,
-
- @Optional("")
- String contextPath,
-
- @Optional("9090")
- int port,
-
- @Optional("8443")
- int sslPort,
-
- @Optional("*firefox")
- String browserStartCommand, ITestContext testContext, XmlTest xmlTest)
throws Exception
- {
- // If a parameter is overridden in another test method, TestNG won't
pass the
- // updated value but the original (coming from testng.xml or the
default).
- Map<String, String> testParameters = xmlTest.getParameters();
-
-
if(testParameters.containsKey(TapestryTestConstants.WEB_APP_FOLDER_PARAMETER))
- webAppFolder =
testParameters.get(TapestryTestConstants.WEB_APP_FOLDER_PARAMETER);
-
-
if(testParameters.containsKey(TapestryTestConstants.CONTEXT_PATH_PARAMTER))
- contextPath =
testParameters.get(TapestryTestConstants.CONTEXT_PATH_PARAMTER);
-
- if(testParameters.containsKey(TapestryTestConstants.PORT_PARAMETER))
- port =
Integer.parseInt(testParameters.get(TapestryTestConstants.PORT_PARAMETER));
-
-
if(testParameters.containsKey(TapestryTestConstants.BROWSER_START_COMMAND_PARAMETER))
- browserStartCommand =
testParameters.get(TapestryTestConstants.BROWSER_START_COMMAND_PARAMETER);
-
- stopWebServer = launchWebServer(webAppFolder, contextPath, port,
sslPort);
-
- seleniumServer = new SeleniumServer();
-
- File ffProfileTemplate = new
File(TapestryTestConstants.MODULE_BASE_DIR,
"src/test/conf/ff_profile_template");
-
- if(ffProfileTemplate.isDirectory())
-
seleniumServer.getConfiguration().setFirefoxProfileTemplate(ffProfileTemplate);
-
- seleniumServer.start();
-
- String baseURL = String.format("http://localhost:%d%s/", port,
contextPath);
-
- CommandProcessor cp = new HttpCommandProcessor("localhost",
- RemoteControlConfiguration.DEFAULT_PORT, browserStartCommand,
baseURL);
-
- ErrorReporter errorReporter = new ErrorReporterImpl(cp, testContext);
-
- selenium = new DefaultSelenium(new ErrorReportingCommandProcessor(cp,
errorReporter));
-
- selenium.start();
-
- testContext.setAttribute(TapestryTestConstants.BASE_URL_ATTRIBUTE,
baseURL);
- testContext.setAttribute(TapestryTestConstants.SELENIUM_ATTRIBUTE,
selenium);
-
testContext.setAttribute(TapestryTestConstants.ERROR_REPORTER_ATTRIBUTE,
errorReporter);
- }
-
- /** Shuts down the stack at the end of the test. */
- @AfterTest
- public synchronized void cleanup()
+ @BeforeTest(dependsOnGroups =
+ { "beforeStartup" })
+ public void startup() throws Exception
{
- if (selenium != null)
- {
- selenium.stop();
- selenium = null;
- }
-
- if (seleniumServer != null)
- {
- seleniumServer.stop();
- seleniumServer = null;
- }
-
- if (stopWebServer != null)
- {
- stopWebServer.run();
- stopWebServer = null;
- }
-
+ System.err.println("***\n*** Class
org.apache.tapestry5.test.SeleniumLauncher is not longer used, and may be\n"
+ + "*** removed from testng.xml.\n***");
}
/**
@@ -240,17 +53,8 @@ public class SeleniumLauncher
* @return Runnable used to shut down the server
* @throws Exception
*/
- protected Runnable launchWebServer(String webAppFolder, String
contextPath, int port, int sslPort)
- throws Exception
+ protected Runnable launchWebServer(String webAppFolder, String
contextPath, int port, int sslPort) throws Exception
{
- final Jetty7Runner runner = new Jetty7Runner(webAppFolder,
contextPath, port, sslPort);
-
- return new Runnable()
- {
- public void run()
- {
- runner.stop();
- }
- };
+ return null;
}
}
Modified:
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java?rev=1024349&r1=1024348&r2=1024349&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java
Tue Oct 19 18:34:41 2010
@@ -14,20 +14,33 @@
package org.apache.tapestry5.test;
+import java.io.File;
import java.lang.reflect.Method;
+import java.util.Map;
+import org.openqa.selenium.server.RemoteControlConfiguration;
+import org.openqa.selenium.server.SeleniumServer;
import org.testng.Assert;
import org.testng.ITestContext;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
+import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
-
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Optional;
+import org.testng.annotations.Parameters;
+import org.testng.xml.XmlTest;
+
+import com.thoughtworks.selenium.CommandProcessor;
+import com.thoughtworks.selenium.DefaultSelenium;
+import com.thoughtworks.selenium.HttpCommandProcessor;
import com.thoughtworks.selenium.Selenium;
/**
* Base class for creating Selenium-based integration test cases. This class
implements all the
- * methods of {...@link Selenium} and delegates to an instance (setup once per
test by {...@link SeleniumLauncher}).
+ * methods of {...@link Selenium} and delegates to an instance (setup once per
test by
+ * {...@link #testStartup(String, String, int, int, String, ITestContext,
XmlTest)}.
*
* @since 5.2.0
*/
@@ -38,9 +51,6 @@ public class SeleniumTestCase extends As
*/
public static final String PAGE_LOAD_TIMEOUT = "15000";
- /**
- * Provided by {...@link SeleniumLauncher}.
- */
private Selenium delegate;
private String baseURL;
@@ -49,6 +59,211 @@ public class SeleniumTestCase extends As
private ITestContext testContext;
+ /**
+ * Starts up the servers for the entire test (i.e., for multiple
TestCases). By placing <parameter> elements
+ * inside the appropriate <test> (of your testng.xml configuration
+ * file), you can change the configuration or behavior of the servers. It
is common to have two
+ * or more identical tests that differ only in terms of the
<code>tapestry.browser-start-command</code> parameter,
+ * to run tests against multiple browsers.
+ * <table>
+ * <tr>
+ * <th>Parameter</th>
+ * <th>Name</th>
+ * <th>Default</th>
+ * <th>Description</th>
+ * </tr>
+ * <tr>
+ * <td>webAppFolder</td>
+ * <td>tapestry.web-app-folder</td>
+ * <td>src/main/webapp</td>
+ * <td>Location of web application context</td>
+ * </tr>
+ * <tr>
+ * <td>contextPath</td>
+ * <td>tapestry.context-path</td>
+ * <td><em>empty string</em></td>
+ * <td>Context path (defaults to root). As elsewhere, the context path
should be blank, or start with a slash (but
+ * not end with one).</td>
+ * </tr>
+ * <tr>
+ * <td>port</td>
+ * <td>tapestry.port</td>
+ * <td>9090</td>
+ * <td>Port number for web server to listen to</td>
+ * </tr>
+ * <tr>
+ * <td>sslPort</td>
+ * <td>tapestry.ssl-port</td>
+ * <td>8443</td>
+ * <td>Port number for web server to listen to for secure requests</td>
+ * </tr>
+ * <tr>
+ * <td>browserStartCommand</td>
+ * <td>tapestry.browser-start-command</td>
+ * <td>*firefox</td>
+ * <td>Command string used to launch the browser, as defined by
Selenium</td>
+ * </tr>
+ * </table>
+ * <p>
+ * Tests in the <em>beforeStartup</em> group will be run before the start
of Selenium. This can be used to
+ * programmatically override the above parameter values. For an example see
+ * {...@link
org.apache.tapestry5.integration.reload.ReloadTests#beforeStartup}.
+ * <p>
+ * This method will be invoked in <em>each</em> subclass, but is set up to
only startup the servers once (it checks
+ * the {...@link ITestContext} to see if the necessary keys are already
present).
+ *
+ * @param webAppFolder
+ * @param contextPath
+ * @param port
+ * @param browserStartCommand
+ * @param testContext
+ * Used to share objects between the launcher and the test
suites
+ * @throws Exception
+ */
+ @Parameters(
+ { TapestryTestConstants.WEB_APP_FOLDER_PARAMETER,
TapestryTestConstants.CONTEXT_PATH_PARAMETER,
+ TapestryTestConstants.PORT_PARAMETER,
TapestryTestConstants.SSL_PORT_PARAMETER,
+ TapestryTestConstants.BROWSER_START_COMMAND_PARAMETER })
+ @BeforeTest(dependsOnGroups =
+ { "beforeStartup" })
+ public void testStartup(
+
+ @Optional("src/main/webapp")
+ String webAppFolder,
+
+ @Optional("")
+ String contextPath,
+
+ @Optional("9090")
+ int port,
+
+ @Optional("8443")
+ int sslPort,
+
+ @Optional("*firefox")
+ String browserStartCommand, final ITestContext testContext, XmlTest
xmlTest) throws Exception
+ {
+ // This is not actually necessary, because TestNG will only invoke
this method once
+ // even when multiple test cases within the test extend from
SeleniumTestCase. TestNG
+ // just invokes it on the "first" TestCase instance it has test
methods for.
+
+ if (testContext.getAttribute(TapestryTestConstants.SHUTDOWN_ATTRIBUTE)
!= null)
+ return;
+
+ // If a parameter is overridden in another test method, TestNG won't
pass the
+ // updated value via a parameter, but still passes the original
(coming from testng.xml or the default).
+ // Seems like a TestNG bug.
+
+ Map<String, String> testParameters = xmlTest.getParameters();
+
+ if
(testParameters.containsKey(TapestryTestConstants.WEB_APP_FOLDER_PARAMETER))
+ webAppFolder =
testParameters.get(TapestryTestConstants.WEB_APP_FOLDER_PARAMETER);
+
+ if
(testParameters.containsKey(TapestryTestConstants.CONTEXT_PATH_PARAMETER))
+ contextPath =
testParameters.get(TapestryTestConstants.CONTEXT_PATH_PARAMETER);
+
+ if (testParameters.containsKey(TapestryTestConstants.PORT_PARAMETER))
+ port =
Integer.parseInt(testParameters.get(TapestryTestConstants.PORT_PARAMETER));
+
+ if
(testParameters.containsKey(TapestryTestConstants.BROWSER_START_COMMAND_PARAMETER))
+ browserStartCommand =
testParameters.get(TapestryTestConstants.BROWSER_START_COMMAND_PARAMETER);
+
+ final Runnable stopWebServer = launchWebServer(webAppFolder,
contextPath, port, sslPort);
+
+ final SeleniumServer seleniumServer = new SeleniumServer();
+
+ File ffProfileTemplate = new
File(TapestryTestConstants.MODULE_BASE_DIR,
"src/test/conf/ff_profile_template");
+
+ if (ffProfileTemplate.isDirectory())
+
seleniumServer.getConfiguration().setFirefoxProfileTemplate(ffProfileTemplate);
+
+ seleniumServer.start();
+
+ String baseURL = String.format("http://localhost:%d%s/", port,
contextPath);
+
+ CommandProcessor cp = new HttpCommandProcessor("localhost",
RemoteControlConfiguration.DEFAULT_PORT,
+ browserStartCommand, baseURL);
+
+ ErrorReporter errorReporter = new ErrorReporterImpl(cp, testContext);
+
+ final Selenium selenium = new DefaultSelenium(new
ErrorReportingCommandProcessor(cp, errorReporter));
+
+ selenium.start();
+
+ testContext.setAttribute(TapestryTestConstants.BASE_URL_ATTRIBUTE,
baseURL);
+ testContext.setAttribute(TapestryTestConstants.SELENIUM_ATTRIBUTE,
selenium);
+
testContext.setAttribute(TapestryTestConstants.ERROR_REPORTER_ATTRIBUTE,
errorReporter);
+
+ testContext.setAttribute(TapestryTestConstants.SHUTDOWN_ATTRIBUTE, new
Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ selenium.stop();
+ seleniumServer.stop();
+ stopWebServer.run();
+ }
+ finally
+ {
+
+
testContext.removeAttribute(TapestryTestConstants.BASE_URL_ATTRIBUTE);
+
testContext.removeAttribute(TapestryTestConstants.SELENIUM_ATTRIBUTE);
+
testContext.removeAttribute(TapestryTestConstants.ERROR_REPORTER_ATTRIBUTE);
+
testContext.removeAttribute(TapestryTestConstants.SHUTDOWN_ATTRIBUTE);
+ }
+ }
+ });
+ }
+
+ /**
+ * Like {...@link #testStartup(String, String, int, int, String,
ITestContext, XmlTest)}, this may
+ * be called multiple times against multiple instances, but only does work
the first time.
+ */
+ @AfterTest
+ public void testShutdown(ITestContext context)
+ {
+ // Likewise, this method should only be invoked once.
+ Runnable r = (Runnable)
context.getAttribute(TapestryTestConstants.SHUTDOWN_ATTRIBUTE);
+
+ // This test is still useful, however, because testStartup() may not
have completed properly,
+ // and the runnable is the last thing it puts into the test context.
+
+ if (r != null)
+ r.run();
+ }
+
+ /**
+ * Invoked from {...@link #testStartup(String, String, int, String,
ITestContext)} to launch the web
+ * server to be
+ * tested. The return value is a Runnable that will shut down the launched
server at the end of
+ * the test (it is coded this way so that the default Jetty web server can
be more easily
+ * replaced).
+ *
+ * @param webAppFolder
+ * path to the web application context
+ * @param contextPath
+ * the path the context is mapped to, usually the empty string
+ * @param port
+ * the port number the server should handle
+ * @param sslPort
+ * the port number on which the server should handle secure
requests
+ * @return Runnable used to shut down the server
+ * @throws Exception
+ */
+ protected Runnable launchWebServer(String webAppFolder, String
contextPath, int port, int sslPort) throws Exception
+ {
+ final Jetty7Runner runner = new Jetty7Runner(webAppFolder,
contextPath, port, sslPort);
+
+ return new Runnable()
+ {
+ public void run()
+ {
+ runner.stop();
+ }
+ };
+ }
+
@BeforeClass
public void setup(ITestContext context)
{
Modified:
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/TapestryTestConstants.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/TapestryTestConstants.java?rev=1024349&r1=1024348&r2=1024349&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/TapestryTestConstants.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/TapestryTestConstants.java
Tue Oct 19 18:34:41 2010
@@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -30,15 +30,11 @@ public class TapestryTestConstants
public static final String CURRENT_DIR_PATH =
System.getProperty("user.dir");
/**
* The Surefire plugin sets basedir but DOES NOT change the current
working directory. When
- * building across modules,
- * basedir changes for each module, but user.dir does not. This value
should be used when
- * referecing local files.
- * Outside of surefire, the "basedir" property will not be set, and the
current working
- * directory will be the
- * default.
+ * building across modules, basedir changes for each module, but user.dir
does not. This value should be used when
+ * referencing local files. Outside of surefire, the "basedir" property
will not be set, and the current working
+ * directory will be the default.
*/
- public static final String MODULE_BASE_DIR_PATH =
System.getProperty("basedir",
- CURRENT_DIR_PATH);
+ public static final String MODULE_BASE_DIR_PATH =
System.getProperty("basedir", CURRENT_DIR_PATH);
/**
* {...@link #MODULE_BASE_DIR_PATH} as a file.
@@ -62,6 +58,14 @@ public class TapestryTestConstants
public static final String ERROR_REPORTER_ATTRIBUTE =
"tapestry.error-reporter";
/**
+ * {...@link ITestContext} attribute holding an instance of {...@link
ErrorReporter}, used
+ * to shutdown Selenium and the Web Server at the end of the test.
+ *
+ * @since 5.2.2
+ */
+ public static final String SHUTDOWN_ATTRIBUTE = "tapestry.shutdown";
+
+ /**
* {...@link ITestContext} attribute holding the application's base URL.
*
* @see SeleniumLauncher#startup(String, String, int, String, ITestContext)
@@ -74,28 +78,28 @@ public class TapestryTestConstants
* (as a {...@link Method} instance).
*/
public static final String CURRENT_TEST_METHOD_ATTRIBUTE =
"tapestry.current-test-method";
-
+
/**
* {...@link XmlTest} parameter holding an absolute or relative path to a
web app
* folder.
*/
public static final String WEB_APP_FOLDER_PARAMETER =
"tapestry.web-app-folder";
-
+
/**
* {...@link XmlTest} parameter holding the context path.
*/
- public static final String CONTEXT_PATH_PARAMTER = "tapestry.context-path";
-
+ public static final String CONTEXT_PATH_PARAMETER =
"tapestry.context-path";
+
/**
* {...@link XmlTest} parameter holding the web server port.
*/
public static final String PORT_PARAMETER = "tapestry.port";
-
+
/**
* {...@link XmlTest} parameter holding the web server ssl port.
*/
public static final String SSL_PORT_PARAMETER = "tapestry.ssl-port";
-
+
/**
* {...@link XmlTest} parameter holding the browser command to pass to
Selenium.
*/
Modified: tapestry/tapestry5/trunk/tapestry-test/src/test/conf/testng.xml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-test/src/test/conf/testng.xml?rev=1024349&r1=1024348&r2=1024349&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-test/src/test/conf/testng.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-test/src/test/conf/testng.xml Tue Oct 19
18:34:41 2010
@@ -12,7 +12,6 @@
<parameter name="tapestry.web-app-folder" value="src/test/webapp"/>
<test name="SeleniumLauncher and SeleniumTestBase">
<classes>
- <class name="org.apache.tapestry5.test.SeleniumLauncher"/>
<class name="org.apache.tapestry5.test.SanityCheckTestSuite"/>
</classes>