use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class ConcurrentWebSocketSessionDecoratorTests method send.
@Test
public void send() throws IOException {
TestWebSocketSession session = new TestWebSocketSession();
session.setOpen(true);
ConcurrentWebSocketSessionDecorator decorator = new ConcurrentWebSocketSessionDecorator(session, 1000, 1024);
TextMessage textMessage = new TextMessage("payload");
decorator.sendMessage(textMessage);
assertThat(session.getSentMessages().size()).isEqualTo(1);
assertThat(session.getSentMessages().get(0)).isEqualTo(textMessage);
assertThat(decorator.getBufferSize()).isEqualTo(0);
assertThat(decorator.getTimeSinceSendStarted()).isEqualTo(0);
assertThat(session.isOpen()).isTrue();
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class ClientSockJsSessionTests method handleFrameMessageWithWebSocketHandlerException.
@Test
public void handleFrameMessageWithWebSocketHandlerException() throws Exception {
this.session.handleFrame(SockJsFrame.openFrame().getContent());
willThrow(new IllegalStateException("Fake error")).given(this.handler).handleMessage(this.session, new TextMessage("foo"));
willThrow(new IllegalStateException("Fake error")).given(this.handler).handleMessage(this.session, new TextMessage("bar"));
this.session.handleFrame(SockJsFrame.messageFrame(CODEC, "foo", "bar").getContent());
assertThat(this.session.isOpen()).isTrue();
verify(this.handler).afterConnectionEstablished(this.session);
verify(this.handler).handleMessage(this.session, new TextMessage("foo"));
verify(this.handler).handleMessage(this.session, new TextMessage("bar"));
verifyNoMoreInteractions(this.handler);
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class XhrTransportTests method sendMessage.
@Test
public void sendMessage() throws Exception {
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set("foo", "bar");
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
TestXhrTransport transport = new TestXhrTransport();
transport.sendMessageResponseToReturn = new ResponseEntity<>(HttpStatus.NO_CONTENT);
URI url = new URI("https://example.com");
transport.executeSendRequest(url, requestHeaders, new TextMessage("payload"));
assertThat(transport.actualSendRequestHeaders.size()).isEqualTo(2);
assertThat(transport.actualSendRequestHeaders.getFirst("foo")).isEqualTo("bar");
assertThat(transport.actualSendRequestHeaders.getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class AbstractSockJsIntegrationTests method testEcho.
private void testEcho(int messageCount, Transport transport, WebSocketHttpHeaders headers) throws Exception {
List<TextMessage> messages = new ArrayList<>();
for (int i = 0; i < messageCount; i++) {
messages.add(new TextMessage("m" + i));
}
TestClientHandler handler = new TestClientHandler();
initSockJsClient(transport);
URI url = new URI(this.baseUrl + "/echo");
WebSocketSession session = this.sockJsClient.doHandshake(handler, headers, url).get();
for (TextMessage message : messages) {
session.sendMessage(message);
}
handler.awaitMessageCount(messageCount, 5000);
for (TextMessage message : messages) {
assertThat(handler.receivedMessages.remove(message)).as("Message not received: " + message).isTrue();
}
assertThat(handler.receivedMessages.size()).as("Remaining messages: " + handler.receivedMessages).isEqualTo(0);
session.close();
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class AbstractSockJsIntegrationTests method testReceiveOneMessage.
private void testReceiveOneMessage(Transport transport, WebSocketHttpHeaders headers) throws Exception {
TestClientHandler clientHandler = new TestClientHandler();
initSockJsClient(transport);
this.sockJsClient.doHandshake(clientHandler, headers, new URI(this.baseUrl + "/test")).get();
TestServerHandler serverHandler = this.wac.getBean(TestServerHandler.class);
assertThat(clientHandler.session).as("afterConnectionEstablished should have been called").isNotNull();
serverHandler.awaitSession(5000);
TextMessage message = new TextMessage("message1");
serverHandler.session.sendMessage(message);
clientHandler.awaitMessage(message, 5000);
}
Aggregations