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@1617 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
1755a8c069
commit
500f91bbce
|
@ -1,98 +0,0 @@
|
|||
// ========================================================================
|
||||
// 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 junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
||||
public abstract class AbstractJettyTestCase extends TestCase
|
||||
{
|
||||
public static final boolean IS_ON_WINDOWS = System.getProperty("os.name").startsWith("Windows");
|
||||
private File baseDir;
|
||||
|
||||
public File getBaseDir()
|
||||
{
|
||||
if (baseDir == null)
|
||||
{
|
||||
String baseDirPath = System.getProperty("basedir");
|
||||
if (baseDirPath == null)
|
||||
{
|
||||
baseDirPath = System.getProperty("user.dir",".");
|
||||
}
|
||||
baseDir = new File(baseDirPath);
|
||||
}
|
||||
|
||||
return baseDir;
|
||||
}
|
||||
|
||||
public File getTargetDir()
|
||||
{
|
||||
File path = new File(getBaseDir(),"target");
|
||||
assertDirExists("target dir",path);
|
||||
return path;
|
||||
}
|
||||
|
||||
public File getTestResourcesDir()
|
||||
{
|
||||
File path = new File(getBaseDir(),"src/test/resources");
|
||||
assertDirExists("test resources dir",path);
|
||||
return path;
|
||||
}
|
||||
|
||||
public File getDocRootBase()
|
||||
{
|
||||
File path = new File(getTestResourcesDir(),"docroots");
|
||||
assertDirExists("docroot base dir",path);
|
||||
return path;
|
||||
}
|
||||
|
||||
public void assertDirExists(String msg, File path)
|
||||
{
|
||||
assertNotNull(msg + " should not be null",path);
|
||||
assertTrue(msg + " should exist",path.exists());
|
||||
assertTrue(msg + " should be a directory",path.isDirectory());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the port that the server is listening on.
|
||||
*
|
||||
* Assumes 1 connector, and that server is started already.
|
||||
*
|
||||
* @param server
|
||||
* the server port.
|
||||
* @return the port that the server is listening on.
|
||||
*/
|
||||
public int findServerPort(Server server)
|
||||
{
|
||||
Connector connectors[] = server.getConnectors();
|
||||
for (int i = 0; i < connectors.length; i++)
|
||||
{
|
||||
Connector connector = connectors[i];
|
||||
if (connector.getLocalPort() > 0)
|
||||
{
|
||||
return connector.getLocalPort();
|
||||
}
|
||||
}
|
||||
|
||||
throw new AssertionFailedError("No valid connector port found.");
|
||||
}
|
||||
}
|
|
@ -31,41 +31,42 @@ import org.eclipse.jetty.test.support.rawhttp.HttpResponseTester;
|
|||
import org.eclipse.jetty.test.support.rawhttp.HttpSocketImpl;
|
||||
import org.eclipse.jetty.test.support.rawhttp.HttpTesting;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests against the facilities within the TestSuite to ensure that the various
|
||||
* org.eclipse.jetty.test.support.* classes do what they are supposed to.
|
||||
*/
|
||||
public class DefaultHandlerTest extends AbstractJettyTestCase
|
||||
public class DefaultHandlerTest
|
||||
{
|
||||
private boolean debug = true;
|
||||
private TestableJettyServer server;
|
||||
private boolean debug = false;
|
||||
private static TestableJettyServer server;
|
||||
private int serverPort;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
@BeforeClass
|
||||
public static void setUpServer() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
server = new TestableJettyServer();
|
||||
server.setScheme(HttpSchemes.HTTP);
|
||||
server.addConfiguration("DefaultHandler.xml");
|
||||
|
||||
server.load();
|
||||
server.start();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void testInit() {
|
||||
serverPort = server.getServerPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
@AfterClass
|
||||
public static void tearDownServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -80,7 +81,7 @@ public class DefaultHandlerTest extends AbstractJettyTestCase
|
|||
String response = IO.toString(in);
|
||||
String expected = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n";
|
||||
|
||||
assertEquals("Response",expected,response);
|
||||
Assert.assertEquals("Response",expected,response);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -10,8 +10,6 @@ import javax.servlet.http.HttpServlet;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.jetty.client.ContentExchange;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.security.Realm;
|
||||
|
@ -34,9 +32,12 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
|
|||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.TypeUtil;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class DigestPostTest extends TestCase
|
||||
public class DigestPostTest
|
||||
{
|
||||
private static final String NC = "00000001";
|
||||
|
||||
|
@ -52,10 +53,10 @@ public class DigestPostTest extends TestCase
|
|||
"The quick brown fox jumped over the lazy dog.\n";
|
||||
|
||||
public volatile static String _received = null;
|
||||
private Server _server;
|
||||
private static Server _server;
|
||||
|
||||
@Override
|
||||
public void setUp()
|
||||
@BeforeClass
|
||||
public static void setUpServer()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -96,16 +97,13 @@ public class DigestPostTest extends TestCase
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see junit.framework.TestCase#tearDown()
|
||||
*/
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
@AfterClass
|
||||
public static void tearDownServer() throws Exception
|
||||
{
|
||||
_server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerDirectlyHTTP10() throws Exception
|
||||
{
|
||||
Socket socket = new Socket("127.0.0.1",_server.getConnectors()[0].getLocalPort());
|
||||
|
@ -122,8 +120,8 @@ public class DigestPostTest extends TestCase
|
|||
|
||||
String result = IO.toString(socket.getInputStream());
|
||||
|
||||
assertTrue(result.startsWith("HTTP/1.1 401 Unauthorized"));
|
||||
assertEquals(null,_received);
|
||||
Assert.assertTrue(result.startsWith("HTTP/1.1 401 Unauthorized"));
|
||||
Assert.assertEquals(null,_received);
|
||||
|
||||
int n=result.indexOf("nonce=");
|
||||
String nonce=result.substring(n+7,result.indexOf('"',n+7));
|
||||
|
@ -149,10 +147,11 @@ public class DigestPostTest extends TestCase
|
|||
|
||||
result = IO.toString(socket.getInputStream());
|
||||
|
||||
assertTrue(result.startsWith("HTTP/1.1 200 OK"));
|
||||
assertEquals(__message,_received);
|
||||
Assert.assertTrue(result.startsWith("HTTP/1.1 200 OK"));
|
||||
Assert.assertEquals(__message,_received);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerDirectlyHTTP11() throws Exception
|
||||
{
|
||||
Socket socket = new Socket("127.0.0.1",_server.getConnectors()[0].getLocalPort());
|
||||
|
@ -173,8 +172,8 @@ public class DigestPostTest extends TestCase
|
|||
int len=socket.getInputStream().read(buf);
|
||||
String result=new String(buf,0,len,"UTF-8");
|
||||
|
||||
assertTrue(result.startsWith("HTTP/1.1 401 Unauthorized"));
|
||||
assertEquals(null,_received);
|
||||
Assert.assertTrue(result.startsWith("HTTP/1.1 401 Unauthorized"));
|
||||
Assert.assertEquals(null,_received);
|
||||
|
||||
int n=result.indexOf("nonce=");
|
||||
String nonce=result.substring(n+7,result.indexOf('"',n+7));
|
||||
|
@ -197,10 +196,11 @@ public class DigestPostTest extends TestCase
|
|||
|
||||
result = IO.toString(socket.getInputStream());
|
||||
|
||||
assertTrue(result.startsWith("HTTP/1.1 200 OK"));
|
||||
assertEquals(__message,_received);
|
||||
Assert.assertTrue(result.startsWith("HTTP/1.1 200 OK"));
|
||||
Assert.assertEquals(__message,_received);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerWithHttpClientStringContent() throws Exception
|
||||
{
|
||||
HttpClient client = new HttpClient();
|
||||
|
@ -219,11 +219,11 @@ public class DigestPostTest extends TestCase
|
|||
client.send(ex);
|
||||
ex.waitForDone();
|
||||
|
||||
assertEquals(__message,_received);
|
||||
assertEquals(200,ex.getResponseStatus());
|
||||
Assert.assertEquals(__message,_received);
|
||||
Assert.assertEquals(200,ex.getResponseStatus());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testServerWithHttpClientStreamContent() throws Exception
|
||||
{
|
||||
HttpClient client = new HttpClient();
|
||||
|
@ -243,9 +243,8 @@ public class DigestPostTest extends TestCase
|
|||
ex.waitForDone();
|
||||
|
||||
String sent = IO.toString(new FileInputStream("src/test/resources/message.txt"));
|
||||
assertEquals(sent,_received);
|
||||
|
||||
assertEquals(200,ex.getResponseStatus());
|
||||
Assert.assertEquals(sent,_received);
|
||||
Assert.assertEquals(200,ex.getResponseStatus());
|
||||
}
|
||||
|
||||
public static class TestRealm implements Realm
|
||||
|
@ -268,6 +267,7 @@ public class DigestPostTest extends TestCase
|
|||
|
||||
public static class PostServlet extends HttpServlet
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException
|
||||
|
|
|
@ -31,7 +31,6 @@ 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;
|
||||
|
@ -42,7 +41,6 @@ import org.eclipse.jetty.test.support.rawhttp.HttpTesting;
|
|||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
|
|
@ -90,7 +90,7 @@ public class TestableJettyServer
|
|||
|
||||
public void addConfiguration(File xmlConfigFile) throws MalformedURLException
|
||||
{
|
||||
xmlConfigurations.add(xmlConfigFile.toURL());
|
||||
xmlConfigurations.add(xmlConfigFile.toURI().toURL());
|
||||
}
|
||||
|
||||
public void addConfiguration(String testConfigName) throws MalformedURLException
|
||||
|
@ -103,6 +103,7 @@ public class TestableJettyServer
|
|||
properties.setProperty(key,value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void load() throws Exception
|
||||
{
|
||||
XmlConfiguration last = null;
|
||||
|
|
|
@ -18,10 +18,12 @@ package org.eclipse.jetty.test.support.rawhttp;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.jetty.test.AbstractJettyTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpRequestTesterTest extends AbstractJettyTestCase
|
||||
public class HttpRequestTesterTest
|
||||
{
|
||||
@Test
|
||||
public void testBasicHttp10Request() throws IOException
|
||||
{
|
||||
HttpRequestTester request = new HttpRequestTester();
|
||||
|
@ -37,9 +39,10 @@ public class HttpRequestTesterTest extends AbstractJettyTestCase
|
|||
expectedRequest.append("Host: fakehost\r\n");
|
||||
expectedRequest.append("\r\n");
|
||||
|
||||
assertEquals("Basic Request",expectedRequest.toString(),rawRequest);
|
||||
Assert.assertEquals("Basic Request",expectedRequest.toString(),rawRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicHttp11Request() throws IOException
|
||||
{
|
||||
HttpRequestTester request = new HttpRequestTester();
|
||||
|
@ -59,6 +62,6 @@ public class HttpRequestTesterTest extends AbstractJettyTestCase
|
|||
expectedRequest.append("0\r\n");
|
||||
expectedRequest.append("\r\n");
|
||||
|
||||
assertEquals("Basic Request",expectedRequest.toString(),rawRequest);
|
||||
Assert.assertEquals("Basic Request",expectedRequest.toString(),rawRequest);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,10 +23,10 @@ import static org.junit.Assert.assertThat;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.test.AbstractJettyTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpResponseTesterTest extends AbstractJettyTestCase
|
||||
public class HttpResponseTesterTest
|
||||
{
|
||||
@Test
|
||||
public void testHttp11Response() throws IOException
|
||||
|
@ -46,17 +46,17 @@ public class HttpResponseTesterTest extends AbstractJettyTestCase
|
|||
HttpResponseTester response = new HttpResponseTester();
|
||||
response.parse(rawResponse);
|
||||
|
||||
assertEquals("Response.version","HTTP/1.1",response.getVersion());
|
||||
assertEquals("Response.status",200,response.getStatus());
|
||||
assertEquals("Response.reason","OK",response.getReason());
|
||||
Assert.assertEquals("Response.version","HTTP/1.1",response.getVersion());
|
||||
Assert.assertEquals("Response.status",200,response.getStatus());
|
||||
Assert.assertEquals("Response.reason","OK",response.getReason());
|
||||
|
||||
assertEquals("Response[Content-Type]","text/plain",response.getContentType());
|
||||
assertEquals("Response[Content-Length]",28,response.getLongHeader("Content-Length"));
|
||||
assertEquals("Response[Connection]","close",response.getHeader("Connection"));
|
||||
Assert.assertEquals("Response[Content-Type]","text/plain",response.getContentType());
|
||||
Assert.assertEquals("Response[Content-Length]",28,response.getLongHeader("Content-Length"));
|
||||
Assert.assertEquals("Response[Connection]","close",response.getHeader("Connection"));
|
||||
|
||||
String expected = "ABCDEFGHIJKLMNOPQRSTTUVWXYZ\n";
|
||||
|
||||
assertEquals("Response.content",expected,response.getContent().toString());
|
||||
Assert.assertEquals("Response.content",expected,response.getContent().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -93,8 +93,8 @@ public class HttpResponseTesterTest extends AbstractJettyTestCase
|
|||
rawResponse.append("\n");
|
||||
|
||||
List<HttpResponseTester> responses = HttpResponseTester.parseMulti(rawResponse);
|
||||
assertNotNull("Responses should not be null",responses);
|
||||
assertEquals("Responses.size",3,responses.size());
|
||||
Assert.assertNotNull("Responses should not be null",responses);
|
||||
Assert.assertEquals("Responses.size",3,responses.size());
|
||||
|
||||
HttpResponseTester resp1 = responses.get(0);
|
||||
resp1.assertStatusOK();
|
||||
|
|
|
@ -61,6 +61,7 @@ public class HttpsSocketImpl implements HttpSocket
|
|||
}
|
||||
} };
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
HostnameVerifier hostnameVerifier = new HostnameVerifier()
|
||||
{
|
||||
public boolean verify(String urlHostName, SSLSession session)
|
||||
|
|
Loading…
Reference in New Issue