Permalink
Browse files

Updated server module tests to Jetty 9.

  • Loading branch information...
1 parent 72a18c4 commit fa96d5fe080c2e0a8f49660f62064585c7a8c0cb @sbordet sbordet committed Sep 26, 2012
Showing with 787 additions and 945 deletions.
  1. +5 −3 cometd-java/cometd-java-server/pom.xml
  2. +15 −29 cometd-java/cometd-java-server/src/test/java/org/cometd/server/AbstractBayeuxClientServerTest.java
  3. +11 −12 cometd-java/cometd-java-server/src/test/java/org/cometd/server/AbstractBayeuxServerTest.java
  4. +14 −19 cometd-java/cometd-java-server/src/test/java/org/cometd/server/BadJSONTest.java
  5. +2 −2 cometd-java/cometd-java-server/src/test/java/org/cometd/server/BayeuxServerCreationTest.java
  6. +5 −5 cometd-java/cometd-java-server/src/test/java/org/cometd/server/BayeuxServerTest.java
  7. +27 −35 cometd-java/cometd-java-server/src/test/java/org/cometd/server/CharsetTest.java
  8. +43 −50 ...d-java/cometd-java-server/src/test/java/org/cometd/server/CometDServiceMetaNotificationsTest.java
  9. +26 −33 cometd-java/cometd-java-server/src/test/java/org/cometd/server/CometDServiceTest.java
  10. +28 −31 cometd-java/cometd-java-server/src/test/java/org/cometd/server/CometDServiceWithThreadPoolTest.java
  11. +39 −53 cometd-java/cometd-java-server/src/test/java/org/cometd/server/ConcurrentConnectDisconnectTest.java
  12. +28 −39 .../cometd-java-server/src/test/java/org/cometd/server/ConcurrentDisconnectSubscribePublishTest.java
  13. +11 −12 ...d-java-server/src/test/java/org/cometd/server/ConcurrentHandshakeFailureSubscribePublishTest.java
  14. +44 −64 cometd-java/cometd-java-server/src/test/java/org/cometd/server/CustomAdviceTest.java
  15. +30 −39 ...va/cometd-java-server/src/test/java/org/cometd/server/CustomResponseOnSecurityPolicyDenyTest.java
  16. +12 −18 cometd-java/cometd-java-server/src/test/java/org/cometd/server/DisconnectTest.java
  17. +7 −7 cometd-java/cometd-java-server/src/test/java/org/cometd/server/ServerMessageImplTest.java
  18. +16 −19 cometd-java/cometd-java-server/src/test/java/org/cometd/server/ServerRedeployTest.java
  19. +24 −30 cometd-java/cometd-java-server/src/test/java/org/cometd/server/ServerShutdownTest.java
  20. +9 −11 cometd-java/cometd-java-server/src/test/java/org/cometd/server/ServiceWithCustomDataClassTest.java
  21. +16 −21 cometd-java/cometd-java-server/src/test/java/org/cometd/server/SlowConnectionTest.java
  22. +11 −6 cometd-java/cometd-java-server/src/test/java/org/cometd/server/SpringFrameworkConfigurationTest.java
  23. +29 −38 ...ava/cometd-java-server/src/test/java/org/cometd/server/SubscriptionsWithMultipleChannelsTest.java
  24. +60 −72 cometd-java/cometd-java-server/src/test/java/org/cometd/server/authorizer/AuthorizerTest.java
  25. +1 −1 cometd-java/cometd-java-server/src/test/java/org/cometd/server/ext/ArrayIdQueueTest.java
  26. +29 −34 cometd-java/cometd-java-server/src/test/java/org/cometd/server/ext/BayeuxExtensionTest.java
  27. +23 −27 cometd-java/cometd-java-server/src/test/java/org/cometd/server/ext/ExtensionConnectTest.java
  28. +22 −23 cometd-java/cometd-java-server/src/test/java/org/cometd/server/ext/ExtensionDisconnectTest.java
  29. +15 −15 cometd-java/cometd-java-server/src/test/java/org/cometd/server/ext/ExtensionHandshakeTest.java
  30. +24 −25 cometd-java/cometd-java-server/src/test/java/org/cometd/server/ext/ExtensionPublishReceivedTest.java
  31. +23 −24 cometd-java/cometd-java-server/src/test/java/org/cometd/server/ext/ExtensionPublishSentTest.java
  32. +23 −24 cometd-java/cometd-java-server/src/test/java/org/cometd/server/ext/ExtensionSubscribeTest.java
  33. +30 −32 cometd-java/cometd-java-server/src/test/java/org/cometd/server/ext/ExtensionUnsubscribeTest.java
  34. +50 −62 cometd-java/cometd-java-server/src/test/java/org/cometd/server/transport/BrowserMappingTest.java
  35. +21 −29 ...d-java-server/src/test/java/org/cometd/server/transport/JSONTransportMetaConnectDeliveryTest.java
  36. +13 −0 cometd-java/cometd-java-server/src/test/resources/log4j.properties
  37. +1 −1 pom.xml
@@ -13,8 +13,8 @@
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5</version>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -60,7 +60,9 @@
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${slf4j-version}</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
@@ -20,13 +20,12 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.eclipse.jetty.client.ContentExchange;
import org.eclipse.jetty.client.HttpClient;
-import org.eclipse.jetty.http.HttpFields;
-import org.eclipse.jetty.http.HttpHeaders;
-import org.eclipse.jetty.http.HttpMethods;
-import org.eclipse.jetty.io.Buffer;
-import org.eclipse.jetty.io.ByteArrayBuffer;
+import org.eclipse.jetty.client.api.ContentResponse;
+import org.eclipse.jetty.client.api.Request;
+import org.eclipse.jetty.client.util.StringContentProvider;
+import org.eclipse.jetty.http.HttpHeader;
+import org.eclipse.jetty.http.HttpMethod;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -48,40 +47,27 @@ public void stopHttpClient() throws Exception
httpClient.stop();
}
- protected String extractClientId(ContentExchange handshake) throws UnsupportedEncodingException
+ protected String extractClientId(ContentResponse handshake) throws UnsupportedEncodingException
{
- String content = handshake.getResponseContent();
+ String content = new String(handshake.content(), "UTF-8");
Matcher matcher = Pattern.compile("\"clientId\"\\s*:\\s*\"([^\"]*)\"").matcher(content);
Assert.assertTrue(matcher.find());
String clientId = matcher.group(1);
Assert.assertTrue(clientId.length() > 0);
return clientId;
}
- protected String extractBayeuxCookie(ContentExchange handshake)
+ protected Request newBayeuxRequest(String requestBody) throws UnsupportedEncodingException
{
- HttpFields headers = handshake.getResponseFields();
- Buffer cookie = headers.get(HttpHeaders.SET_COOKIE_BUFFER);
- String cookieName = "BAYEUX_BROWSER";
- Matcher matcher = Pattern.compile(cookieName + "=([^;]*)").matcher(cookie.toString());
- Assert.assertTrue(matcher.find());
- String bayeuxCookie = matcher.group(1);
- Assert.assertTrue(bayeuxCookie.length() > 0);
- return cookieName + "=" + bayeuxCookie;
- }
-
- protected ContentExchange newBayeuxExchange(String requestBody) throws UnsupportedEncodingException
- {
- ContentExchange result = new ContentExchange(true);
- configureBayeuxExchange(result, requestBody, "UTF-8");
- return result;
+ Request request = httpClient.newRequest(cometdURL);
+ configureBayeuxRequest(request, requestBody, "UTF-8");
+ return request;
}
- protected void configureBayeuxExchange(ContentExchange exchange, String requestBody, String encoding) throws UnsupportedEncodingException
+ protected void configureBayeuxRequest(Request request, String requestBody, String encoding) throws UnsupportedEncodingException
{
- exchange.setURL(cometdURL);
- exchange.setMethod(HttpMethods.POST);
- exchange.setRequestContentType("application/json;charset=" + encoding);
- exchange.setRequestContent(new ByteArrayBuffer(requestBody, encoding));
+ request.method(HttpMethod.POST);
+ request.header(HttpHeader.CONTENT_TYPE.asString(), "application/json;charset=" + encoding);
+ request.content(new StringContentProvider(requestBody, encoding));
}
}
@@ -19,44 +19,43 @@
import java.util.HashMap;
import java.util.Map;
-import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.HandlerCollection;
-import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
-import org.junit.rules.TestWatchman;
-import org.junit.runners.model.FrameworkMethod;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
public abstract class AbstractBayeuxServerTest
{
@Rule
- public final TestWatchman testName = new TestWatchman()
+ public final TestWatcher testName = new TestWatcher()
{
@Override
- public void starting(FrameworkMethod method)
+ protected void starting(Description description)
{
- super.starting(method);
- System.err.printf("Running %s.%s%n", method.getMethod().getDeclaringClass().getName(), method.getName());
+ super.starting(description);
+ System.err.printf("Running %s.%s%n", description.getTestClass().getName(), description.getMethodName());
}
};
protected Server server;
- protected Connector connector;
+ protected ServerConnector connector;
protected int port;
protected ServletContextHandler context;
protected CometdServlet cometdServlet;
protected String cometdURL;
protected BayeuxServerImpl bayeux;
- protected long timeout = 5000;
+ protected long timeout = 2000;
@Before
public void startServer() throws Exception
{
server = new Server();
- connector = new SelectChannelConnector();
+ connector = new ServerConnector(server);
server.addConnector(connector);
HandlerCollection handlers = new HandlerCollection();
@@ -68,7 +67,7 @@ public void startServer() throws Exception
// Setup comet servlet
cometdServlet = new CometdServlet();
ServletHolder cometdServletHolder = new ServletHolder(cometdServlet);
- Map<String, String> options = new HashMap<String, String>();
+ Map<String, String> options = new HashMap<>();
options.put("timeout", String.valueOf(timeout));
if (Boolean.getBoolean("debugTests"))
{
@@ -17,14 +17,14 @@
package org.cometd.server;
import java.io.IOException;
+import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.cometd.server.transport.JSONTransport;
-import org.eclipse.jetty.client.ContentExchange;
-import org.eclipse.jetty.client.HttpExchange;
-import org.eclipse.jetty.http.HttpHeaders;
+import org.eclipse.jetty.client.api.ContentResponse;
+import org.eclipse.jetty.client.api.Request;
import org.junit.Assert;
import org.junit.Test;
@@ -47,38 +47,33 @@ protected void handleJSONParseException(HttpServletRequest request, HttpServletR
}
});
- ContentExchange handshake = newBayeuxExchange("[{" +
+ Request handshake = newBayeuxRequest("[{" +
"\"channel\": \"/meta/handshake\"," +
"\"version\": \"1.0\"," +
"\"minimumVersion\": \"1.0\"," +
"\"supportedConnectionTypes\": [\"long-polling\"]" +
"}]");
- httpClient.send(handshake);
- Assert.assertEquals(HttpExchange.STATUS_COMPLETED, handshake.waitForDone());
- Assert.assertEquals(200, handshake.getResponseStatus());
+ ContentResponse response = handshake.send().get(5, TimeUnit.SECONDS);
+ Assert.assertEquals(200, response.status());
- String clientId = extractClientId(handshake);
- String bayeuxCookie = extractBayeuxCookie(handshake);
+ String clientId = extractClientId(response);
- ContentExchange connect = newBayeuxExchange("[{" +
+ Request connect = newBayeuxRequest("[{" +
"\"channel\": \"/meta/connect\"," +
"\"clientId\": \"" + clientId + "\"," +
"\"connectionType\": \"long-polling\"" +
"}]");
- connect.setRequestHeader(HttpHeaders.COOKIE, bayeuxCookie);
- httpClient.send(connect);
- Assert.assertEquals(HttpExchange.STATUS_COMPLETED, connect.waitForDone());
- Assert.assertEquals(200, connect.getResponseStatus());
+ response = connect.send().get(5, TimeUnit.SECONDS);
+
+ Assert.assertEquals(200, response.status());
// Forge a bad JSON message
- ContentExchange badConnect = newBayeuxExchange("[{" +
+ Request badConnect = newBayeuxRequest("[{" +
"\"channel\": \"/meta/connect\"," +
"\"clientId\": \"" + clientId + "\"," +
"\"connectionType\": \"long-polling\"");
//"}]"); Bad JSON, missing this line
- connect.setRequestHeader(HttpHeaders.COOKIE, bayeuxCookie);
- httpClient.send(badConnect);
- Assert.assertEquals(HttpExchange.STATUS_COMPLETED, badConnect.waitForDone());
- Assert.assertEquals(400, badConnect.getResponseStatus());
+ response = badConnect.send().get(5, TimeUnit.SECONDS);
+ Assert.assertEquals(400, response.status());
}
}
@@ -40,15 +40,15 @@ public void testCreationWithoutOptions() throws Exception
assertEquals(2, knownTransports.size());
assertTrue(knownTransports.contains(JSONTransport.NAME));
assertTrue(knownTransports.contains(JSONPTransport.NAME));
- assertEquals(knownTransports, new HashSet<String>(bayeuxServer.getAllowedTransports()));
+ assertEquals(knownTransports, new HashSet<>(bayeuxServer.getAllowedTransports()));
}
@Test
public void testCreationWithOptions() throws Exception
{
BayeuxServerImpl bayeuxServer = new BayeuxServerImpl();
- Map<String, String> options = new HashMap<String, String>();
+ Map<String, String> options = new HashMap<>();
String timeoutKey = "timeout";
String timeoutValue = "10007";
options.put(timeoutKey, timeoutValue);
@@ -36,7 +36,7 @@
public class BayeuxServerTest
{
- private final Queue<Object> _events = new ConcurrentLinkedQueue<Object>();
+ private final Queue<Object> _events = new ConcurrentLinkedQueue<>();
private final BayeuxServerImpl _bayeux = new BayeuxServerImpl();
private ServerSessionImpl newServerSession()
@@ -153,16 +153,16 @@ public void testSessionAttributes() throws Exception
public void testLocalSessions() throws Exception
{
LocalSession session0 = _bayeux.newLocalSession("s0");
- Assert.assertTrue(session0.toString().indexOf("s0?")>=0);
+ Assert.assertTrue(session0.toString().contains("s0?"));
session0.handshake();
- Assert.assertTrue(session0.toString().indexOf("s0_")>=0);
+ Assert.assertTrue(session0.toString().contains("s0_"));
final LocalSession session1 = _bayeux.newLocalSession("s1");
session1.handshake();
final LocalSession session2 = _bayeux.newLocalSession("s2");
session2.handshake();
- final Queue<String> events = new ConcurrentLinkedQueue<String>();
+ final Queue<String> events = new ConcurrentLinkedQueue<>();
ClientSessionChannel.MessageListener listener = new ClientSessionChannel.MessageListener()
{
@@ -271,7 +271,7 @@ public void run()
@Test
public void testExtensions() throws Exception
{
- final Queue<String> events = new ConcurrentLinkedQueue<String>();
+ final Queue<String> events = new ConcurrentLinkedQueue<>();
_bayeux.addExtension(new BayeuxServer.Extension.Adapter()
{
@Override
Oops, something went wrong.

0 comments on commit fa96d5f

Please sign in to comment.