Author: markt
Date: Thu Jul 22 12:18:59 2010
New Revision: 966613
URL: http://svn.apache.org/viewvc?rev=966613&view=rev
Log:
Run all unit tests will all connectors
Modified:
tomcat/trunk/build.xml
tomcat/trunk/test/org/apache/catalina/startup/TestTomcatSSL.java
tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/build.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/build.xml?rev=966613&r1=966612&r2=966613&view=diff
==============================================================================
--- tomcat/trunk/build.xml (original)
+++ tomcat/trunk/build.xml Thu Jul 22 12:18:59 2010
@@ -928,39 +928,72 @@
</target>
<target name="test" description="Runs the JUnit test cases"
- depends="test-compile,deploy" >
+ depends="test-bio,test-nio,test-apr" >
+ </target>
+
+ <target name="test-bio" description="Runs the JUnit test cases for BIO"
+ depends="test-compile,deploy" >
+ <runtests protocol="org.apache.coyote.http11.Http11Protocol"
+ extension=".BIO.txt" />
+ </target>
+
+ <target name="test-nio" description="Runs the JUnit test cases for NIO"
+ depends="test-compile,deploy" >
+ <runtests protocol="org.apache.coyote.http11.Http11NioProtocol"
+ extension=".NIO.txt" />
+ </target>
+
+ <target name="test-apr" description="Runs the JUnit test cases for APR"
+ depends="test-compile,deploy,test-apr-exists"
+ if="${apr.exists}">
+ <runtests protocol="org.apache.coyote.http11.Http11AprProtocol"
+ extension=".APR.txt" />
+ </target>
+
+ <target name="test-apr-exists" description="Checks for APR lib">
+ <available file="${tomcat.build}/bin/native" property="apr.exists" />
+ </target>
+
+ <macrodef name="runtests"
+ description="Runs the unit tests using the specified connector" >
+ <attribute name="protocol"
+ description="The class name for the connector protocol"/>
+ <attribute name="extension"
+ description="The extension to use to distinguish the output"/>
- <junit printsummary="yes" fork="yes" dir="." showoutput="yes">
+ <sequential>
+ <junit printsummary="yes" fork="yes" dir="." showoutput="yes">
- <jvmarg value="-Dsun.security.ssl.allowUnsafeRenegotiation=true" />
- <jvmarg value="-Djava.library.path=${tomcat.build}/bin/native"/>
+ <jvmarg value="-Djava.library.path=${tomcat.build}/bin/native"/>
- <classpath refid="tomcat.test.classpath" />
+ <classpath refid="tomcat.test.classpath" />
- <sysproperty key="tomcat.test.temp" value="${test.temp}" />
- <sysproperty key="tomcat.test.tomcatbuild" value="${tomcat.build}" />
-
- <formatter type="plain" usefile="true" />
-
- <!-- If test.entry is defined, run a single test, otherwise run all
valid tests -->
- <test todir="${tomcat.build}/logs" name="${test.entry}" if="test.entry"/>
- <batchtest todir="${tomcat.build}/logs" unless="test.entry"
- errorproperty="test.result.error"
failureproperty="test.result.failure"
- >
- <fileset dir="test" >
- <!-- Include all by default -->
- <include name="**/Test*.java" />
- <!-- Exclude helper classes -->
- <exclude name="**/Tester*.java" />
- <!-- Exclude the tests known to fail -->
- <exclude name="org/apache/catalina/tribes/**" />
- </fileset>
- </batchtest>
- </junit>
+ <sysproperty key="tomcat.test.temp" value="${test.temp}" />
+ <sysproperty key="tomcat.test.tomcatbuild" value="${tomcat.build}" />
+ <sysproperty key="tomcat.test.protocol" value="@{protocol}" />
+
+ <formatter type="plain" usefile="true" extension="@{extension}"/>
+
+ <!-- If test.entry is defined, run a single test, otherwise run all
valid tests -->
+ <test todir="${tomcat.build}/logs" name="${test.entry}"
if="test.entry"/>
+ <batchtest todir="${tomcat.build}/logs" unless="test.entry"
+ errorproperty="test.result.error"
failureproperty="test.result.failure"
+ >
+ <fileset dir="test" >
+ <!-- Include all by default -->
+ <include name="**/Test*.java" />
+ <!-- Exclude helper classes -->
+ <exclude name="**/Tester*.java" />
+ <!-- Exclude the tests known to fail -->
+ <exclude name="org/apache/catalina/tribes/**" />
+ </fileset>
+ </batchtest>
+ </junit>
- <fail if="test.result.error" message="Some tests completed with an Error.
See ${tomcat.build}/logs for details." />
- <fail if="test.result.failure" message="Some tests completed with a
Failure. See ${tomcat.build}/logs for details." />
- </target>
+ <fail if="test.result.error" message="Some tests completed with an
Error. See ${tomcat.build}/logs for details." />
+ <fail if="test.result.failure" message="Some tests completed with a
Failure. See ${tomcat.build}/logs for details." />
+ </sequential>
+ </macrodef>
<target name="extras-prepare" >
<mkdir dir="${tomcat.extras}"/>
Modified: tomcat/trunk/test/org/apache/catalina/startup/TestTomcatSSL.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestTomcatSSL.java?rev=966613&r1=966612&r2=966613&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/TestTomcatSSL.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TestTomcatSSL.java Thu Jul 22
12:18:59 2010
@@ -30,7 +30,6 @@ import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
-import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.buf.ByteChunk;
/**
@@ -56,15 +55,7 @@ public class TestTomcatSSL extends Tomca
}
};
- private void initSsl(Tomcat tomcat, boolean nio) {
- if (nio) {
- Connector connector =
- new Connector("org.apache.coyote.http11.Http11NioProtocol");
- connector.setPort(getPort());
- tomcat.getService().addConnector(connector);
- tomcat.setConnector(connector);
- tomcat.getConnector().setProperty("sslProtocol", "tls");
- }
+ private void initSsl(Tomcat tomcat) {
String protocol = tomcat.getConnector().getProtocolHandlerClassName();
if (protocol.indexOf("Apr") == -1) {
tomcat.getConnector().setProperty("sslProtocol", "tls");
@@ -88,14 +79,6 @@ public class TestTomcatSSL extends Tomca
}
public void testSimpleSsl() throws Exception {
- simpleSsl(false);
- }
-
- public void testSimpleSslNio() throws Exception {
- simpleSsl(true);
- }
-
- public void simpleSsl(boolean nio) throws Exception {
// Install the all-trusting trust manager so https:// works
// with unsigned certs.
@@ -113,7 +96,7 @@ public class TestTomcatSSL extends Tomca
File appDir = new File(getBuildDirectory(), "webapps/examples");
tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
- initSsl(tomcat, nio);
+ initSsl(tomcat);
tomcat.start();
ByteChunk res = getUrl("https://localhost:" + getPort() +
@@ -124,19 +107,16 @@ public class TestTomcatSSL extends Tomca
boolean handshakeDone = false;
public void testRenegotiateFail() throws Exception {
- renegotiateFail(false);
- }
-
- public void renegotiateFail(boolean nio) throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File(getBuildDirectory(), "webapps/examples");
// app dir is relative to server home
tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
- initSsl(tomcat, nio);
- // Default - MITM not enabled
+ initSsl(tomcat);
+ // Default - MITM attack prevented
+
tomcat.start();
SSLContext sslCtx = SSLContext.getInstance("TLS");
sslCtx.init(null, trustAllCerts, new java.security.SecureRandom());
@@ -191,36 +171,22 @@ public class TestTomcatSSL extends Tomca
}
public void testRenegotiateWorks() throws Exception {
- renegotiateWorks(false);
- }
-
-
- // Re-negotiation not implemented in NIO
- // public void testRenegotiateWorksNio() throws Exception {
- // renegotiateWorks(true);
- // }
-
- public void testRenegotiateFailNio() throws Exception {
- renegotiateFail(true);
- }
-
-
- public void renegotiateWorks(boolean nio) throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File(getBuildDirectory(), "webapps/examples");
// app dir is relative to server home
tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
- initSsl(tomcat, nio);
+ initSsl(tomcat);
+
// Enable MITM attack
tomcat.getConnector().setAttribute("allowUnsafeLegacyRenegotiation",
"true");
tomcat.start();
String protocol = tomcat.getConnector().getProtocolHandlerClassName();
- if (protocol.indexOf("Apr") != -1) {
- return; // Not supported yet (10/05/25)
+ if (protocol.indexOf("Nio") != -1) {
+ return; // Not supported yet (2010-07-22)
}
SSLContext sslCtx = SSLContext.getInstance("TLS");
@@ -265,4 +231,11 @@ public class TestTomcatSSL extends Tomca
}
}
+
+ @Override
+ public void setUp() throws Exception {
+ // Make sure SSL renegotiation is not disabled in the JVM
+ System.setProperty("sun.security.ssl.allowUnsafeRenegotiation",
"true");
+ super.setUp();
+ }
}
Modified: tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java?rev=966613&r1=966612&r2=966613&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java Thu Jul
22 12:18:59 2010
@@ -32,6 +32,7 @@ import javax.servlet.http.HttpServletReq
import javax.servlet.http.HttpServletResponse;
import org.apache.catalina.LifecycleState;
+import org.apache.catalina.connector.Connector;
import org.apache.catalina.core.StandardServer;
import org.apache.catalina.core.AprLifecycleListener;
@@ -109,17 +110,30 @@ public abstract class TomcatBaseTest ext
tomcat = new Tomcat();
- // Add AprLifecycleListener
- StandardServer server = (StandardServer) tomcat.getServer();
- AprLifecycleListener listener = new AprLifecycleListener();
- server.addLifecycleListener(listener);
+ // Has a protocol been specified
+ String protocol = System.getProperty("tomcat.test.protocol");
- tomcat.setBaseDir(tempDir.getAbsolutePath());
- tomcat.getHost().setAppBase(appBase.getAbsolutePath());
-
+ // Use BIO by default
+ if (protocol == null) {
+ protocol = "org.apache.coyote.http11.Http11Protocol";
+ }
+
+ Connector connector = new Connector(protocol);
// If each test is running on same port - they
// may interfere with each other (on unix at least)
- tomcat.setPort(getNextPort());
+ connector.setPort(getNextPort());
+ tomcat.getService().addConnector(connector);
+ tomcat.setConnector(connector);
+
+ // Add AprLifecycleListener if we are using the Apr connector
+ if (protocol.contains("Apr")) {
+ StandardServer server = (StandardServer) tomcat.getServer();
+ AprLifecycleListener listener = new AprLifecycleListener();
+ server.addLifecycleListener(listener);
+ }
+
+ tomcat.setBaseDir(tempDir.getAbsolutePath());
+ tomcat.getHost().setAppBase(appBase.getAbsolutePath());
}
@Override
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=966613&r1=966612&r2=966613&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Jul 22 12:18:59 2010
@@ -285,6 +285,10 @@
installer, making it clear that the service will be installed. Patch
provided by sebb. (markt)
</fix>
+ <add>
+ Re-factor unit tests to enable them to be run once with each of the
HTTP
+ connector implementations (BIO, NIO and APR/native). (markt)
+ </add>
</changelog>
</subsection>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]