diff --git a/client/src/test/java/org/asynchttpclient/AbstractBasicTest.java b/client/src/test/java/org/asynchttpclient/AbstractBasicTest.java index 6333153121..916b1f3570 100644 --- a/client/src/test/java/org/asynchttpclient/AbstractBasicTest.java +++ b/client/src/test/java/org/asynchttpclient/AbstractBasicTest.java @@ -40,7 +40,6 @@ public abstract class AbstractBasicTest { @BeforeClass(alwaysRun = true) public void setUpGlobal() throws Exception { - server = new Server(); ServerConnector connector1 = addHttpConnector(server); server.setHandler(configureHandler()); @@ -55,8 +54,9 @@ public void setUpGlobal() throws Exception { @AfterClass(alwaysRun = true) public void tearDownGlobal() throws Exception { - if (server != null) + if (server != null) { server.stop(); + } } protected String getTargetUrl() { diff --git a/client/src/test/java/org/asynchttpclient/ws/AbstractBasicTest.java b/client/src/test/java/org/asynchttpclient/ws/AbstractBasicWebSocketTest.java similarity index 72% rename from client/src/test/java/org/asynchttpclient/ws/AbstractBasicTest.java rename to client/src/test/java/org/asynchttpclient/ws/AbstractBasicWebSocketTest.java index 6688da4b0f..a0296bb538 100644 --- a/client/src/test/java/org/asynchttpclient/ws/AbstractBasicTest.java +++ b/client/src/test/java/org/asynchttpclient/ws/AbstractBasicWebSocketTest.java @@ -14,32 +14,37 @@ import static org.asynchttpclient.test.TestUtils.addHttpConnector; +import org.asynchttpclient.AbstractBasicTest; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.websocket.server.WebSocketHandler; -import org.testng.annotations.AfterClass; +import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; import org.testng.annotations.BeforeClass; -public abstract class AbstractBasicTest extends org.asynchttpclient.AbstractBasicTest { +public abstract class AbstractBasicWebSocketTest extends AbstractBasicTest { @BeforeClass(alwaysRun = true) + @Override public void setUpGlobal() throws Exception { server = new Server(); ServerConnector connector = addHttpConnector(server); - server.setHandler(getWebSocketHandler()); + server.setHandler(configureHandler()); server.start(); port1 = connector.getLocalPort(); logger.info("Local HTTP server started successfully"); } - @AfterClass(alwaysRun = true) - public void tearDownGlobal() throws Exception { - server.stop(); - } - protected String getTargetUrl() { return String.format("ws://localhost:%d/", port1); } - - public abstract WebSocketHandler getWebSocketHandler(); + + @Override + public WebSocketHandler configureHandler() { + return new WebSocketHandler() { + @Override + public void configure(WebSocketServletFactory factory) { + factory.register(EchoSocket.class); + } + }; + } } diff --git a/client/src/test/java/org/asynchttpclient/ws/ByteMessageTest.java b/client/src/test/java/org/asynchttpclient/ws/ByteMessageTest.java index e3f6664498..313113f0a9 100644 --- a/client/src/test/java/org/asynchttpclient/ws/ByteMessageTest.java +++ b/client/src/test/java/org/asynchttpclient/ws/ByteMessageTest.java @@ -20,24 +20,12 @@ import java.util.concurrent.atomic.AtomicReference; import org.asynchttpclient.AsyncHttpClient; -import org.eclipse.jetty.websocket.server.WebSocketHandler; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; import org.testng.annotations.Test; -public class ByteMessageTest extends AbstractBasicTest { +public class ByteMessageTest extends AbstractBasicWebSocketTest { private static final byte[] ECHO_BYTES = "ECHO".getBytes(StandardCharsets.UTF_8); - @Override - public WebSocketHandler getWebSocketHandler() { - return new WebSocketHandler() { - @Override - public void configure(WebSocketServletFactory factory) { - factory.register(EchoSocket.class); - } - }; - } - @Test(groups = "standalone") public void echoByte() throws Exception { try (AsyncHttpClient c = asyncHttpClient()) { diff --git a/client/src/test/java/org/asynchttpclient/ws/CloseCodeReasonMessageTest.java b/client/src/test/java/org/asynchttpclient/ws/CloseCodeReasonMessageTest.java index 132b4e842c..3a602783f5 100644 --- a/client/src/test/java/org/asynchttpclient/ws/CloseCodeReasonMessageTest.java +++ b/client/src/test/java/org/asynchttpclient/ws/CloseCodeReasonMessageTest.java @@ -21,21 +21,9 @@ import java.util.concurrent.atomic.AtomicReference; import org.asynchttpclient.AsyncHttpClient; -import org.eclipse.jetty.websocket.server.WebSocketHandler; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; import org.testng.annotations.Test; -public class CloseCodeReasonMessageTest extends AbstractBasicTest { - - @Override - public WebSocketHandler getWebSocketHandler() { - return new WebSocketHandler() { - @Override - public void configure(WebSocketServletFactory factory) { - factory.register(EchoSocket.class); - } - }; - } +public class CloseCodeReasonMessageTest extends AbstractBasicWebSocketTest { @Test(groups = "standalone", timeOut = 60000) public void onCloseWithCode() throws Exception { diff --git a/client/src/test/java/org/asynchttpclient/ws/ProxyTunnellingTest.java b/client/src/test/java/org/asynchttpclient/ws/ProxyTunnellingTest.java index 515ad95fb1..ba2d7f01d7 100644 --- a/client/src/test/java/org/asynchttpclient/ws/ProxyTunnellingTest.java +++ b/client/src/test/java/org/asynchttpclient/ws/ProxyTunnellingTest.java @@ -24,15 +24,13 @@ import org.eclipse.jetty.proxy.ConnectHandler; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.websocket.server.WebSocketHandler; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; /** * Proxy usage tests. */ -public class ProxyTunnellingTest extends AbstractBasicTest { +public class ProxyTunnellingTest extends AbstractBasicWebSocketTest { private Server server2; @@ -46,23 +44,13 @@ public void setUpServers(boolean targetHttps) throws Exception { server2 = new Server(); @SuppressWarnings("resource") ServerConnector connector2 = targetHttps ? addHttpsConnector(server2) : addHttpConnector(server2); - server2.setHandler(getWebSocketHandler()); + server2.setHandler(configureHandler()); server2.start(); port2 = connector2.getLocalPort(); logger.info("Local HTTP server started successfully"); } - @Override - public WebSocketHandler getWebSocketHandler() { - return new WebSocketHandler() { - @Override - public void configure(WebSocketServletFactory factory) { - factory.register(EchoSocket.class); - } - }; - } - @AfterMethod(alwaysRun = true) public void tearDownGlobal() throws Exception { server.stop(); diff --git a/client/src/test/java/org/asynchttpclient/ws/RedirectTest.java b/client/src/test/java/org/asynchttpclient/ws/RedirectTest.java index 893ac4fbb8..763848cc13 100644 --- a/client/src/test/java/org/asynchttpclient/ws/RedirectTest.java +++ b/client/src/test/java/org/asynchttpclient/ws/RedirectTest.java @@ -31,12 +31,10 @@ import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.HandlerList; -import org.eclipse.jetty.websocket.server.WebSocketHandler; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -public class RedirectTest extends AbstractBasicTest { +public class RedirectTest extends AbstractBasicWebSocketTest { @BeforeClass @Override @@ -55,7 +53,7 @@ public void handle(String s, Request request, HttpServletRequest httpServletRequ } } }); - list.addHandler(getWebSocketHandler()); + list.addHandler(configureHandler()); server.setHandler(list); server.start(); @@ -64,17 +62,6 @@ public void handle(String s, Request request, HttpServletRequest httpServletRequ logger.info("Local HTTP server started successfully"); } - @Override - public WebSocketHandler getWebSocketHandler() { - return new WebSocketHandler() { - @Override - public void configure(WebSocketServletFactory factory) { - factory.register(EchoSocket.class); - } - }; - } - - @Test(groups = "standalone", timeOut = 60000) public void testRedirectToWSResource() throws Exception { try (AsyncHttpClient c = asyncHttpClient(config().setFollowRedirect(true))) { diff --git a/client/src/test/java/org/asynchttpclient/ws/TextMessageTest.java b/client/src/test/java/org/asynchttpclient/ws/TextMessageTest.java index ac9054ae65..2da22ec799 100644 --- a/client/src/test/java/org/asynchttpclient/ws/TextMessageTest.java +++ b/client/src/test/java/org/asynchttpclient/ws/TextMessageTest.java @@ -21,21 +21,9 @@ import java.util.concurrent.atomic.AtomicReference; import org.asynchttpclient.AsyncHttpClient; -import org.eclipse.jetty.websocket.server.WebSocketHandler; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; import org.testng.annotations.Test; -public class TextMessageTest extends AbstractBasicTest { - - @Override - public WebSocketHandler getWebSocketHandler() { - return new WebSocketHandler() { - @Override - public void configure(WebSocketServletFactory factory) { - factory.register(EchoSocket.class); - } - }; - } +public class TextMessageTest extends AbstractBasicWebSocketTest { @Test(groups = "standalone", timeOut = 60000) public void onOpen() throws Exception { diff --git a/client/src/test/java/org/asynchttpclient/ws/WebSocketWriteFutureTest.java b/client/src/test/java/org/asynchttpclient/ws/WebSocketWriteFutureTest.java index 9d2c625620..90253fbd84 100644 --- a/client/src/test/java/org/asynchttpclient/ws/WebSocketWriteFutureTest.java +++ b/client/src/test/java/org/asynchttpclient/ws/WebSocketWriteFutureTest.java @@ -24,10 +24,10 @@ import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; import org.testng.annotations.Test; -public class WebSocketWriteFutureTest extends AbstractBasicTest { +public class WebSocketWriteFutureTest extends AbstractBasicWebSocketTest { @Override - public WebSocketHandler getWebSocketHandler() { + public WebSocketHandler configureHandler() { return new WebSocketHandler() { @Override public void configure(WebSocketServletFactory factory) {