-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebSocketClientRunner.java
47 lines (40 loc) · 1.24 KB
/
WebSocketClientRunner.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package demo.websocket;
import com.intuit.karate.netty.WebSocketClient;
import com.intuit.karate.netty.WebSocketOptions;
import demo.TestBase;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author pthomas3
*/
public class WebSocketClientRunner {
private static final Logger logger = LoggerFactory.getLogger(WebSocketClientRunner.class);
private WebSocketClient client;
private String result;
@BeforeClass
public static void beforeClass() throws Exception {
TestBase.beforeClass();
}
@Test
public void testWebSocketClient() throws Exception {
String port = System.getProperty("demo.server.port");
WebSocketOptions options = new WebSocketOptions("ws://localhost:" + port + "/websocket");
options.setTextConsumer(text -> {
logger.debug("websocket listener text: {}", text);
synchronized (this) {
result = text;
notify();
}
});
client = new WebSocketClient(options);
client.send("Billie");
synchronized (this) {
wait();
}
assertEquals("hello Billie !", result);
}
}