Skip to content

Commit 814bba0

Browse files
committed
Add example of accessing string message from handler
1 parent d642cb2 commit 814bba0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/AndroidClient/client/src/test/java/net/servicestack/client/ServerEventClientTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,13 @@ public void test_Does_reconnect_on_lost_connection() throws Exception {
363363
public void test_Does_send_message_to_Handler() throws Exception {
364364

365365
List<ChatMessage> chatMsgs = new ArrayList<>();
366+
List<String> paintMsgs = new ArrayList<>();
366367

367368
try(ServerEventsClient client1 = createServerEventsClient("http://chat.servicestack.net")
369+
.registerHandler("paint", (client, e) -> {
370+
String color = JsonUtils.fromJson(e.getJson(), String.class);
371+
paintMsgs.add(color);
372+
})
368373
.registerHandler("chat", (client, e) -> {
369374
ChatMessage chatMsg = JsonUtils.fromJson(e.getJson(), ChatMessage.class);
370375
chatMsgs.add(chatMsg);
@@ -389,6 +394,14 @@ public void test_Does_send_message_to_Handler() throws Exception {
389394

390395
chatMsg = Func.last(chatMsgs);
391396
assertEquals("msg2", chatMsg.getMessage());
397+
398+
postRaw(client1, "cmd.paint$#town", "red");
399+
400+
while (paintMsgs.size() < 1){
401+
Thread.sleep(100);
402+
}
403+
404+
assertEquals("red", paintMsgs.get(0));
392405
}
393406
}
394407

0 commit comments

Comments
 (0)