Skip to content

Commit 3cc4a95

Browse files
committed
minor clean up
1 parent 26cccb4 commit 3cc4a95

8 files changed

+26
-82
lines changed

client/src/test/java/org/asynchttpclient/AbstractBasicTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public abstract class AbstractBasicTest {
4040

4141
@BeforeClass(alwaysRun = true)
4242
public void setUpGlobal() throws Exception {
43-
4443
server = new Server();
4544
ServerConnector connector1 = addHttpConnector(server);
4645
server.setHandler(configureHandler());
@@ -55,8 +54,9 @@ public void setUpGlobal() throws Exception {
5554

5655
@AfterClass(alwaysRun = true)
5756
public void tearDownGlobal() throws Exception {
58-
if (server != null)
57+
if (server != null) {
5958
server.stop();
59+
}
6060
}
6161

6262
protected String getTargetUrl() {

client/src/test/java/org/asynchttpclient/ws/AbstractBasicTest.java client/src/test/java/org/asynchttpclient/ws/AbstractBasicWebSocketTest.java

+15-10
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,37 @@
1414

1515
import static org.asynchttpclient.test.TestUtils.addHttpConnector;
1616

17+
import org.asynchttpclient.AbstractBasicTest;
1718
import org.eclipse.jetty.server.Server;
1819
import org.eclipse.jetty.server.ServerConnector;
1920
import org.eclipse.jetty.websocket.server.WebSocketHandler;
20-
import org.testng.annotations.AfterClass;
21+
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
2122
import org.testng.annotations.BeforeClass;
2223

23-
public abstract class AbstractBasicTest extends org.asynchttpclient.AbstractBasicTest {
24+
public abstract class AbstractBasicWebSocketTest extends AbstractBasicTest {
2425

2526
@BeforeClass(alwaysRun = true)
27+
@Override
2628
public void setUpGlobal() throws Exception {
2729
server = new Server();
2830
ServerConnector connector = addHttpConnector(server);
29-
server.setHandler(getWebSocketHandler());
31+
server.setHandler(configureHandler());
3032
server.start();
3133
port1 = connector.getLocalPort();
3234
logger.info("Local HTTP server started successfully");
3335
}
3436

35-
@AfterClass(alwaysRun = true)
36-
public void tearDownGlobal() throws Exception {
37-
server.stop();
38-
}
39-
4037
protected String getTargetUrl() {
4138
return String.format("ws://localhost:%d/", port1);
4239
}
43-
44-
public abstract WebSocketHandler getWebSocketHandler();
40+
41+
@Override
42+
public WebSocketHandler configureHandler() {
43+
return new WebSocketHandler() {
44+
@Override
45+
public void configure(WebSocketServletFactory factory) {
46+
factory.register(EchoSocket.class);
47+
}
48+
};
49+
}
4550
}

client/src/test/java/org/asynchttpclient/ws/ByteMessageTest.java

+1-13
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,12 @@
2020
import java.util.concurrent.atomic.AtomicReference;
2121

2222
import org.asynchttpclient.AsyncHttpClient;
23-
import org.eclipse.jetty.websocket.server.WebSocketHandler;
24-
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
2523
import org.testng.annotations.Test;
2624

27-
public class ByteMessageTest extends AbstractBasicTest {
25+
public class ByteMessageTest extends AbstractBasicWebSocketTest {
2826

2927
private static final byte[] ECHO_BYTES = "ECHO".getBytes(StandardCharsets.UTF_8);
3028

31-
@Override
32-
public WebSocketHandler getWebSocketHandler() {
33-
return new WebSocketHandler() {
34-
@Override
35-
public void configure(WebSocketServletFactory factory) {
36-
factory.register(EchoSocket.class);
37-
}
38-
};
39-
}
40-
4129
@Test(groups = "standalone")
4230
public void echoByte() throws Exception {
4331
try (AsyncHttpClient c = asyncHttpClient()) {

client/src/test/java/org/asynchttpclient/ws/CloseCodeReasonMessageTest.java

+1-13
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,9 @@
2121
import java.util.concurrent.atomic.AtomicReference;
2222

2323
import org.asynchttpclient.AsyncHttpClient;
24-
import org.eclipse.jetty.websocket.server.WebSocketHandler;
25-
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
2624
import org.testng.annotations.Test;
2725

28-
public class CloseCodeReasonMessageTest extends AbstractBasicTest {
29-
30-
@Override
31-
public WebSocketHandler getWebSocketHandler() {
32-
return new WebSocketHandler() {
33-
@Override
34-
public void configure(WebSocketServletFactory factory) {
35-
factory.register(EchoSocket.class);
36-
}
37-
};
38-
}
26+
public class CloseCodeReasonMessageTest extends AbstractBasicWebSocketTest {
3927

4028
@Test(groups = "standalone", timeOut = 60000)
4129
public void onCloseWithCode() throws Exception {

client/src/test/java/org/asynchttpclient/ws/ProxyTunnellingTest.java

+2-14
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@
2424
import org.eclipse.jetty.proxy.ConnectHandler;
2525
import org.eclipse.jetty.server.Server;
2626
import org.eclipse.jetty.server.ServerConnector;
27-
import org.eclipse.jetty.websocket.server.WebSocketHandler;
28-
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
2927
import org.testng.annotations.AfterMethod;
3028
import org.testng.annotations.Test;
3129

3230
/**
3331
* Proxy usage tests.
3432
*/
35-
public class ProxyTunnellingTest extends AbstractBasicTest {
33+
public class ProxyTunnellingTest extends AbstractBasicWebSocketTest {
3634

3735
private Server server2;
3836

@@ -46,23 +44,13 @@ public void setUpServers(boolean targetHttps) throws Exception {
4644
server2 = new Server();
4745
@SuppressWarnings("resource")
4846
ServerConnector connector2 = targetHttps ? addHttpsConnector(server2) : addHttpConnector(server2);
49-
server2.setHandler(getWebSocketHandler());
47+
server2.setHandler(configureHandler());
5048
server2.start();
5149
port2 = connector2.getLocalPort();
5250

5351
logger.info("Local HTTP server started successfully");
5452
}
5553

56-
@Override
57-
public WebSocketHandler getWebSocketHandler() {
58-
return new WebSocketHandler() {
59-
@Override
60-
public void configure(WebSocketServletFactory factory) {
61-
factory.register(EchoSocket.class);
62-
}
63-
};
64-
}
65-
6654
@AfterMethod(alwaysRun = true)
6755
public void tearDownGlobal() throws Exception {
6856
server.stop();

client/src/test/java/org/asynchttpclient/ws/RedirectTest.java

+2-15
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@
3131
import org.eclipse.jetty.server.ServerConnector;
3232
import org.eclipse.jetty.server.handler.AbstractHandler;
3333
import org.eclipse.jetty.server.handler.HandlerList;
34-
import org.eclipse.jetty.websocket.server.WebSocketHandler;
35-
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
3634
import org.testng.annotations.BeforeClass;
3735
import org.testng.annotations.Test;
3836

39-
public class RedirectTest extends AbstractBasicTest {
37+
public class RedirectTest extends AbstractBasicWebSocketTest {
4038

4139
@BeforeClass
4240
@Override
@@ -55,7 +53,7 @@ public void handle(String s, Request request, HttpServletRequest httpServletRequ
5553
}
5654
}
5755
});
58-
list.addHandler(getWebSocketHandler());
56+
list.addHandler(configureHandler());
5957
server.setHandler(list);
6058

6159
server.start();
@@ -64,17 +62,6 @@ public void handle(String s, Request request, HttpServletRequest httpServletRequ
6462
logger.info("Local HTTP server started successfully");
6563
}
6664

67-
@Override
68-
public WebSocketHandler getWebSocketHandler() {
69-
return new WebSocketHandler() {
70-
@Override
71-
public void configure(WebSocketServletFactory factory) {
72-
factory.register(EchoSocket.class);
73-
}
74-
};
75-
}
76-
77-
7865
@Test(groups = "standalone", timeOut = 60000)
7966
public void testRedirectToWSResource() throws Exception {
8067
try (AsyncHttpClient c = asyncHttpClient(config().setFollowRedirect(true))) {

client/src/test/java/org/asynchttpclient/ws/TextMessageTest.java

+1-13
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,9 @@
2121
import java.util.concurrent.atomic.AtomicReference;
2222

2323
import org.asynchttpclient.AsyncHttpClient;
24-
import org.eclipse.jetty.websocket.server.WebSocketHandler;
25-
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
2624
import org.testng.annotations.Test;
2725

28-
public class TextMessageTest extends AbstractBasicTest {
29-
30-
@Override
31-
public WebSocketHandler getWebSocketHandler() {
32-
return new WebSocketHandler() {
33-
@Override
34-
public void configure(WebSocketServletFactory factory) {
35-
factory.register(EchoSocket.class);
36-
}
37-
};
38-
}
26+
public class TextMessageTest extends AbstractBasicWebSocketTest {
3927

4028
@Test(groups = "standalone", timeOut = 60000)
4129
public void onOpen() throws Exception {

client/src/test/java/org/asynchttpclient/ws/WebSocketWriteFutureTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
2525
import org.testng.annotations.Test;
2626

27-
public class WebSocketWriteFutureTest extends AbstractBasicTest {
27+
public class WebSocketWriteFutureTest extends AbstractBasicWebSocketTest {
2828

2929
@Override
30-
public WebSocketHandler getWebSocketHandler() {
30+
public WebSocketHandler configureHandler() {
3131
return new WebSocketHandler() {
3232
@Override
3333
public void configure(WebSocketServletFactory factory) {

0 commit comments

Comments
 (0)