310703 - Update test suite to JUnit4 - Module tests/test-integration

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1616 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Joakim Erdfelt 2010-04-27 20:06:51 +00:00
parent 5dc89af42e
commit 1755a8c069
9 changed files with 323 additions and 62 deletions

View File

@ -1,4 +1,5 @@
jetty-7.1.0.RC1-SNAPSHOT
+ 310703 Update test suite to JUnit4 - Module tests/test-integration
+ 308848 Update test suite to JUnit4 - Module jetty-ajp
+ 308869 Update test suite to JUnit4 - Module jetty-xml
+ 308868 Update test suite to JUnit4 - Module jetty-websocket

View File

@ -75,7 +75,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
<version>${junit4-version}</version>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -0,0 +1,220 @@
// ========================================================================
// Copyright (c) Webtide LLC
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.apache.org/licenses/LICENSE-2.0.txt
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.test;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import junit.framework.TestCase;
import org.eclipse.jetty.util.IO;
/**
* Common utility methods for working with JUnit tests cases in a maven friendly way.
*/
public class MavenTestingUtils
{
private static File basedir;
private static File testResourcesDir;
private static File targetDir;
// private static Boolean surefireRunning;
public static File getBasedir()
{
if (basedir == null)
{
String cwd = System.getProperty("basedir");
if (cwd == null)
{
cwd = System.getProperty("user.dir");
}
basedir = new File(cwd);
}
return basedir;
}
/**
* Get the directory to the /target directory for this project.
*
* @return the directory path to the target directory.
*/
public static File getTargetDir()
{
if (targetDir == null)
{
targetDir = new File(getBasedir(),"target");
PathAssert.assertDirExists("Target Dir",targetDir);
}
return targetDir;
}
/**
* Create a {@link File} object for a path in the /target directory.
*
* @param path
* the path desired, no validation of existence is performed.
* @return the File to the path.
*/
public static File getTargetFile(String path)
{
return new File(getTargetDir(),path.replace("/",File.separator));
}
public static File getTargetTestingDir()
{
File dir = new File(getTargetDir(),"testing");
if (!dir.exists())
{
dir.mkdirs();
}
return dir;
}
/**
* Get a dir in /target/ that uses the JUnit 3.x {@link TestCase#getName()} to make itself unique.
*
* @param test
* the junit 3.x testcase to base this new directory on.
* @return
*/
public static File getTargetTestingDir(TestCase test)
{
return getTargetTestingDir(test.getName());
}
/**
* Get a dir in /target/ that uses the an arbitrary name.
*
* @param testname
* the testname to create directory against.
* @return
*/
public static File getTargetTestingDir(String testname)
{
File dir = new File(getTargetDir(),"test-" + testname);
return dir;
}
/**
* Get a dir from the src/test/resource directory.
*
* @param name
* the name of the path to get (it must exist as a dir)
* @return the dir in src/test/resource
*/
public static File getTestResourceDir(String name)
{
File dir = new File(getTestResourcesDir(),name);
PathAssert.assertDirExists("Test Resource Dir",dir);
return dir;
}
/**
* Get a file from the src/test/resource directory.
*
* @param name
* the name of the path to get (it must exist as a file)
* @return the file in src/test/resource
*/
public static File getTestResourceFile(String name)
{
File file = new File(getTestResourcesDir(),name);
PathAssert.assertFileExists("Test Resource File",file);
return file;
}
/**
* Get a path resource (File or Dir) from the src/test/resource directory.
*
* @param name
* the name of the path to get (it must exist)
* @return the path in src/test/resource
*/
public static File getTestResourcePath(String name)
{
File path = new File(getTestResourcesDir(),name);
PathAssert.assertExists("Test Resource Path",path);
return path;
}
/**
* Get the directory to the src/test/resource directory
*
* @return the directory {@link File} to the src/test/resources directory
*/
public static File getTestResourcesDir()
{
if (testResourcesDir == null)
{
testResourcesDir = new File(basedir,"src/test/resources".replace("/",File.separator));
PathAssert.assertDirExists("Test Resources Dir",testResourcesDir);
}
return testResourcesDir;
}
/**
* Read the contents of a file into a String and return it.
*
* @param file
* the file to read.
* @return the contents of the file.
* @throws IOException
* if unable to read the file.
*/
public static String readToString(File file) throws IOException
{
FileReader reader = null;
try
{
reader = new FileReader(file);
return IO.toString(reader);
}
finally
{
IO.close(reader);
}
}
public static String getTestID()
{
StackTraceElement stacked[] = new Throwable().getStackTrace();
String name = null;
for (StackTraceElement stack : stacked)
{
if (stack.getClassName().endsWith("Test"))
{
name = stack.getClassName();
if (stack.getMethodName().startsWith("test"))
{
return stack.getClassName() + "#" + stack.getMethodName();
}
}
}
if (name == null)
{
return "Unidentified_Test";
}
return name;
}
}

View File

@ -0,0 +1,40 @@
// ========================================================================
// Copyright (c) Webtide LLC
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.apache.org/licenses/LICENSE-2.0.txt
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.test;
import java.io.File;
import org.junit.Assert;
public class PathAssert
{
public static void assertDirExists(String msg, File path)
{
assertExists(msg,path);
Assert.assertTrue(msg + " path should be a Dir : " + path.getAbsolutePath(),path.isDirectory());
}
public static void assertFileExists(String msg, File path)
{
assertExists(msg,path);
Assert.assertTrue(msg + " path should be a File : " + path.getAbsolutePath(),path.isFile());
}
public static void assertExists(String msg, File path)
{
Assert.assertTrue(msg + " path should exist: " + path.getAbsolutePath(),path.exists());
}
}

View File

@ -16,20 +16,19 @@
package org.eclipse.jetty.test.rfcs;
import java.io.IOException;
import org.eclipse.jetty.http.HttpSchemes;
import org.eclipse.jetty.test.support.TestableJettyServer;
import org.eclipse.jetty.test.support.rawhttp.HttpSocket;
import org.eclipse.jetty.test.support.rawhttp.HttpSocketImpl;
import org.junit.BeforeClass;
/**
* Perform the RFC2616 tests against a server running with the Jetty BIO Connector and listening on standard HTTP.
*/
public class RFC2616BIOHttpTest extends RFC2616BaseTest
{
@Override
public TestableJettyServer getJettyServer() throws IOException
@BeforeClass
public static void setupServer() throws Exception
{
TestableJettyServer server = new TestableJettyServer();
server.setScheme(HttpSchemes.HTTP);
@ -37,7 +36,7 @@ public class RFC2616BIOHttpTest extends RFC2616BaseTest
server.addConfiguration("RFC2616_Redirects.xml");
server.addConfiguration("RFC2616_Filters.xml");
server.addConfiguration("BIOHttp.xml");
return server;
setUpServer(server);
}
@Override

View File

@ -16,20 +16,20 @@
package org.eclipse.jetty.test.rfcs;
import java.io.IOException;
import org.eclipse.jetty.http.HttpSchemes;
import org.eclipse.jetty.test.support.TestableJettyServer;
import org.eclipse.jetty.test.support.rawhttp.HttpSocket;
import org.eclipse.jetty.test.support.rawhttp.HttpsSocketImpl;
import org.junit.BeforeClass;
/**
* Perform the RFC2616 tests against a server running with the Jetty BIO Connector and listening on HTTPS (HTTP over SSL).
* Perform the RFC2616 tests against a server running with the Jetty BIO Connector and listening on HTTPS (HTTP over
* SSL).
*/
public class RFC2616BIOHttpsTest extends RFC2616BaseTest
{
@Override
public TestableJettyServer getJettyServer() throws IOException
@BeforeClass
public static void setupServer() throws Exception
{
TestableJettyServer server = new TestableJettyServer();
server.setScheme(HttpSchemes.HTTPS);
@ -37,7 +37,7 @@ public class RFC2616BIOHttpsTest extends RFC2616BaseTest
server.addConfiguration("RFC2616_Redirects.xml");
server.addConfiguration("RFC2616_Filters.xml");
server.addConfiguration("BIOHttps.xml");
return server;
setUpServer(server);
}
@Override

View File

@ -32,28 +32,31 @@ import java.util.TimeZone;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.test.AbstractJettyTestCase;
import org.eclipse.jetty.test.MavenTestingUtils;
import org.eclipse.jetty.test.StringAssert;
import org.eclipse.jetty.test.support.StringUtil;
import org.eclipse.jetty.test.support.TestableJettyServer;
import org.eclipse.jetty.test.support.rawhttp.HttpResponseTester;
import org.eclipse.jetty.test.support.rawhttp.HttpSocket;
import org.eclipse.jetty.test.support.rawhttp.HttpTesting;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* <a href="http://tools.ietf.org/html/rfc2616">RFC 2616</a> (HTTP/1.1) Test Case
*/
public abstract class RFC2616BaseTest extends AbstractJettyTestCase
public abstract class RFC2616BaseTest
{
private static final String ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n";
/** STRICT RFC TESTS */
private static final boolean STRICT = false;
private static TestableJettyServer server;
private List<HttpResponseTester> responses;
private HttpResponseTester response;
private HttpTesting http;
private TestableJettyServer server;
class TestFile
{
@ -78,13 +81,12 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
}
}
@Override
@Before
public void setUp() throws Exception
public static void setUpServer(TestableJettyServer testableserver) throws Exception
{
super.setUp();
File testWorkDir = new File(getTargetDir(),"work" + File.separator + getClass().getSimpleName() + File.separator + getName());
File targetDir = MavenTestingUtils.getTargetDir();
String testId = MavenTestingUtils.getTestID();
File testWorkDir = new File(targetDir,"work" + File.separator + testId);
if (!testWorkDir.exists())
{
testWorkDir.mkdirs();
@ -92,22 +94,23 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
System.setProperty("java.io.tmpdir",testWorkDir.getAbsolutePath());
server = getJettyServer();
server = testableserver;
server.load();
server.start();
}
@Before
public void setUp() throws Exception
{
http = new HttpTesting(getHttpClientSocket(),server.getServerPort());
}
@Override
@After
public void tearDown() throws Exception
@AfterClass
public static void tearDownServer() throws Exception
{
server.stop();
super.tearDown();
}
public abstract TestableJettyServer getJettyServer() throws IOException;
public abstract HttpSocket getHttpClientSocket() throws Exception;
/**
@ -145,7 +148,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
// Test formatting
fields.putDateField("Date",expected.getTime().getTime());
assertEquals("3.3.1 RFC 822 preferred","Sun, 06 Nov 1994 08:49:37 GMT",fields.getStringField("Date"));
Assert.assertEquals("3.3.1 RFC 822 preferred","Sun, 06 Nov 1994 08:49:37 GMT",fields.getStringField("Date"));
}
/**
@ -201,7 +204,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
req2.append("\n");
responses = http.requests(req2);
assertEquals("Response Count",3,responses.size());
Assert.assertEquals("Response Count",3,responses.size());
response = responses.get(0); // Response 1
response.assertStatusOK("3.6.1 Transfer Codings / Response 1 Code");
@ -246,7 +249,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
req3.append("\n");
responses = http.requests(req3);
assertEquals("Response Count",3,responses.size());
Assert.assertEquals("Response Count",3,responses.size());
response = responses.get(0); // Response 1
response.assertStatusOK("3.6.1 Transfer Codings / Response 1 Code");
@ -281,7 +284,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
req4.append("\n");
responses = http.requests(req4);
assertEquals("Response Count",2,responses.size());
Assert.assertEquals("Response Count",2,responses.size());
response = responses.get(0); // Response 1
response.assertStatusOK("3.6.1 Transfer Codings / Response 1 Code");
@ -305,12 +308,12 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
fields.put("Q","bbb;q=0.5,aaa,ccc;q=0.002,d;q=0,e;q=0.0001,ddd;q=0.001,aa2,abb;q=0.7");
Enumeration<String> qualities = fields.getValues("Q",", \t");
List<?> list = HttpFields.qualityList(qualities);
assertEquals("Quality parameters","aaa",HttpFields.valueParameters(list.get(0).toString(),null));
assertEquals("Quality parameters","aa2",HttpFields.valueParameters(list.get(1).toString(),null));
assertEquals("Quality parameters","abb",HttpFields.valueParameters(list.get(2).toString(),null));
assertEquals("Quality parameters","bbb",HttpFields.valueParameters(list.get(3).toString(),null));
assertEquals("Quality parameters","ccc",HttpFields.valueParameters(list.get(4).toString(),null));
assertEquals("Quality parameters","ddd",HttpFields.valueParameters(list.get(5).toString(),null));
Assert.assertEquals("Quality parameters","aaa",HttpFields.valueParameters(list.get(0).toString(),null));
Assert.assertEquals("Quality parameters","aa2",HttpFields.valueParameters(list.get(1).toString(),null));
Assert.assertEquals("Quality parameters","abb",HttpFields.valueParameters(list.get(2).toString(),null));
Assert.assertEquals("Quality parameters","bbb",HttpFields.valueParameters(list.get(3).toString(),null));
Assert.assertEquals("Quality parameters","ccc",HttpFields.valueParameters(list.get(4).toString(),null));
Assert.assertEquals("Quality parameters","ddd",HttpFields.valueParameters(list.get(5).toString(),null));
}
/**
@ -340,7 +343,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
req1.append("\n");
responses = http.requests(req1);
assertEquals("Response Count",2,responses.size());
Assert.assertEquals("Response Count",2,responses.size());
response = responses.get(0);
response.assertStatusOK("4.4.2 Message Length / Response Code");
@ -377,7 +380,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
req2.append("7890AB");
responses = http.requests(req2);
assertEquals("Response Count",2,responses.size());
Assert.assertEquals("Response Count",2,responses.size());
response = responses.get(0); // response 1
response.assertStatusOK("4.4.3 Ignore Content-Length / Response Code");
@ -630,7 +633,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
req2.append("\n");
responses = http.requests(req2);
assertEquals("Response Count",2,responses.size()); // Should not have a R3 response.
Assert.assertEquals("Response Count",2,responses.size()); // Should not have a R3 response.
response = responses.get(0); // response 1
response.assertStatusOK("8.1 Persistent Connections");
@ -838,7 +841,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
responses = http.requests(req2);
assertEquals("Response Count",2,responses.size()); // Should have 2 responses
Assert.assertEquals("Response Count",2,responses.size()); // Should have 2 responses
response = responses.get(0); // Only interested in first response
response.assertHeaderExists("9.2 OPTIONS","Allow");
@ -1070,7 +1073,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
req2.append("\n");
responses = http.requests(req2);
assertEquals("Response Count",2,responses.size());
Assert.assertEquals("Response Count",2,responses.size());
response = responses.get(0);
String specId = "10.3 Redirection HTTP/1.1 - basic (response 1)";
@ -1522,16 +1525,16 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
if (parts[i].trim().startsWith("boundary="))
{
String boundparts[] = StringUtil.split(parts[i],'=');
assertEquals(msg + " Boundary parts.length",2,boundparts.length);
Assert.assertEquals(msg + " Boundary parts.length",2,boundparts.length);
boundary = boundparts[1];
}
}
assertNotNull(msg + " Should have found boundary in Content-Type header",boundary);
Assert.assertNotNull(msg + " Should have found boundary in Content-Type header",boundary);
// Find boundary offsets within body
List<HttpResponseTester> multiparts = response.findBodyMultiparts(boundary);
assertEquals(msg + " multiparts in body (count)",2,multiparts.size());
Assert.assertEquals(msg + " multiparts in body (count)",2,multiparts.size());
// Validate multipart #1
HttpResponseTester multipart1 = multiparts.get(0);
@ -1584,16 +1587,16 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
if (parts[i].trim().startsWith("boundary="))
{
String boundparts[] = StringUtil.split(parts[i],'=');
assertEquals(msg + " Boundary parts.length",2,boundparts.length);
Assert.assertEquals(msg + " Boundary parts.length",2,boundparts.length);
boundary = boundparts[1];
}
}
assertNotNull(msg + " Should have found boundary in Content-Type header",boundary);
Assert.assertNotNull(msg + " Should have found boundary in Content-Type header",boundary);
// Find boundary offsets within body
List<HttpResponseTester> multiparts = response.findBodyMultiparts(boundary);
assertEquals(msg + " multiparts in body (count)",3,multiparts.size());
Assert.assertEquals(msg + " multiparts in body (count)",3,multiparts.size());
// Validate multipart #1
HttpResponseTester multipart1 = multiparts.get(0);
@ -1767,7 +1770,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
responses = http.requests(req2);
// Since R2 closes the connection, should only get 2 responses (R1 &
// R2), not (R3)
assertEquals("Response Count",2,responses.size());
Assert.assertEquals("Response Count",2,responses.size());
response = responses.get(0); // response 1
specId = "19.6.2 Compatibility with previous HTTP - Keep-alive";
@ -1808,7 +1811,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
req3.append("Connection: close\n");
req3.append("\n");
responses = http.requests(req3);
assertEquals("Response Count",3,responses.size());
Assert.assertEquals("Response Count",3,responses.size());
specId = "19.6.2 Compatibility with HTTP/1.0- Keep-alive";
response = responses.get(0);
@ -1834,6 +1837,6 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
String actual = sdf.format(new Date(actualTime));
String expected = sdf.format(expectedTime.getTime());
assertEquals(msg,expected,actual);
Assert.assertEquals(msg,expected,actual);
}
}

View File

@ -16,20 +16,19 @@
package org.eclipse.jetty.test.rfcs;
import java.io.IOException;
import org.eclipse.jetty.http.HttpSchemes;
import org.eclipse.jetty.test.support.TestableJettyServer;
import org.eclipse.jetty.test.support.rawhttp.HttpSocket;
import org.eclipse.jetty.test.support.rawhttp.HttpSocketImpl;
import org.junit.BeforeClass;
/**
* Perform the RFC2616 tests against a server running with the Jetty NIO Connector and listening on standard HTTP.
*/
public class RFC2616NIOHttpTest extends RFC2616BaseTest
{
@Override
public TestableJettyServer getJettyServer() throws IOException
@BeforeClass
public static void setupServer() throws Exception
{
TestableJettyServer server = new TestableJettyServer();
server.setScheme(HttpSchemes.HTTP);
@ -37,7 +36,7 @@ public class RFC2616NIOHttpTest extends RFC2616BaseTest
server.addConfiguration("RFC2616_Redirects.xml");
server.addConfiguration("RFC2616_Filters.xml");
server.addConfiguration("NIOHttp.xml");
return server;
setUpServer(server);
}
@Override

View File

@ -16,20 +16,19 @@
package org.eclipse.jetty.test.rfcs;
import java.io.IOException;
import org.eclipse.jetty.http.HttpSchemes;
import org.eclipse.jetty.test.support.TestableJettyServer;
import org.eclipse.jetty.test.support.rawhttp.HttpSocket;
import org.eclipse.jetty.test.support.rawhttp.HttpsSocketImpl;
import org.junit.BeforeClass;
/**
* Perform the RFC2616 tests against a server running with the Jetty NIO Connector and listening on HTTPS (HTTP over SSL).
*/
public class RFC2616NIOHttpsTest extends RFC2616BaseTest
{
@Override
public TestableJettyServer getJettyServer() throws IOException
@BeforeClass
public static void setupServer() throws Exception
{
TestableJettyServer server = new TestableJettyServer();
server.setScheme(HttpSchemes.HTTPS);
@ -37,7 +36,7 @@ public class RFC2616NIOHttpsTest extends RFC2616BaseTest
server.addConfiguration("RFC2616_Redirects.xml");
server.addConfiguration("RFC2616_Filters.xml");
server.addConfiguration("NIOHttps.xml");
return server;
setUpServer(server);
}
@Override