jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaqu...@apache.org
Subject svn commit: r666988 - /incubator/jspwiki/trunk/build.xml
Date Thu, 12 Jun 2008 06:39:42 GMT
Author: ajaquith
Date: Wed Jun 11 23:39:41 2008
New Revision: 666988

URL: http://svn.apache.org/viewvc?rev=666988&view=rev
Log:
Web unit tests refactored (yet again) to use an embedded Jetty server. This replaces the need
to use a separate Tomcat server, and *should* always work without any configuration of any
kind. Please tests this via the Ant 'webtests' target! Note that this checkin introduces the
TestContainer class, which with a little modification (later, please!) could easily be used
as a stand-alone server. Refactorings are welcome; in the meantime, TestContainer should be
considered volatile. Note also that the Rename Profile web unit tests for the container scenarios
currently fails; all others run successfully.

Modified:
    incubator/jspwiki/trunk/build.xml

Modified: incubator/jspwiki/trunk/build.xml
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/build.xml?rev=666988&r1=666987&r2=666988&view=diff
==============================================================================
--- incubator/jspwiki/trunk/build.xml (original)
+++ incubator/jspwiki/trunk/build.xml Wed Jun 11 23:39:41 2008
@@ -106,10 +106,12 @@
   <property name="tests.reports" value="tests/reports" />
   
   <!-- Web unit test properties -->
-  <property name="webtests.browser" value="*firefox" />
-  <property name="webtests.container.user" value="janne" />
-  <property name="webtests.container.password" value="myP@5sw0rd" />
-  <property name="webtests.reports" value="${basedir}/tests/reports/selenium" />
+  <property name="webtests.browser"  value="*firefox" />
+  <property name="webtests.reports"  value="${basedir}/tests/reports/selenium" />
+  <property name="webtests.build"    value="tests/build/webtests" />
+  <property name="webtests.port"     value="10024" />
+  <property name="webtests.shutdown" value="19041" />
+  <property name="webtests.temp"     value="${java.io.tmpdir}/webtests" />
 
   <!-- The place where the javadocs are created -->
 
@@ -392,7 +394,6 @@
          <include name="dtd/**" />
          <include name="jsp/**" />
          <include name="commons-logging.properties" />
-         <include name="jspwiki.jaas" />
          <include name="jspwiki.policy" />
          <include name="jspwiki.properties" />
          <include name="*.tld" />
@@ -511,8 +512,7 @@
      <copy file="README" todir="${install.fulldir}" />
      <copy file="ChangeLog" todir="${install.fulldir}" />
      <copy file="ReleaseNotes" todir="${install.fulldir}" />
-     <copy file="LICENSE" todir="${install.fulldir}" />
-     <copy file="NOTICE" todir="${install.fulldir}" />
+     <copy file="doc/LICENSE" todir="${install.fulldir}" />
 
      <zip zipfile="${release.dir}/${ant.project.name}-bin.zip">
         <zipfileset dir="${install.fulldir}" prefix="${ant.project.name}" />
@@ -535,25 +535,25 @@
       <mkdir dir="tests/etc/WEB-INF" />
 
       <!-- Create web.xml files for testing -->
-      <copy file="${basedir}/etc/web.xml" tofile="${tests.build}/web.xml.custom" overwrite="true"
/>
+      <copy file="${basedir}/etc/web.xml" tofile="${webtests.build}/web.xml.custom" overwrite="true"
/>
 
       <!-- For web unit tests, turn off SSL (self-signed certs b0rk
            the tests) and enable JDBC refs -->
-      <replace file="${tests.build}/web.xml.custom"
+      <replace file="${webtests.build}/web.xml.custom"
                token="CONFIDENTIAL" value="NONE" />
-      <replace file="${tests.build}/web.xml.custom"
+      <replace file="${webtests.build}/web.xml.custom"
                token="&lt;!--  REMOVE ME TO ENABLE JDBC DATABASE" value="" />
-      <replace file="${tests.build}/web.xml.custom"
+      <replace file="${webtests.build}/web.xml.custom"
                token="REMOVE ME TO ENABLE JDBC DATABASE  --&gt;" value="" />
 
       <!-- For unit testing, turn on container auth -->
-      <copy file="${tests.build}/web.xml.custom"
-          tofile="${tests.build}/web.xml.container" overwrite="true" />
-      <replace file="${tests.build}/web.xml.container"
+      <copy file="${webtests.build}/web.xml.custom"
+          tofile="${webtests.build}/web.xml.container" overwrite="true" />
+      <replace file="${webtests.build}/web.xml.container"
                token="&lt;!--  REMOVE ME TO ENABLE CONTAINER-MANAGED AUTH" value="" />
-      <replace file="${tests.build}/web.xml.container"
+      <replace file="${webtests.build}/web.xml.container"
                token="REMOVE ME TO ENABLE CONTAINER-MANAGED AUTH  --&gt;" value="" />
-      <copy file="${tests.build}/web.xml.container"
+      <copy file="${webtests.build}/web.xml.container"
           tofile="tests/etc/WEB-INF/web.xml" overwrite="true" />
 
       <!-- Copy the DTDs to the test WEB-INF -->
@@ -590,13 +590,9 @@
         <classpath>
            <path refid="path.tests" />
         </classpath>
-
-        <sysproperty key="java.security.auth.login.config" value="${basedir}/etc/jspwiki.jaas"/>
-		<sysproperty key="jspwiki.tests.auth" value="true" />
-
+        <sysproperty key="jspwiki.tests.auth" value="true" />
         <formatter type="plain" />
-    	    <formatter type="xml" usefile="yes" />
-
+        <formatter type="xml" usefile="yes" />
         <batchtest todir="${tests.reports}">
            <fileset dir="${tests.src}">
                 <include name="**/*Test.java" />
@@ -624,15 +620,11 @@
         <classpath>
            <path refid="path.tests" />
         </classpath>
-
-        <sysproperty key="java.security.auth.login.config" value="${basedir}/etc/jspwiki.jaas"/>
         <sysproperty key="jspwiki.tests.auth" value="true" />
         <jvmarg value="-Xdebug" />
         <jvmarg value="-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y"
/>
-
         <formatter type="plain" />
         <formatter type="xml" usefile="yes" />
-
         <batchtest todir="${tests.reports}">
            <fileset dir="${tests.src}">
                 <include name="**/AuthorizationManagerTest.java" />
@@ -656,145 +648,222 @@
         <classpath>
            <path refid="path.tests" />
         </classpath>
-
-        <sysproperty key="java.security.auth.login.config" value="${basedir}/etc/jspwiki.jaas"/>
-		<sysproperty key="jspwiki.tests.auth" value="true" />
-
+        <sysproperty key="jspwiki.tests.auth" value="true" />
         <arg value="com.ecyrd.jspwiki.AllTests" />
      </java>
 
   </target>
 
-  <!-- This target runs web unit tests using Selenium. These tests assumes you 
-       have Tomcat or higher installed **and** that it is running on
-       ${tomcat.host}:${tomcat.port} when you execute this target. The Manager
-       app must be configured. Also, the Tomcat server's tomcat-users.xml
-       file must contain a user named 'janne' with a password 'myP@5sw0rd'
-       and an assigned role of 'Authenticated'.
-       These tests has been verified to deploy on Tomcat 5.5;
-       other versions may not work.
-
-       If you have previously set a custom JSPWiki security policy, you
-       MUST bounce Tomcat first. Otherwise, the previously installed policy
-       will be in effect, and may hose the web unit tests.
-
-       Of course, you need not use Tomcat in production... but to
-       keep this build file simple, we do require it for web unit tests.
-
-       Note: if the majority of JDBC tests fail but the non-JDBC tests do
-       not, that likely means that Tomcat cannot find your JDBC jar. You
-       should copy this file to Tomcat's common/lib directory (for 5.5) or
-       lib (6.0).
+  <!-- This target runs web unit tests using Selenium. These tests run
+       using an enbedded Jetty server running on a hard-coded high port.
+       The webapps deployed to Jetty contain 2 sample users:
+       - 'janne' with password 'myP@5sw0rd' and role of 'Authenticated'
+       - 'admin' with password 'myP@5sw0rd' and roles of 'Authenticated', 'Admin'
+       These are the same as the test users in tests/com.ecyrd.jspwiki.auth.Users.
   -->
-  <target name="webtests" depends="jar,tests-init,jartests,tests-db-init,tomcat-init,war">
-
-    <!-- Make sure Tomcat is set up the way we expect -->
-    <ant dir="${basedir}" antfile="tests/etc/webtests.xml"
-      target="webtests-init" inheritRefs="true" />
-
-    <!-- Build and test the custom auth WAR -->
-    <copy file="etc/jspwiki.properties"
-        toFile="${tests.build}/jspwiki.properties.custom" flatten="true" />
-    <propertyfile file="${tests.build}/jspwiki.properties.custom">
+  <target name="webtests" depends="jar,tests-init,jartests,tests-db-init,war">
+    <mkdir dir="${webtests.temp}" />
+    <mkdir dir="${webtests.build}" />
+  
+    <!-- Create the master jspwiki.properties template for all webtests -->
+    <copy file="tests/etc/jspwiki.properties"
+        toFile="${webtests.build}/jspwiki.properties.tmpl" flatten="true" />
+    <propertyfile file="${webtests.build}/jspwiki.properties.tmpl">
+      <entry key="jspwiki.authorizer" value="com.ecyrd.jspwiki.auth.authorize.WebContainerAuthorizer"
/>
       <entry key="jspwiki.userdatabase" value="com.ecyrd.jspwiki.auth.user.XMLUserDatabase"
/>
       <entry key="jspwiki.groupdatabase" value="com.ecyrd.jspwiki.auth.authorize.XMLGroupDatabase"
/>
       <entry key="jspwiki.referenceStyle" value="relative" />
+      <entry key="jspwiki.userdatabase.hashPrefix" value="false" />
+      <entry key="log4j.appender.TestContainerLog.File" value="${basedir}/${webtests.build}/testcontainer.log"
/>
+      <entry key="jspwiki-x.securityconfig.enable" value="true" />
     </propertyfile>
+
+    <!-- Build the custom auth WAR -->
     <webtest-setup context="test-custom"
-      webxml="${tests.build}/web.xml.custom"
-      props="${tests.build}/jspwiki.properties.custom" />
-    <webtest-selenium context="test-custom" />
-    <webtest-teardown context="test-custom" />
-
-    <!-- Build and test the custom auth WAR (absolute URLs) -->
-    <copy file="${tests.build}/jspwiki.properties.custom"
-        toFile="${tests.build}/jspwiki.properties.custom-absolute" flatten="true" />
-    <propertyfile file="${tests.build}/jspwiki.properties.custom-absolute">
-      <entry key="jspwiki.referenceStyle" value="absolute" />
-      <entry key="jspwiki.baseURL" value="${tomcat.protocol}://${tomcat.host}:${tomcat.port}/test-custom-absolute/"
/>
-    </propertyfile>
+      webxml="${webtests.build}/web.xml.custom"/>
+
+    <!-- Build the custom auth WAR (absolute URLs) -->
     <webtest-setup context="test-custom-absolute"
-      webxml="${tests.build}/web.xml.custom"
-      props="${tests.build}/jspwiki.properties.custom-absolute" />
-    <webtest-selenium context="test-custom-absolute" />
-    <webtest-teardown context="test-custom-absolute" />
+      webxml="${webtests.build}/web.xml.custom">
+      <propertyfile-entries>
+        <entry key="jspwiki.referenceStyle" value="absolute" />
+        <entry key="jspwiki.baseURL" value="http://localhost:${webtests.port}/test-custom-absolute/"
/>
+      </propertyfile-entries>
+    </webtest-setup>
 
-    <!-- Build and test the container auth WAR -->
+    <!-- Build the container auth WAR -->
     <webtest-setup context="test-container"
-      webxml="${tests.build}/web.xml.container"
-      props="${tests.build}/jspwiki.properties.custom" />
-    <webtest-selenium context="test-container" />
-    <webtest-teardown context="test-container" />
+      webxml="${webtests.build}/web.xml.container" />
 
     <!-- Build the custom auth WAR (JDBC database) -->
-    <copy file="etc/jspwiki.properties"
-        toFile="${tests.build}/jspwiki.properties.custom-jdbc" flatten="true" />
-    <propertyfile file="${tests.build}/jspwiki.properties.custom-jdbc">
-      <entry key="jspwiki.userdatabase" value="com.ecyrd.jspwiki.auth.user.JDBCUserDatabase"
/>
-      <entry key="jspwiki.userdatabase.hashPrefix" value="false" />
-      <entry key="jspwiki.groupdatabase" value="com.ecyrd.jspwiki.auth.authorize.JDBCGroupDatabase"
/>
-    </propertyfile>
     <webtest-setup context="test-custom-jdbc"
-      webxml="${tests.build}/web.xml.custom"
-      props="${tests.build}/jspwiki.properties.custom-jdbc" />
-    <webtest-selenium context="test-container-jdbc" />
-    <webtest-teardown context="test-container-jdbc" />
-
-    <!-- Build and test the container auth WAR (shared JDBC database) and test it -->
-    <copy file="etc/jspwiki.properties"
-        toFile="${tests.build}/jspwiki.properties.container-jdbc" flatten="true" />
-    <propertyfile file="${tests.build}/jspwiki.properties.container-jdbc">
-      <entry key="jspwiki.userdatabase" value="com.ecyrd.jspwiki.auth.user.JDBCUserDatabase"
/>
-      <entry key="jspwiki.userdatabase.isSharedWithContainer" value="true" />
-      <entry key="jspwiki.userdatabase.hashPrefix" value="false" />
-      <entry key="jspwiki.groupdatabase" value="com.ecyrd.jspwiki.auth.authorize.JDBCGroupDatabase"
/>
-    </propertyfile>
-    <webtest-setup context="test-container-jdbc"
-      webxml="${tests.build}/web.xml.container"
-      props="${tests.build}/jspwiki.properties.container-jdbc" />
-    <webtest-selenium context="test-custom-jdbc" />
-    <webtest-teardown context="test-custom-jdbc" />
+      webxml="${webtests.build}/web.xml.custom">
+      <propertyfile-entries>
+        <entry key="jspwiki.userdatabase" value="com.ecyrd.jspwiki.auth.user.JDBCUserDatabase"
/>
+        <entry key="jspwiki.groupdatabase" value="com.ecyrd.jspwiki.auth.authorize.JDBCGroupDatabase"
/>
+      </propertyfile-entries>
+    </webtest-setup>
 
+    <!-- Build the container auth WAR (JDBC database) and test it -->
+    <webtest-setup context="test-container-jdbc"
+      webxml="${webtests.build}/web.xml.container">
+      <propertyfile-entries>
+        <entry key="jspwiki.userdatabase" value="com.ecyrd.jspwiki.auth.user.JDBCUserDatabase"
/>
+        <entry key="jspwiki.groupdatabase" value="com.ecyrd.jspwiki.auth.authorize.JDBCGroupDatabase"
/>
+      </propertyfile-entries>
+    </webtest-setup>
+
+    <!-- Run each test in succession -->
+    <mkdir dir="${webtests.reports}" />
+    <webtest-exec context="test-custom" />
+    <webtest-exec context="test-container" />
+    <webtest-exec context="test-custom-jdbc" />
+    <webtest-exec context="test-container-jdbc" />
+    <webtest-exec context="test-custom-absolute" />
     <echo>The web unit tests have finished. You can find the test reports in ${webtests.reports}.
     
-If all of the tests ran successfully, the reports will all be "green." If all tests ran successfully
except for the "test-container" suite, then your web container is likely not set up correctly.
Check to make sure that the your Tomcat container's default realm contains the user '${webtests.container.user}'
with password '${webtests.container.password}' and role 'Authenticated'. Usually, Tomcat uses
the "memory realm"; the config file is at ${tomcat.home}/conf/tomcat-users.xml.</echo>
+If all of the tests ran successfully, the reports will all be "green."</echo>
     
   </target>
 
   <macrodef name="webtest-setup">
     <attribute name="context" />
     <attribute name="webxml" />
-    <attribute name="props" />
+    <attribute name="context.dir" default="${webtests.build}/@{context}" />
+    <attribute name="context.path" default="${basedir}/${webtests.build}/@{context}" />
+    <element name="propertyfile-entries" implicit="no" optional="true" />
     <sequential>
-      <ant dir="${basedir}" antfile="tests/etc/webtests.xml"
-        target="webtest-setup" inheritRefs="true">
-        <property name="webtest.context" value="@{context}" />
-        <property name="webtest.webxml"  value="@{webxml}" />
-        <property name="webtest.props"   value="@{props}" />
-      </ant>
+
+      <echo message="==============================================================="
/>
+      <echo message=" Setting up web unit tests for '@{context}'" />
+      <echo message="- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
/>
+      <echo message="" />
+      <echo message="Creating Selenium test scripts..."/>
+      <mkdir dir="@{context.dir}/selenium" />
+      <copy flatten="true" toDir="@{context.dir}/selenium">
+        <fileset dir="tests/etc/selenium/tests/all" />
+        <filterset>
+          <filter token="selenium.context" value="@{context}" />
+        </filterset>
+      </copy>
+
+      <echo message="Creating test page repositories..."/>
+      <!-- Create a wiki page directory and point jspwiki.properties to it -->
+      <mkdir dir="@{context.dir}/wikipages" />
+      <copy toDir="@{context.dir}/wikipages" flatten="true" >
+        <fileset dir="src/wikipages">
+          <include name="Main.*" />
+          <include name="LeftMenu*.*" />
+          <include name="About.*" />
+          <include name="RecentChanges.*" />
+          <include name="WikiEtiquette.*" />
+          <include name="UnusedPages.*" />
+          <include name="UndefinedPages.*" />
+          <include name="PageIndex.*" />
+        </fileset>
+      </copy>
+
+      <echo message="Creating test webapp..."/>
+      <mkdir dir="@{context.dir}/webapp/WEB-INF/classes" />
+      <mkdir dir="@{context.dir}/webapp/WEB-INF/lib" />
+
+      <!-- Copy the WEB-INF files -->
+      <copy toDir="@{context.dir}/webapp/WEB-INF">
+        <fileset dir="etc">
+          <include name="dtd/**" />
+          <include name="commons-logging.properties" />
+          <include name="jspwiki.policy" />
+          <include name="*.tld" />
+        </fileset>
+        <fileset dir="tests/etc" includes="userdatabase.xml groupdatabase.xml" />
+      </copy>
+      <copy toFile="@{context.dir}/webapp/WEB-INF/web.xml" file="@{webxml}" flatten="true"
/>
+      
+      <!-- Create the jspwiki.properties file -->
+      <mkdir dir="@{context.dir}/workdir" />
+      <copy toFile="@{context.dir}/webapp/WEB-INF/jspwiki.properties"
+        file="${webtests.build}/jspwiki.properties.tmpl" flatten="true" />
+        <propertyfile file="@{context.dir}/webapp/WEB-INF/jspwiki.properties">
+          <entry key="jspwiki.baseURL"                            value="http://localhost:${webtests.port}/@{context}/"
/>
+          <entry key="jspwiki.workDir"                            value="@{context.path}/workdir"
/>
+          <entry key="jspwiki.fileSystemProvider.pageDir"         value="@{context.path}/wikipages"
/>
+          <entry key="jspwiki.basicAttachmentProvider.storageDir" value="@{context.path}/wikipages"
/>
+          <entry key="jspwiki.xmlUserDatabaseFile"                value="@{context.path}/webapp/WEB-INF/userdatabase.xml"
/>
+          <entry key="jspwiki.xmlGroupDatabaseFile"               value="@{context.path}/webapp/WEB-INF/groupdatabase.xml"
/>
+          <entry key="log4j.appender.FileLog.File"                value="@{context.path}/jspwiki.log"
/>
+        <propertyfile-entries/>
+      </propertyfile>
+
+      <!-- Copy the classes -->
+      <copy toDir="@{context.dir}/webapp/WEB-INF/classes">
+        <fileset dir="etc" includes="oscache.properties" />
+      </copy>
+
+      <!-- Copy the libraries -->
+      <copy toDir="@{context.dir}/webapp/WEB-INF/lib">
+        <fileset dir="lib" includes="*.jar" excludes="servlet-api.jar jsp-api.jar"/>
+        <fileset file="${jarfile}"/>
+        <fileset file="${jdbc.driver.jar}"/>
+      </copy>
+
+      <!-- Copy the JSPs -->
+      <copy toDir="@{context.dir}/webapp">
+        <fileset dir="${code.src}/webdocs" includes="**" />
+      </copy>
+
     </sequential>
   </macrodef>
+  
+  <!-- ============================================================== -->
+  
+  <!-- Selenium execution test task -->
 
-  <macrodef name="webtest-teardown">
-    <attribute name="context" />
+  <!-- This macro executes the Selenium test plans located in 
+       tests/build/selenium/@context@/, based on templates stored
+       in tests/etc/selenium/tests. It expects your favorite servlet
+       container up & running on ${tomcat.protocol}://${tomcat.host}:${tomcat.port} 
+       For this reason, these properties must be set up in your 
+       build.properties file.
+  -->
+
+  <macrodef name="webtest-exec">
+    <attribute name="context"/>
     <sequential>
-      <ant dir="${basedir}" antfile="tests/etc/webtests.xml"
-        target="webtest-teardown" inheritRefs="true">
-        <property name="webtest.context" value="@{context}" />
-      </ant>
+      <!-- If already running, shut down the embedded Jetty server by pinging the shutdown
port -->
+      <echo message="Shutting down Jetty (if it is up)."/>
+      <get src="http://localhost:${webtests.shutdown}/" dest="${webtests.temp}/shutdown.log"
+        ignoreerrors="true" verbose="true" />
+      <sleep seconds="2"/>
+
+      <!-- Start Jetty with our test context -->
+      <echo message="Starting Jetty."/>
+      <java classname="com.ecyrd.jspwiki.web.TestContainer" fork="true" spawn="true">
+        <classpath>
+           <path refid="path.tests" />
+        </classpath>
+        <sysproperty key="java.io.tmpdir" value="${webtests.temp}" />
+        <!--
+        <jvmarg value="-Xdebug" />
+        <jvmarg value="-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
/>
+        -->
+        <arg line="@{context}=${webtests.build}/@{context}/webapp" />
+      </java>
+
+      <!-- Start Selenium tests -->
+      <echo message="Running web unit tests for context '@{context}'."/>
+      <java jar="tests/lib/selenium-server-0.9.2-patched.jar" fork="true"
+        output="${webtests.build}/@{context}/selenium/selenium.log">
+        <!--
+        <arg line="-browserSessionReuse" />
+        -->
+        <arg line="-htmlSuite" />
+        <arg line='"${webtests.browser}"' />
+        <arg line='"http://localhost:${webtests.port}"' />
+        <arg line="${basedir}/${webtests.build}/@{context}/selenium/TestSuite.html" />
+        <arg line="${webtests.reports}/@{context}.html" />
+      </java>
     </sequential>
   </macrodef>
-  
-  <macrodef name="webtest-selenium">
-	<attribute name="context" />
-	<sequential>
-	  <ant dir="${basedir}" antfile="tests/etc/webtests.xml"
-	    target="webtest-selenium-exec" inheritRefs="true">
-	    <property name="webtest.context" value="@{context}" />
-	  </ant>
-	</sequential>
-  </macrodef>
-
 
   <!-- ============================================================== -->
 



Mime
View raw message