You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2011/07/25 16:45:39 UTC
svn commit: r1150727 - in /tomcat/trunk/test/org/apache/catalina:
session/Benchmarks.java session/Threading.java
startup/TestContextConfigAnnotation.java util/TestContextName.java
util/TestRequestUtil.java util/TestServerInfo.java
Author: kkolinko
Date: Mon Jul 25 14:45:37 2011
New Revision: 1150727
URL: http://svn.apache.org/viewvc?rev=1150727&view=rev
Log:
Converted the tests to JUnit 4.
Modified:
tomcat/trunk/test/org/apache/catalina/session/Benchmarks.java
tomcat/trunk/test/org/apache/catalina/session/Threading.java
tomcat/trunk/test/org/apache/catalina/startup/TestContextConfigAnnotation.java
tomcat/trunk/test/org/apache/catalina/util/TestContextName.java
tomcat/trunk/test/org/apache/catalina/util/TestRequestUtil.java
tomcat/trunk/test/org/apache/catalina/util/TestServerInfo.java
Modified: tomcat/trunk/test/org/apache/catalina/session/Benchmarks.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/session/Benchmarks.java?rev=1150727&r1=1150726&r2=1150727&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/session/Benchmarks.java (original)
+++ tomcat/trunk/test/org/apache/catalina/session/Benchmarks.java Mon Jul 25 14:45:37 2011
@@ -22,19 +22,19 @@ import java.io.IOException;
import java.io.InputStream;
import java.security.SecureRandom;
-import junit.framework.TestCase;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.Session;
-
import org.apache.catalina.core.StandardContext;
-
/**
* Named Benchmarks so it is not automatically executed as part of the unit
* tests.
*/
-public class Benchmarks extends TestCase {
+public class Benchmarks {
/*
* Results on markt's 4-core Windows dev box
@@ -49,6 +49,7 @@ public class Benchmarks extends TestCase
* 4 threads - ~3,500ms
* 16 threads - ~14,465ms
*/
+ @Test
public void testManagerBaseGenerateSessionId() throws Exception {
doTestManagerBaseGenerateSessionId(1, 1000000);
doTestManagerBaseGenerateSessionId(1, 1000000);
@@ -146,6 +147,7 @@ public class Benchmarks extends TestCase
* 4 threads - ~11,700ms
* 16 threads - ~45,600ms
*/
+ @Test
public void testManagerBaseCreateSession() throws LifecycleException {
doTestManagerBaseCreateSession(1, 1000000);
doTestManagerBaseCreateSession(2, 1000000);
@@ -240,6 +242,7 @@ public class Benchmarks extends TestCase
* 2 threads - ~725ms ~5,200ms
* 4 threads - ~1,265ms ~10,500ms
*/
+ @Test
public void testSecureRandomVsDevURandom() throws Exception {
doTestSecureRandomVsDevURandom(1, 1000000);
doTestSecureRandomVsDevURandom(2, 1000000);
Modified: tomcat/trunk/test/org/apache/catalina/session/Threading.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/session/Threading.java?rev=1150727&r1=1150726&r2=1150727&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/session/Threading.java (original)
+++ tomcat/trunk/test/org/apache/catalina/session/Threading.java Mon Jul 25 14:45:37 2011
@@ -20,7 +20,9 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
-import junit.framework.TestCase;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
/**
* The design of the session manager depends on the thread-safety - or not - of
@@ -31,18 +33,21 @@ import junit.framework.TestCase;
* Named Threading so it is not automatically executed as part of the unit
* tests.
*/
-public class Threading extends TestCase {
+public class Threading {
/**
* {@link FileInputStream#read(byte[])} and related methods are all native
* methods so it isn't immediately obvious if they are thread-safe or not.
*
+ * <pre>
* Windows JDK 1.6.0_22_x64 - Thread safe
* OSX JDK 1.6.0_22_x64 - Not thread safe
+ * </pre>
*
* Therefore, have to assume that {@link FileInputStream#read(byte[])} is
* not thread safe.
*/
+ @Test
public void testFileInputStream() throws Exception {
doTestFileInputStream(1);
doTestFileInputStream(2);
@@ -55,7 +60,7 @@ public class Threading extends TestCase
// Assumes "ant release" has been run
// Will need to be updated as new releases are made
File file = new File(
- "./output/release/v7.0.6-dev/bin/apache-tomcat-7.0.6-dev.zip");
+ "./output/release/v7.0.20-dev/bin/apache-tomcat-7.0.20-dev.zip");
FileInputStream fis = new FileInputStream(file);
Modified: tomcat/trunk/test/org/apache/catalina/startup/TestContextConfigAnnotation.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestContextConfigAnnotation.java?rev=1150727&r1=1150726&r2=1150727&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/TestContextConfigAnnotation.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TestContextConfigAnnotation.java Mon Jul 25 14:45:37 2011
@@ -28,7 +28,13 @@ import javax.servlet.ServletContainerIni
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
import org.apache.catalina.Container;
import org.apache.catalina.Loader;
@@ -45,8 +51,9 @@ import org.apache.catalina.deploy.WebXml
* @author Peter Rossbach
* @version $Revision$
*/
-public class TestContextConfigAnnotation extends TestCase {
+public class TestContextConfigAnnotation {
+ @Test
public void testAnnotation() throws Exception {
WebXml webxml = new WebXml();
ContextConfig config = new ContextConfig();
@@ -72,6 +79,7 @@ public class TestContextConfigAnnotation
}
+ @Test
public void testOverwriteAnnotation() throws Exception {
WebXml webxml = new WebXml();
ServletDef servletDef = new ServletDef();
@@ -111,6 +119,7 @@ public class TestContextConfigAnnotation
assertNull(servletDef.getJspFile());
}
+ @Test
public void testNoMapping() throws Exception {
WebXml webxml = new WebXml();
ContextConfig config = new ContextConfig();
@@ -128,6 +137,7 @@ public class TestContextConfigAnnotation
}
+ @Test
public void testSetupWebXMLNoMapping() throws Exception {
WebXml webxml = new WebXml();
ServletDef servletDef = new ServletDef();
@@ -150,6 +160,7 @@ public class TestContextConfigAnnotation
assertEquals(servletDef, servletDef1);
}
+ @Test
public void testDuplicateMapping() throws Exception {
WebXml webxml = new WebXml();
ContextConfig config = new ContextConfig();
@@ -166,6 +177,7 @@ public class TestContextConfigAnnotation
assertNull(servletDef);
}
+ @Test
public void testFilterMapping() throws Exception {
WebXml webxml = new WebXml();
ContextConfig config = new ContextConfig();
@@ -180,6 +192,7 @@ public class TestContextConfigAnnotation
assertEquals("Servlet says: ",fdef.getParameterMap().get("message"));
}
+ @Test
public void testOverwriteFilterMapping() throws Exception {
WebXml webxml = new WebXml();
FilterDef filterDef = new FilterDef();
@@ -234,6 +247,7 @@ public class TestContextConfigAnnotation
}
+ @Test
public void testDuplicateFilterMapping() throws Exception {
WebXml webxml = new WebXml();
ContextConfig config = new ContextConfig();
@@ -250,6 +264,7 @@ public class TestContextConfigAnnotation
assertNull(filterDef);
}
+ @Test
public void testCheckHandleTypes() throws Exception {
ContextConfig config = new ContextConfig();
Modified: tomcat/trunk/test/org/apache/catalina/util/TestContextName.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/util/TestContextName.java?rev=1150727&r1=1150726&r2=1150727&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/util/TestContextName.java (original)
+++ tomcat/trunk/test/org/apache/catalina/util/TestContextName.java Mon Jul 25 14:45:37 2011
@@ -16,9 +16,13 @@
*/
package org.apache.catalina.util;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
-public class TestContextName extends TestCase {
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class TestContextName {
private ContextName cn1;
private ContextName cn2;
@@ -37,9 +41,8 @@ public class TestContextName extends Tes
private ContextName cn15;
private ContextName cn16;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
cn1 = new ContextName(null, null);
cn2 = new ContextName("", null);
cn3 = new ContextName("/", null);
@@ -58,6 +61,7 @@ public class TestContextName extends Tes
cn16 = new ContextName("foo#bar##E");
}
+ @Test
public void testGetBaseName() {
assertEquals("ROOT", cn1.getBaseName());
assertEquals("ROOT", cn2.getBaseName());
@@ -77,6 +81,7 @@ public class TestContextName extends Tes
assertEquals("foo#bar##E", cn16.getBaseName());
}
+ @Test
public void testGetPath() {
assertEquals("", cn1.getPath());
assertEquals("", cn2.getPath());
@@ -96,6 +101,7 @@ public class TestContextName extends Tes
assertEquals("/foo/bar", cn16.getPath());
}
+ @Test
public void testGetVersion() {
assertEquals("", cn1.getVersion());
assertEquals("", cn2.getVersion());
@@ -115,6 +121,7 @@ public class TestContextName extends Tes
assertEquals("E", cn16.getVersion());
}
+ @Test
public void testGetName() {
assertEquals("", cn1.getName());
assertEquals("", cn2.getName());
@@ -134,6 +141,7 @@ public class TestContextName extends Tes
assertEquals("/foo/bar##E", cn16.getName());
}
+ @Test
public void testGetDisplayName() {
assertEquals("/", cn1.getDisplayName());
assertEquals("/", cn2.getDisplayName());
@@ -153,6 +161,7 @@ public class TestContextName extends Tes
assertEquals("/foo/bar##E", cn16.getDisplayName());
}
+ @Test
public void testConstructorString() {
doTestConstructorString(cn1);
doTestConstructorString(cn2);
Modified: tomcat/trunk/test/org/apache/catalina/util/TestRequestUtil.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/util/TestRequestUtil.java?rev=1150727&r1=1150726&r2=1150727&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/util/TestRequestUtil.java (original)
+++ tomcat/trunk/test/org/apache/catalina/util/TestRequestUtil.java Mon Jul 25 14:45:37 2011
@@ -17,10 +17,14 @@
package org.apache.catalina.util;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
-public class TestRequestUtil extends TestCase {
+import org.junit.Test;
+public class TestRequestUtil {
+
+ @Test
public void testNormalizeString() {
assertEquals("/something",RequestUtil.normalize("//something"));
assertEquals("/some/thing",RequestUtil.normalize("some//thing"));
@@ -28,6 +32,7 @@ public class TestRequestUtil extends Tes
assertEquals("/",RequestUtil.normalize("//"));
}
+ @Test
public void testURLDecodeStringInvalid() {
// %n rather than %nn should throw an IAE according to the Javadoc
Exception exception = null;
@@ -48,35 +53,41 @@ public class TestRequestUtil extends Tes
assertTrue(exception instanceof IllegalArgumentException);
}
+ @Test
public void testURLDecodeStringValidIso88591Start() {
String result = RequestUtil.URLDecode("%41xxxx", "ISO-8859-1");
assertEquals("Axxxx", result);
}
+ @Test
public void testURLDecodeStringValidIso88591Middle() {
String result = RequestUtil.URLDecode("xx%41xx", "ISO-8859-1");
assertEquals("xxAxx", result);
}
+ @Test
public void testURLDecodeStringValidIso88591End() {
String result = RequestUtil.URLDecode("xxxx%41", "ISO-8859-1");
assertEquals("xxxxA", result);
}
+ @Test
public void testURLDecodeStringValidUtf8Start() {
String result = RequestUtil.URLDecode("%c3%aaxxxx", "UTF-8");
assertEquals("\u00eaxxxx", result);
}
+ @Test
public void testURLDecodeStringValidUtf8Middle() {
String result = RequestUtil.URLDecode("xx%c3%aaxx", "UTF-8");
assertEquals("xx\u00eaxx", result);
}
+ @Test
public void testURLDecodeStringValidUtf8End() {
String result = RequestUtil.URLDecode("xxxx%c3%aa", "UTF-8");
Modified: tomcat/trunk/test/org/apache/catalina/util/TestServerInfo.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/util/TestServerInfo.java?rev=1150727&r1=1150726&r2=1150727&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/util/TestServerInfo.java (original)
+++ tomcat/trunk/test/org/apache/catalina/util/TestServerInfo.java Mon Jul 25 14:45:37 2011
@@ -17,13 +17,14 @@
package org.apache.catalina.util;
-import junit.framework.TestCase;
+import org.junit.Test;
-public class TestServerInfo extends TestCase {
+public class TestServerInfo {
/**
* Test that prints the server version info.
*/
+ @Test
public void testServerInfo() {
ServerInfo.main(new String[0]);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org