Skip to content

Commit

Permalink
minor clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
slandelle committed Aug 3, 2017
1 parent 26cccb4 commit 3cc4a95
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
}
}
14 changes: 1 addition & 13 deletions client/src/test/java/org/asynchttpclient/ws/ByteMessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand Down
17 changes: 2 additions & 15 deletions client/src/test/java/org/asynchttpclient/ws/RedirectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,7 +53,7 @@ public void handle(String s, Request request, HttpServletRequest httpServletRequ
}
}
});
list.addHandler(getWebSocketHandler());
list.addHandler(configureHandler());
server.setHandler(list);

server.start();
Expand All @@ -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))) {
Expand Down
14 changes: 1 addition & 13 deletions client/src/test/java/org/asynchttpclient/ws/TextMessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3cc4a95

Please sign in to comment.