Package ch.colabproject.colab.tests.ws
Class WebsocketClient
- java.lang.Object
-
- ch.colabproject.colab.tests.ws.WebsocketClient
-
public class WebsocketClient extends Object
- Author:
- maxence
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static WebsocketClient
build(String endpoint)
void
clearMessages()
Clear received messagesvoid
close()
List<WsMessage>
getMessages(int numberOfExpectedMessages, int timeout)
wait until client receivednumberOfExpectedMessages
messages.WsSessionIdentifier
getSessionId()
void
onClose(javax.websocket.Session session, javax.websocket.CloseReason reason)
On close callbackvoid
onOpen(javax.websocket.Session session)
Callback hook for Connection open events.void
onRawMessage(String message)
On message callback.void
sendMessage(WsMessage message)
Send a message.
-
-
-
Method Detail
-
onOpen
public void onOpen(javax.websocket.Session session)
Callback hook for Connection open events.- Parameters:
session
- client session
-
onClose
public void onClose(javax.websocket.Session session, javax.websocket.CloseReason reason)
On close callback- Parameters:
session
- the sessionreason
- the reason
-
onRawMessage
public void onRawMessage(String message)
On message callback.- Parameters:
message
- the message
-
sendMessage
public void sendMessage(WsMessage message) throws IOException, javax.websocket.EncodeException
Send a message.- Parameters:
message
- the message to send- Throws:
IOException
- failed to send the messagejavax.websocket.EncodeException
- websocket error
-
getMessages
public List<WsMessage> getMessages(int numberOfExpectedMessages, int timeout)
wait until client receivednumberOfExpectedMessages
messages.- Parameters:
numberOfExpectedMessages
- number of expected messagestimeout
- stop waiting after this amount of second- Returns:
- list of messages
-
getSessionId
public WsSessionIdentifier getSessionId()
-
clearMessages
public void clearMessages()
Clear received messages
-
close
public void close() throws IOException
- Throws:
IOException
-
build
public static WebsocketClient build(String endpoint) throws javax.websocket.DeploymentException, IOException, URISyntaxException, InterruptedException
- Throws:
javax.websocket.DeploymentException
IOException
URISyntaxException
InterruptedException
-
-