You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by ul...@apache.org on 2011/12/16 15:16:38 UTC

svn commit: r1215139 - in /tapestry/tapestry5/trunk: tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ tapestry-test/src/main/java/org/apache/tapestry5/test/

Author: uli
Date: Fri Dec 16 14:16:37 2011
New Revision: 1215139

URL: http://svn.apache.org/viewvc?rev=1215139&view=rev
Log:
TAP5-1794 - Allow for configuring Selenium-based integration tests using an annotation

As an example, convert ActivationRequestParameterTests to use the new annotation.

Added:
    tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/TapestryTestConfiguration.java
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ActivationRequestParameterTests.groovy
    tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ActivationRequestParameterTests.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ActivationRequestParameterTests.groovy?rev=1215139&r1=1215138&r2=1215139&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ActivationRequestParameterTests.groovy (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ActivationRequestParameterTests.groovy Fri Dec 16 14:16:37 2011
@@ -17,7 +17,9 @@ package org.apache.tapestry5.integration
 
 import org.apache.tapestry5.integration.TapestryCoreTestCase
 import org.testng.annotations.Test
+import org.apache.tapestry5.test.TapestryTestConfiguration
 
+@TapestryTestConfiguration(webAppFolder = "src/test/app1")
 class ActivationRequestParameterTests extends TapestryCoreTestCase
 {
     @Test

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=1215139&r1=1215138&r2=1215139&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 Fri Dec 16 14:16:37 2011
@@ -156,13 +156,24 @@ public abstract class SeleniumTestCase e
 
         // Map<String, String> testParameters = xmlTest.getParameters();
 
-        String webAppFolder = getParameter(xmlTest, TapestryTestConstants.WEB_APP_FOLDER_PARAMETER, "src/main/webapp");
-        String container = getParameter(xmlTest, TapestryTestConstants.SERVLET_CONTAINER_PARAMETER, JETTY_7);
-        String contextPath = getParameter(xmlTest, TapestryTestConstants.CONTEXT_PATH_PARAMETER, "");
-        int port = Integer.parseInt(getParameter(xmlTest, TapestryTestConstants.PORT_PARAMETER, "9090"));
-        int sslPort = Integer.parseInt(getParameter(xmlTest, TapestryTestConstants.SSL_PORT_PARAMETER, "8443"));
+        TapestryTestConfiguration annotation = this.getClass().getAnnotation(TapestryTestConfiguration.class);
+        if(annotation == null)
+        {
+            @TapestryTestConfiguration final class defaults{};
+            annotation = defaults.class.getAnnotation(TapestryTestConfiguration.class);
+        }
+
+        String webAppFolder = getParameter(xmlTest, TapestryTestConstants.WEB_APP_FOLDER_PARAMETER,
+                annotation.webAppFolder());
+        String container = getParameter(xmlTest, TapestryTestConstants.SERVLET_CONTAINER_PARAMETER,
+                annotation.container());
+        String contextPath = getParameter(xmlTest, TapestryTestConstants.CONTEXT_PATH_PARAMETER,
+                annotation.contextPath());
+        int port = Integer.parseInt(getParameter(xmlTest, TapestryTestConstants.PORT_PARAMETER, annotation.port()));
+        int sslPort = Integer.parseInt(getParameter(xmlTest, TapestryTestConstants.SSL_PORT_PARAMETER,
+                annotation.sslPort()));
         String browserStartCommand = getParameter(xmlTest, TapestryTestConstants.BROWSER_START_COMMAND_PARAMETER,
-                "*firefox");
+                annotation.browserStartCommand());
 
         final Runnable stopWebServer = launchWebServer(container, webAppFolder, contextPath, port, sslPort);
 

Added: tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/TapestryTestConfiguration.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/TapestryTestConfiguration.java?rev=1215139&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/TapestryTestConfiguration.java (added)
+++ tapestry/tapestry5/trunk/tapestry-test/src/main/java/org/apache/tapestry5/test/TapestryTestConfiguration.java Fri Dec 16 14:16:37 2011
@@ -0,0 +1,65 @@
+//  Copyright 2011 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.
+
+package org.apache.tapestry5.test;
+
+import org.apache.tapestry5.test.SeleniumTestCase;
+
+import java.lang.annotation.*;
+
+/**
+ * To be used on Selenium-based integration tests that extend {@link SeleniumTestCase} as an alternative to using a
+ * TestNG XML configuration file. Using the XML file, it's intricate to run <em>individual</em> test classes or
+ * methods using IDEA's or Eclipse's TestNG integration.
+ *
+ * <b>Parameters coming from a TestNG XML configuration file take precedence over those supplied with the annotation.</b>
+ *
+ * Configures the container to be started for the tests and the browser to be used.
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface TapestryTestConfiguration
+{
+    /**
+     * The folder for the web application root relative to the working directory. Defaults to "src/main/webapp".
+     */
+    String webAppFolder() default "src/main/webapp";
+
+    /**
+     * Which container to use. Can be one of {@link SeleniumTestCase.JETTY_7} or {@link SeleniumTestCase.TOMCAT_6}.
+     * Defaults to {@link SeleniumTestCase.JETTY_7}.
+     */
+    String container() default SeleniumTestCase.JETTY_7;
+
+    /**
+     * The context path to make the application available under. Defaults to "", i.e. the context root.
+     */
+    String contextPath() default "";
+
+    /**
+     * The port to listen on for HTTP requests. Defaults to "9090".
+     */
+    String port() default "9090";
+
+    /**
+     * The port to listen on fot HTTPS requests. Defaults to "8443".
+     */
+    String sslPort() default "8443";
+
+    /**
+     * The browser start command to use with Selenium. Defaults to "*firefox".
+     */
+    String browserStartCommand() default "*firefox";
+}