|
14 | 14 |
|
15 | 15 | import static org.asynchttpclient.test.TestUtils.addHttpConnector;
|
16 | 16 |
|
| 17 | +import org.asynchttpclient.AbstractBasicTest; |
17 | 18 | import org.eclipse.jetty.server.Server;
|
18 | 19 | import org.eclipse.jetty.server.ServerConnector;
|
19 | 20 | import org.eclipse.jetty.websocket.server.WebSocketHandler;
|
20 |
| -import org.testng.annotations.AfterClass; |
| 21 | +import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; |
21 | 22 | import org.testng.annotations.BeforeClass;
|
22 | 23 |
|
23 |
| -public abstract class AbstractBasicTest extends org.asynchttpclient.AbstractBasicTest { |
| 24 | +public abstract class AbstractBasicWebSocketTest extends AbstractBasicTest { |
24 | 25 |
|
25 | 26 | @BeforeClass(alwaysRun = true)
|
| 27 | + @Override |
26 | 28 | public void setUpGlobal() throws Exception {
|
27 | 29 | server = new Server();
|
28 | 30 | ServerConnector connector = addHttpConnector(server);
|
29 |
| - server.setHandler(getWebSocketHandler()); |
| 31 | + server.setHandler(configureHandler()); |
30 | 32 | server.start();
|
31 | 33 | port1 = connector.getLocalPort();
|
32 | 34 | logger.info("Local HTTP server started successfully");
|
33 | 35 | }
|
34 | 36 |
|
35 |
| - @AfterClass(alwaysRun = true) |
36 |
| - public void tearDownGlobal() throws Exception { |
37 |
| - server.stop(); |
38 |
| - } |
39 |
| - |
40 | 37 | protected String getTargetUrl() {
|
41 | 38 | return String.format("ws://localhost:%d/", port1);
|
42 | 39 | }
|
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 | + } |
45 | 50 | }
|
0 commit comments