308851 Converted all jetty-client tests to JUnit 4

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@3457 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Michael Gorovoy 2011-07-01 21:06:31 +00:00
parent 6190961f31
commit c8375b286a
12 changed files with 267 additions and 61 deletions

View File

@ -14,6 +14,10 @@
package org.eclipse.jetty.client;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.net.SocketTimeoutException;
@ -22,8 +26,6 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import junit.framework.TestCase;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Request;
@ -32,17 +34,20 @@ import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.StdErrLog;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* @version $Revision$ $Date$
*/
public abstract class AbstractHttpExchangeCancelTest extends TestCase
public abstract class AbstractHttpExchangeCancelTest
{
private Server server;
private Connector connector;
@Override
protected void setUp() throws Exception
@Before
public void setUp() throws Exception
{
server = new Server();
connector = new SelectChannelConnector();
@ -51,13 +56,15 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
server.start();
}
@Override
protected void tearDown() throws Exception
@After
public void tearDown() throws Exception
{
server.stop();
server.join();
}
/* ------------------------------------------------------------ */
@Test
public void testHttpExchangeCancelOnSend1() throws Exception
{
// One of the first things that HttpClient.send() does
@ -93,6 +100,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
assertFalse(exchange.isAssociated());
}
/* ------------------------------------------------------------ */
@Test
public void testHttpExchangeCancelOnSend2() throws Exception
{
// One of the first things that HttpClient.send() does
@ -129,6 +138,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
assertFalse(exchange.isAssociated());
}
/* ------------------------------------------------------------ */
@Test
public void testHttpExchangeCancelOnRequestCommitted() throws Exception
{
TestHttpExchange exchange = new TestHttpExchange()
@ -152,6 +163,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
assertFalse(exchange.isAssociated());
}
/* ------------------------------------------------------------ */
@Test
public void testHttpExchangeCancelOnRequestComplete() throws Exception
{
TestHttpExchange exchange = new TestHttpExchange()
@ -175,6 +188,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
assertFalse(exchange.isAssociated());
}
/* ------------------------------------------------------------ */
@Test
public void testHttpExchangeCancelOnResponseStatus() throws Exception
{
TestHttpExchange exchange = new TestHttpExchange()
@ -198,6 +213,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
assertFalse(exchange.isAssociated());
}
/* ------------------------------------------------------------ */
@Test
public void testHttpExchangeCancelOnResponseHeader() throws Exception
{
TestHttpExchange exchange = new TestHttpExchange()
@ -221,6 +238,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
assertFalse(exchange.isAssociated());
}
/* ------------------------------------------------------------ */
@Test
public void testHttpExchangeCancelOnResponseHeadersComplete() throws Exception
{
TestHttpExchange exchange = new TestHttpExchange()
@ -244,6 +263,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
assertFalse(exchange.isAssociated());
}
/* ------------------------------------------------------------ */
@Test
public void testHttpExchangeCancelOnResponseContent() throws Exception
{
TestHttpExchange exchange = new TestHttpExchange()
@ -267,6 +288,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
assertFalse(exchange.isAssociated());
}
/* ------------------------------------------------------------ */
@Test
public void testHttpExchangeCancelOnResponseComplete() throws Exception
{
TestHttpExchange exchange = new TestHttpExchange()
@ -290,6 +313,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
assertEquals(HttpExchange.STATUS_COMPLETED, status);
}
/* ------------------------------------------------------------ */
@Test
public void testHttpExchangeOnServerException() throws Exception
{
try
@ -313,6 +338,8 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
}
}
/* ------------------------------------------------------------ */
@Test
public void testHttpExchangeOnExpire() throws Exception
{
HttpClient httpClient = getHttpClient();
@ -338,15 +365,19 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
assertFalse(exchange.isAssociated());
}
/* ------------------------------------------------------------ */
protected abstract HttpClient getHttpClient();
/* ------------------------------------------------------------ */
protected Address newAddress()
{
return new Address("localhost", connector.getLocalPort());
}
/* ------------------------------------------------------------ */
private static class EmptyHandler extends AbstractHandler
{
/* ------------------------------------------------------------ */
public void handle(String path, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException
{
request.setHandled(true);
@ -382,28 +413,33 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
}
}
/* ------------------------------------------------------------ */
protected static class TestHttpExchange extends ContentExchange
{
private boolean responseCompleted;
private boolean failed = false;
private boolean expired = false;
/* ------------------------------------------------------------ */
protected TestHttpExchange()
{
super(true);
}
/* ------------------------------------------------------------ */
@Override
protected synchronized void onResponseComplete() throws IOException
{
this.responseCompleted = true;
}
/* ------------------------------------------------------------ */
public synchronized boolean isResponseCompleted()
{
return responseCompleted;
}
/* ------------------------------------------------------------ */
@Override
protected synchronized void onException(Throwable ex)
{
@ -414,17 +450,20 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
failed = true;
}
/* ------------------------------------------------------------ */
public synchronized boolean isFailed()
{
return failed;
}
/* ------------------------------------------------------------ */
@Override
protected synchronized void onExpire()
{
this.expired = true;
}
/* ------------------------------------------------------------ */
public synchronized boolean isExpired()
{
return expired;

View File

@ -14,6 +14,8 @@
package org.eclipse.jetty.client;
import static org.junit.Assert.assertNull;
import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
@ -22,13 +24,15 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import junit.framework.TestCase;
import org.junit.Test;
/* ------------------------------------------------------------ */
/**
* @version $Revision$ $Date$
*/
public class AsyncCallbackHttpExchangeTest extends TestCase
public class AsyncCallbackHttpExchangeTest
{
/* ------------------------------------------------------------ */
/**
* If the HttpExchange callbacks are called holding the lock on HttpExchange,
* it will be impossible for the callback to perform some work asynchronously
@ -37,6 +41,7 @@ public class AsyncCallbackHttpExchangeTest extends TestCase
*
* @throws Exception if the test fails
*/
@Test
public void testAsyncCallback() throws Exception
{
ExecutorService executor = Executors.newCachedThreadPool();
@ -56,22 +61,26 @@ public class AsyncCallbackHttpExchangeTest extends TestCase
}
}
/* ------------------------------------------------------------ */
private class TestHttpExchange extends HttpExchange
{
private final ExecutorService executor;
private final AtomicReference<Exception> failure;
/* ------------------------------------------------------------ */
private TestHttpExchange(ExecutorService executor, AtomicReference<Exception> failure)
{
this.executor = executor;
this.failure = failure;
}
/* ------------------------------------------------------------ */
@Override
protected void onRequestCommitted() throws IOException
{
Future<Integer> future = executor.submit(new Callable<Integer>()
{
/* ------------------------------------------------------------ */
public Integer call() throws Exception
{
// Method getStatus() reads synchronized state

View File

@ -13,11 +13,16 @@
package org.eclipse.jetty.client;
import org.junit.Before;
/* ------------------------------------------------------------ */
public class AsyncSslSecurityListenerTest extends SslSecurityListenerTest
{
/* ------------------------------------------------------------ */
@Before
@Override
protected void setUp() throws Exception
public void setUp() throws Exception
{
_type = HttpClient.CONNECTOR_SELECT_CHANNEL;
super.setUp();

View File

@ -14,7 +14,11 @@
package org.eclipse.jetty.client;
import org.junit.After;
import org.junit.Before;
/* ------------------------------------------------------------ */
/**
* @version $Revision$ $Date$
*/
@ -22,8 +26,10 @@ public class BlockingHttpExchangeCancelTest extends AbstractHttpExchangeCancelTe
{
private HttpClient httpClient;
/* ------------------------------------------------------------ */
@Before
@Override
protected void setUp() throws Exception
public void setUp() throws Exception
{
super.setUp();
httpClient = new HttpClient();
@ -31,13 +37,16 @@ public class BlockingHttpExchangeCancelTest extends AbstractHttpExchangeCancelTe
httpClient.start();
}
/* ------------------------------------------------------------ */
@After
@Override
protected void tearDown() throws Exception
public void tearDown() throws Exception
{
httpClient.stop();
super.tearDown();
}
/* ------------------------------------------------------------ */
@Override
protected HttpClient getHttpClient()
{

View File

@ -1,5 +1,7 @@
package org.eclipse.jetty.client;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.Enumeration;
@ -7,26 +9,27 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import junit.framework.TestCase;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class CachedHeadersIsolationTest extends TestCase
/* ------------------------------------------------------------ */
public class CachedHeadersIsolationTest
{
Server server;
HttpClient client;
int port;
@Override
protected void setUp() throws Exception
@Before
public void setUp() throws Exception
{
super.setUp();
server = new Server();
Connector connector = new SelectChannelConnector();
@ -35,7 +38,7 @@ public class CachedHeadersIsolationTest extends TestCase
server.setHandler(new AbstractHandler()
{
/* ------------------------------------------------------------ */
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException
{
@ -58,14 +61,16 @@ public class CachedHeadersIsolationTest extends TestCase
}
@Override
protected void tearDown() throws Exception
/* ------------------------------------------------------------ */
@After
public void tearDown() throws Exception
{
super.tearDown();
server.stop();
client.stop();
}
/* ------------------------------------------------------------ */
@Test
public void testHeaderWhenReadEarly() throws Exception
{
@ -88,6 +93,8 @@ public class CachedHeadersIsolationTest extends TestCase
assertEquals("Overwritten buffer","Value",e1.getResponseFields().getStringField("Name"));
}
/* ------------------------------------------------------------ */
@Test
public void testHeaderWhenReadLate() throws Exception
{

View File

@ -13,6 +13,9 @@
package org.eclipse.jetty.client;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
@ -27,8 +30,6 @@ import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import junit.framework.TestCase;
import org.eclipse.jetty.client.security.Realm;
import org.eclipse.jetty.client.security.SimpleRealmResolver;
import org.eclipse.jetty.http.HttpMethods;
@ -45,9 +46,11 @@ import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.IO;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class ContentExchangeTest
extends TestCase
{
private static String _content =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis felis nunc. "+
@ -71,6 +74,8 @@ public class ContentExchangeTest
private String _baseUrl;
private String _requestContent;
/* ------------------------------------------------------------ */
@Before
public void setUp()
throws Exception
{
@ -91,6 +96,8 @@ public class ContentExchangeTest
_baseUrl = _protocol+"://localhost:"+port+ "/";
}
/* ------------------------------------------------------------ */
@After
public void tearDown()
throws Exception
{
@ -101,6 +108,8 @@ public class ContentExchangeTest
}
}
/* ------------------------------------------------------------ */
@Test
public void testPut() throws Exception
{
startClient(_realm);
@ -124,6 +133,8 @@ public class ContentExchangeTest
assertEquals(_content,content);
}
/* ------------------------------------------------------------ */
@Test
public void testGet() throws Exception
{
startClient(_realm);
@ -148,6 +159,8 @@ public class ContentExchangeTest
assertEquals(_content,content);
}
/* ------------------------------------------------------------ */
@Test
public void testHead() throws Exception
{
startClient(_realm);
@ -166,6 +179,8 @@ public class ContentExchangeTest
assertEquals(HttpStatus.OK_200,responseStatus);
}
/* ------------------------------------------------------------ */
@Test
public void testPost() throws Exception
{
startClient(_realm);
@ -186,6 +201,7 @@ public class ContentExchangeTest
assertEquals(_content,_requestContent);
}
/* ------------------------------------------------------------ */
protected void configureServer(Server server)
throws Exception
{
@ -209,6 +225,7 @@ public class ContentExchangeTest
}
/* ------------------------------------------------------------ */
protected void startClient(Realm realm)
throws Exception
{
@ -221,12 +238,14 @@ public class ContentExchangeTest
_client.start();
}
/* ------------------------------------------------------------ */
protected void configureClient(HttpClient client)
throws Exception
{
client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
}
/* ------------------------------------------------------------ */
protected void stopClient()
throws Exception
{
@ -237,41 +256,49 @@ public class ContentExchangeTest
}
}
/* ------------------------------------------------------------ */
protected String getBasePath()
{
return _docRoot.getAbsolutePath();
}
/* ------------------------------------------------------------ */
protected String getBaseUrl()
{
return _baseUrl;
}
/* ------------------------------------------------------------ */
protected HttpClient getClient()
{
return _client;
}
/* ------------------------------------------------------------ */
protected Realm getRealm()
{
return _realm;
}
/* ------------------------------------------------------------ */
protected String getContent()
{
return _content;
}
/* ------------------------------------------------------------ */
protected void setProtocol(String protocol)
{
_protocol = protocol;
}
/* ------------------------------------------------------------ */
protected void setRealm(Realm realm)
{
_realm = realm;
}
/* ------------------------------------------------------------ */
public static void copyStream(InputStream in, OutputStream out)
{
try
@ -293,13 +320,16 @@ public class ContentExchangeTest
}
}
/* ------------------------------------------------------------ */
protected class TestHandler extends AbstractHandler {
private final String resourcePath;
/* ------------------------------------------------------------ */
public TestHandler(String repositoryPath) {
this.resourcePath = repositoryPath;
}
/* ------------------------------------------------------------ */
public void handle(String target, Request baseRequest,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException

View File

@ -13,6 +13,8 @@
package org.eclipse.jetty.client;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import javax.servlet.ServletException;
@ -31,94 +33,126 @@ import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.Test;
/* ------------------------------------------------------------ */
public class ErrorStatusTest
extends ContentExchangeTest
{
/* ------------------------------------------------------------ */
@Test
public void testPutBadRequest()
throws Exception
{
doPutFail(HttpStatus.BAD_REQUEST_400);
}
/* ------------------------------------------------------------ */
@Test
public void testPutUnauthorized()
throws Exception
{
doPutFail(HttpStatus.UNAUTHORIZED_401);
}
/* ------------------------------------------------------------ */
@Test
public void testPutForbidden()
throws Exception
{
doPutFail(HttpStatus.FORBIDDEN_403);
}
/* ------------------------------------------------------------ */
@Test
public void testPutNotFound()
throws Exception
{
doPutFail(HttpStatus.NOT_FOUND_404);
}
/* ------------------------------------------------------------ */
@Test
public void testPutServerError()
throws Exception
{
doPutFail(HttpStatus.INTERNAL_SERVER_ERROR_500);
}
/* ------------------------------------------------------------ */
@Test
public void testGetBadRequest()
throws Exception
{
doGetFail(HttpStatus.BAD_REQUEST_400);
}
/* ------------------------------------------------------------ */
@Test
public void testGetUnauthorized()
throws Exception
{
doGetFail(HttpStatus.UNAUTHORIZED_401);
}
/* ------------------------------------------------------------ */
@Test
public void testGetNotFound()
throws Exception
{
doGetFail(HttpStatus.NOT_FOUND_404);
}
/* ------------------------------------------------------------ */
@Test
public void testGetServerError()
throws Exception
{
doGetFail(HttpStatus.INTERNAL_SERVER_ERROR_500);
}
/* ------------------------------------------------------------ */
@Test
public void testPostBadRequest()
throws Exception
{
doPostFail(HttpStatus.BAD_REQUEST_400);
}
/* ------------------------------------------------------------ */
@Test
public void testPostUnauthorized()
throws Exception
{
doPostFail(HttpStatus.UNAUTHORIZED_401);
}
/* ------------------------------------------------------------ */
@Test
public void testPostForbidden()
throws Exception
{
doPostFail(HttpStatus.FORBIDDEN_403);
}
/* ------------------------------------------------------------ */
@Test
public void testPostNotFound()
throws Exception
{
doPostFail(HttpStatus.NOT_FOUND_404);
}
/* ------------------------------------------------------------ */
@Test
public void testPostServerError()
throws Exception
{
doPostFail(HttpStatus.INTERNAL_SERVER_ERROR_500);
}
/* ------------------------------------------------------------ */
protected void doPutFail(int status)
throws Exception
{
@ -140,6 +174,7 @@ public class ErrorStatusTest
assertEquals(status, responseStatus);
}
/* ------------------------------------------------------------ */
protected void doGetFail(int status)
throws Exception
{
@ -164,6 +199,7 @@ public class ErrorStatusTest
assertEquals(status, responseStatus);
}
/* ------------------------------------------------------------ */
protected void doPostFail(int status)
throws Exception
{
@ -185,6 +221,7 @@ public class ErrorStatusTest
assertEquals(status, responseStatus);
}
/* ------------------------------------------------------------ */
protected void configureServer(Server server)
throws Exception
{
@ -208,7 +245,9 @@ public class ErrorStatusTest
server.setHandler( handlers );
}
/* ------------------------------------------------------------ */
protected static class StatusHandler extends AbstractHandler {
/* ------------------------------------------------------------ */
public void handle(String target, Request baseRequest,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException

View File

@ -13,6 +13,8 @@
package org.eclipse.jetty.client;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
@ -21,8 +23,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import junit.framework.TestCase;
import org.eclipse.jetty.client.security.Realm;
import org.eclipse.jetty.client.security.SimpleRealmResolver;
import org.eclipse.jetty.http.HttpMethods;
@ -31,13 +31,13 @@ import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/* ------------------------------------------------------------ */
/**
*/
public class HttpGetRedirectTest
extends TestCase
{
private static String _content =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis felis nunc. "+
@ -62,6 +62,8 @@ public class HttpGetRedirectTest
private String _requestUrl2;
private RedirectHandler _handler;
/* ------------------------------------------------------------ */
@Before
public void setUp()
throws Exception
{
@ -81,6 +83,8 @@ public class HttpGetRedirectTest
_handler._toURL=_protocol+"://localhost:"+connector.getLocalPort()+ "/moved.txt";
}
/* ------------------------------------------------------------ */
@After
public void tearDown()
throws Exception
{
@ -91,6 +95,8 @@ public class HttpGetRedirectTest
}
}
/* ------------------------------------------------------------ */
@Test
public void testGet() throws Exception
{
startClient(_realm);
@ -115,6 +121,7 @@ public class HttpGetRedirectTest
stopClient();
}
/* ------------------------------------------------------------ */
protected void configureServer(Server server)
throws Exception
{
@ -128,6 +135,7 @@ public class HttpGetRedirectTest
}
/* ------------------------------------------------------------ */
protected void startClient(Realm realm)
throws Exception
{
@ -139,6 +147,7 @@ public class HttpGetRedirectTest
_client.start();
}
/* ------------------------------------------------------------ */
protected void stopClient()
throws Exception
{
@ -149,22 +158,26 @@ public class HttpGetRedirectTest
}
}
/* ------------------------------------------------------------ */
protected String getBasePath()
{
return _docRoot.getAbsolutePath();
}
/* ------------------------------------------------------------ */
protected void setProtocol(String protocol)
{
_protocol = protocol;
}
/* ------------------------------------------------------------ */
protected void setRealm(Realm realm)
{
_realm = realm;
}
/* ------------------------------------------------------------ */
private static class RedirectHandler
extends AbstractHandler
{
@ -174,6 +187,7 @@ public class HttpGetRedirectTest
private int _redirectCount = 0;
private String _toURL;
/* ------------------------------------------------------------ */
public RedirectHandler( final int code, final String fromURI, final String toURL, final int maxRedirects )
{
this._code = code;
@ -186,6 +200,7 @@ public class HttpGetRedirectTest
}
/* ------------------------------------------------------------ */
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{

View File

@ -14,6 +14,10 @@
package org.eclipse.jetty.client;
import org.junit.After;
import org.junit.Before;
/* ------------------------------------------------------------ */
/**
* @version $Revision$ $Date$
*/
@ -21,8 +25,10 @@ public class NonBlockingHttpExchangeCancelTest extends AbstractHttpExchangeCance
{
private HttpClient httpClient;
/* ------------------------------------------------------------ */
@Before
@Override
protected void setUp() throws Exception
public void setUp() throws Exception
{
super.setUp();
httpClient = new HttpClient();
@ -30,13 +36,16 @@ public class NonBlockingHttpExchangeCancelTest extends AbstractHttpExchangeCance
httpClient.start();
}
/* ------------------------------------------------------------ */
@After
@Override
protected void tearDown() throws Exception
public void tearDown() throws Exception
{
httpClient.stop();
super.tearDown();
}
/* ------------------------------------------------------------ */
@Override
protected HttpClient getHttpClient()
{

View File

@ -13,6 +13,9 @@
package org.eclipse.jetty.client;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@ -25,8 +28,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import junit.framework.TestCase;
import org.eclipse.jetty.client.security.Realm;
import org.eclipse.jetty.client.security.SimpleRealmResolver;
import org.eclipse.jetty.http.HttpMethods;
@ -45,16 +46,16 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/* ------------------------------------------------------------ */
/**
* Functional testing for HttpExchange.
*
*
*
*/
public class SecurityListenerTest extends TestCase
public class SecurityListenerTest
{
private Server _server;
private int _port;
private HttpClient _httpClient;
@ -62,8 +63,9 @@ public class SecurityListenerTest extends TestCase
private Realm _jettyRealm;
private static final String APP_CONTEXT = "localhost /";
@Override
protected void setUp() throws Exception
/* ------------------------------------------------------------ */
@Before
public void setUp() throws Exception
{
startServer();
_httpClient=new HttpClient();
@ -92,13 +94,16 @@ public class SecurityListenerTest extends TestCase
_httpClient.setRealmResolver( new SimpleRealmResolver(_jettyRealm) );
}
@Override
protected void tearDown() throws Exception
/* ------------------------------------------------------------ */
@After
public void tearDown() throws Exception
{
stopServer();
_httpClient.stop();
}
/* ------------------------------------------------------------ */
// @Test
public void xtestPerf() throws Exception
{
sender(1);
@ -112,6 +117,7 @@ public class SecurityListenerTest extends TestCase
sender(10000);
}
/* ------------------------------------------------------------ */
public void sender(final int nb) throws Exception
{
final CountDownLatch latch=new CountDownLatch(nb);
@ -204,6 +210,8 @@ public class SecurityListenerTest extends TestCase
// }
/* ------------------------------------------------------------ */
@Test
public void testDestinationSecurityCaching() throws Exception
{
final CyclicBarrier barrier = new CyclicBarrier(2);
@ -248,6 +256,7 @@ public class SecurityListenerTest extends TestCase
}
/* ------------------------------------------------------------ */
public static void copyStream(InputStream in, OutputStream out)
{
try
@ -269,6 +278,7 @@ public class SecurityListenerTest extends TestCase
}
}
/* ------------------------------------------------------------ */
private void startServer() throws Exception
{
_server = new Server();
@ -332,7 +342,7 @@ public class SecurityListenerTest extends TestCase
_port = connector.getLocalPort();
}
/* ------------------------------------------------------------ */
private void stopServer() throws Exception
{
_server.stop();

View File

@ -13,6 +13,9 @@
package org.eclipse.jetty.client;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@ -28,8 +31,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import junit.framework.TestCase;
import org.eclipse.jetty.client.security.HashRealmResolver;
import org.eclipse.jetty.client.security.Realm;
import org.eclipse.jetty.http.HttpMethods;
@ -49,11 +50,15 @@ import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.ssl.SslSocketConnector;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.log.Log;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/* ------------------------------------------------------------ */
/**
* Functional testing.
*/
public class SslSecurityListenerTest extends TestCase
public class SslSecurityListenerTest
{
protected Server _server;
protected int _port;
@ -62,8 +67,9 @@ public class SslSecurityListenerTest extends TestCase
protected int _type = HttpClient.CONNECTOR_SOCKET;
private static final String APP_CONTEXT = "localhost /";
@Override
protected void setUp() throws Exception
/* ------------------------------------------------------------ */
@Before
public void setUp() throws Exception
{
startServer();
_httpClient = new HttpClient();
@ -73,16 +79,19 @@ public class SslSecurityListenerTest extends TestCase
_jettyRealm = new Realm()
{
/* ------------------------------------------------------------ */
public String getId()
{
return "MyRealm";
}
/* ------------------------------------------------------------ */
public String getPrincipal()
{
return "jetty";
}
/* ------------------------------------------------------------ */
public String getCredentials()
{
return "jetty";
@ -94,8 +103,9 @@ public class SslSecurityListenerTest extends TestCase
_httpClient.setRealmResolver(resolver);
}
@Override
protected void tearDown() throws Exception
/* ------------------------------------------------------------ */
@After
public void tearDown() throws Exception
{
Thread.sleep(1000);
_httpClient.stop();
@ -103,6 +113,8 @@ public class SslSecurityListenerTest extends TestCase
stopServer();
}
/* ------------------------------------------------------------ */
@Test
public void testSslGet() throws Exception
{
// TODO Resolve problems on IBM JVM https://bugs.eclipse.org/bugs/show_bug.cgi?id=304532
@ -117,6 +129,7 @@ public class SslSecurityListenerTest extends TestCase
ContentExchange httpExchange = new ContentExchange(true)
{
/* ------------------------------------------------------------ */
@Override
protected void onResponseComplete() throws IOException
{
@ -138,6 +151,7 @@ public class SslSecurityListenerTest extends TestCase
}
/* ------------------------------------------------------------ */
protected void startServer() throws Exception
{
_server = new Server();
@ -180,7 +194,7 @@ public class SslSecurityListenerTest extends TestCase
Handler testHandler = new AbstractHandler()
{
/* ------------------------------------------------------------ */
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
// System.err.println("passed authentication!\n"+((Request)request).getConnection().getRequestFields());
@ -216,6 +230,7 @@ public class SslSecurityListenerTest extends TestCase
_port = connector.getLocalPort();
}
/* ------------------------------------------------------------ */
public static void copyStream(InputStream in, OutputStream out)
{
try
@ -237,6 +252,7 @@ public class SslSecurityListenerTest extends TestCase
}
}
/* ------------------------------------------------------------ */
private void stopServer() throws Exception
{
_server.stop();

View File

@ -13,6 +13,8 @@
package org.eclipse.jetty.client;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
@ -21,8 +23,6 @@ import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import junit.framework.TestCase;
import org.eclipse.jetty.http.HttpMethods;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.Connection;
@ -34,11 +34,15 @@ import org.eclipse.jetty.websocket.WebSocket;
import org.eclipse.jetty.websocket.WebSocketBuffers;
import org.eclipse.jetty.websocket.WebSocketConnectionD00;
import org.eclipse.jetty.websocket.WebSocketHandler;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/* ------------------------------------------------------------ */
/**
* Functional testing for HttpExchange.
*/
public class WebSocketUpgradeTest extends TestCase
public class WebSocketUpgradeTest
{
protected Server _server;
protected int _port;
@ -49,8 +53,9 @@ public class WebSocketUpgradeTest extends TestCase
protected TestWebSocket _websocket;
final BlockingQueue<Object> _results = new ArrayBlockingQueue<Object>(100);
@Override
protected void setUp() throws Exception
/* ------------------------------------------------------------ */
@Before
public void setUp() throws Exception
{
startServer();
_httpClient=new HttpClient();
@ -62,25 +67,29 @@ public class WebSocketUpgradeTest extends TestCase
_httpClient.start();
}
@Override
protected void tearDown() throws Exception
/* ------------------------------------------------------------ */
@After
public void tearDown() throws Exception
{
_httpClient.stop();
Thread.sleep(500);
stopServer();
}
/* ------------------------------------------------------------ */
@Test
public void testGetWithContentExchange() throws Exception
{
final WebSocket clientWS = new WebSocket.OnTextMessage()
{
Connection _connection;
/* ------------------------------------------------------------ */
public void onClose(int closeCode, String message)
{
}
/* ------------------------------------------------------------ */
public void onOpen(Connection connection)
{
_connection=connection;
@ -88,6 +97,7 @@ public class WebSocketUpgradeTest extends TestCase
_results.add(_connection);
}
/* ------------------------------------------------------------ */
public void onMessage(String data)
{
_results.add("clientWS.onMessage");
@ -126,6 +136,7 @@ public class WebSocketUpgradeTest extends TestCase
return connection;
}
/* ------------------------------------------------------------ */
private void waitFor(int results)
{
try
@ -176,6 +187,7 @@ public class WebSocketUpgradeTest extends TestCase
}
/* ------------------------------------------------------------ */
protected void newServer() throws Exception
{
_server=new Server();
@ -186,11 +198,13 @@ public class WebSocketUpgradeTest extends TestCase
_server.setConnectors(new Connector[] { _connector });
}
/* ------------------------------------------------------------ */
protected void startServer() throws Exception
{
newServer();
_handler= new WebSocketHandler()
{
/* ------------------------------------------------------------ */
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol)
{
_websocket = new TestWebSocket();
@ -203,18 +217,19 @@ public class WebSocketUpgradeTest extends TestCase
_port=_connector.getLocalPort();
}
/* ------------------------------------------------------------ */
private void stopServer() throws Exception
{
_server.stop();
_server.join();
}
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
class TestWebSocket implements WebSocket.OnTextMessage
{
Connection _connection;
/* ------------------------------------------------------------ */
public void onOpen(Connection connection)
{
_connection=connection;
@ -223,18 +238,21 @@ public class WebSocketUpgradeTest extends TestCase
_results.add(this);
}
/* ------------------------------------------------------------ */
public void onMessage(final String data)
{
_results.add("serverWS.onMessage");
_results.add(data);
}
/* ------------------------------------------------------------ */
public void onClose(int code, String message)
{
_results.add("onDisconnect");
_webSockets.remove(this);
}
/* ------------------------------------------------------------ */
public void sendMessage(String msg) throws IOException
{
_connection.sendMessage(msg);