use of org.springframework.messaging.Message in project spring-framework by spring-projects.
the class SendToMethodReturnValueHandlerTests method sendToUserWithUserNameProvider.
@Test
public void sendToUserWithUserNameProvider() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1";
TestUser user = new UniqueUser();
Message<?> inputMessage = createMessage(sessionId, "sub1", null, null, user);
this.handler.handleReturnValue(PAYLOAD, this.sendToUserReturnType, inputMessage);
verify(this.messageChannel, times(2)).send(this.messageCaptor.capture());
SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
assertEquals("/user/Me myself and I/dest1", accessor.getDestination());
accessor = getCapturedAccessor(1);
assertEquals("/user/Me myself and I/dest2", accessor.getDestination());
}
use of org.springframework.messaging.Message in project spring-framework by spring-projects.
the class SendToMethodReturnValueHandlerTests method sendToUserDefaultDestination.
@Test
public void sendToUserDefaultDestination() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1";
TestUser user = new TestUser();
Message<?> inputMessage = createMessage(sessionId, "sub1", "/app", "/dest", user);
this.handler.handleReturnValue(PAYLOAD, this.sendToUserDefaultDestReturnType, inputMessage);
verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
assertNull(accessor.getSessionId());
assertNull(accessor.getSubscriptionId());
assertEquals("/user/" + user.getName() + "/queue/dest", accessor.getDestination());
}
use of org.springframework.messaging.Message in project spring-framework by spring-projects.
the class SimpAnnotationMethodMessageHandlerTests method completableFutureFailure.
@Test
@SuppressWarnings("unchecked")
public void completableFutureFailure() {
Message emptyMessage = (Message) MessageBuilder.withPayload(new byte[0]).build();
given(this.channel.send(any(Message.class))).willReturn(true);
given(this.converter.toMessage(any(), any(MessageHeaders.class))).willReturn(emptyMessage);
CompletableFutureController controller = new CompletableFutureController();
this.messageHandler.registerHandler(controller);
this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/"));
Message<?> message = createMessage("/app1/completable-future");
this.messageHandler.handleMessage(message);
controller.future.completeExceptionally(new IllegalStateException());
assertTrue(controller.exceptionCaught);
}
use of org.springframework.messaging.Message in project spring-framework by spring-projects.
the class SubscriptionMethodReturnValueHandlerTests method testMessageSentToChannel.
@Test
public void testMessageSentToChannel() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1";
String subscriptionId = "subs1";
String destination = "/dest";
Message<?> inputMessage = createInputMessage(sessionId, subscriptionId, destination, null);
this.handler.handleReturnValue(PAYLOAD, this.subscribeEventReturnType, inputMessage);
verify(this.messageChannel).send(this.messageCaptor.capture());
assertNotNull(this.messageCaptor.getValue());
Message<?> message = this.messageCaptor.getValue();
SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.wrap(message);
assertNull("SimpMessageHeaderAccessor should have disabled id", headerAccessor.getId());
assertNull("SimpMessageHeaderAccessor should have disabled timestamp", headerAccessor.getTimestamp());
assertEquals(sessionId, headerAccessor.getSessionId());
assertEquals(subscriptionId, headerAccessor.getSubscriptionId());
assertEquals(destination, headerAccessor.getDestination());
assertEquals(MIME_TYPE, headerAccessor.getContentType());
assertEquals(this.subscribeEventReturnType, headerAccessor.getHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER));
}
use of org.springframework.messaging.Message in project spring-framework by spring-projects.
the class MessageMethodArgumentResolverTests method resolveWithConversion.
@Test
public void resolveWithConversion() throws Exception {
Message<String> message = MessageBuilder.withPayload("test").build();
MethodParameter parameter = new MethodParameter(this.method, 1);
when(this.converter.fromMessage(message, Integer.class)).thenReturn(4);
@SuppressWarnings("unchecked") Message<Integer> actual = (Message<Integer>) this.resolver.resolveArgument(parameter, message);
assertNotNull(actual);
assertSame(message.getHeaders(), actual.getHeaders());
assertEquals(new Integer(4), actual.getPayload());
}
Aggregations