@Override public void handleMessage(Message<?> message) throws MessagingException { MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel(); replyChannel.send(new GenericMessage<>("response")); } });
@Test(expected = IllegalStateException.class) public void sendMissingDestination() { Message<?> message = new GenericMessage<Object>("payload"); this.template.send(message); }
@Test public void sendAndReceive() { Message<?> requestMessage = new GenericMessage<Object>("request"); Message<?> responseMessage = new GenericMessage<Object>("response"); this.template.setReceiveMessage(responseMessage); Message<?> actual = this.template.sendAndReceive("myChannel", requestMessage); assertEquals(requestMessage, this.template.message); assertSame(responseMessage, actual); assertSame(this.myChannel, this.template.messageChannel); }
@Test public void sendAndReceiveToDestination() { Message<?> requestMessage = new GenericMessage<Object>("request"); Message<?> responseMessage = new GenericMessage<Object>("response"); this.template.setReceiveMessage(responseMessage); Message<?> actual = this.template.sendAndReceive("somewhere", requestMessage); assertEquals("somewhere", this.template.destination); assertSame(requestMessage, this.template.requestMessage); assertSame(responseMessage, actual); }
@Test(expected = IllegalStateException.class) public void sendNoDestinationResolver() { TestDestinationResolvingMessagingTemplate template = new TestDestinationResolvingMessagingTemplate(); template.send("myChannel", new GenericMessage<Object>("payload")); }
@Test public void convertAndSendToDestination() { Message<?> responseMessage = new GenericMessage<Object>("response"); this.template.setReceiveMessage(responseMessage); String response = this.template.convertSendAndReceive("somewhere", "request", String.class); assertEquals("somewhere", this.template.destination); assertSame("request", this.template.requestMessage.getPayload()); assertSame("response", response); }
@Test public void sendToDestination() { Message<?> message = new GenericMessage<Object>("payload"); this.template.send("somewhere", message); assertEquals("somewhere", this.template.destination); assertSame(message, this.template.message); }
@Test public void receive() { Message<?> expected = new GenericMessage<Object>("payload"); this.template.setReceiveMessage(expected); Message<?> actual = this.template.receive("myChannel"); assertSame(expected, actual); assertSame(this.myChannel, this.template.messageChannel); }
@Test public void convertAndSendToDestinationWithHeaders() { Message<?> responseMessage = new GenericMessage<Object>("response"); this.template.setReceiveMessage(responseMessage); String response = this.template.convertSendAndReceive("somewhere", "request", this.headers, String.class); assertEquals("somewhere", this.template.destination); assertEquals("value", this.template.requestMessage.getHeaders().get("key")); assertSame("request", this.template.requestMessage.getPayload()); assertSame("response", response); }
@Test public void send() { Message<?> message = new GenericMessage<Object>("payload"); this.template.send("myChannel", message); assertSame(this.myChannel, this.template.messageChannel); assertSame(message, this.template.message); }
@Test public void convertSendAndReceiveWithPostProcessor() { Message<?> responseMessage = new GenericMessage<Object>("response"); this.template.setReceiveMessage(responseMessage); String actual = this.template.convertSendAndReceive("myChannel", "request", String.class, this.postProcessor); assertEquals("request", this.template.message.getPayload()); assertSame("request", this.postProcessor.getMessage().getPayload()); assertSame("response", actual); assertSame(this.myChannel, this.template.messageChannel); }
@Test public void existingHeaders() throws InterruptedException { Map<String, Object> map = new HashMap<>(); map.put("foo", "bar"); map.put("bar", "baz"); GenericMessage<String> message = new GenericMessage<>("payload", map); MessageHeaderAccessor accessor = new MessageHeaderAccessor(message); MessageHeaders actual = accessor.getMessageHeaders(); assertEquals(3, actual.size()); assertEquals("bar", actual.get("foo")); assertEquals("baz", actual.get("bar")); }
@Test public void convertAndSend() { Message<?> responseMessage = new GenericMessage<Object>("response"); this.template.setDefaultDestination("home"); this.template.setReceiveMessage(responseMessage); String response = this.template.convertSendAndReceive("request", String.class); assertEquals("home", this.template.destination); assertSame("request", this.template.requestMessage.getPayload()); assertSame("response", response); }
@Test public void receiveAndConvert() { Message<?> expected = new GenericMessage<>("payload"); this.template.setDefaultDestination("home"); this.template.setReceiveMessage(expected); String payload = this.template.receiveAndConvert(String.class); assertEquals("home", this.template.destination); assertSame("payload", payload); }
@Test public void setAttributesFromMessageWithMissingSessionId() { this.thrown.expect(IllegalStateException.class); this.thrown.expectMessage(startsWith("No session id in")); SimpAttributesContextHolder.setAttributesFromMessage(new GenericMessage<Object>("")); }
@Test public void send() { Message<?> message = new GenericMessage<Object>("payload"); this.template.setDefaultDestination("home"); this.template.send(message); assertEquals("home", this.template.destination); assertSame(message, this.template.message); }
@Test public void convertAndSendToDestinationWithPostProcessor() { Message<?> responseMessage = new GenericMessage<Object>("response"); this.template.setReceiveMessage(responseMessage); String response = this.template.convertSendAndReceive("somewhere", "request", String.class, this.postProcessor); assertEquals("somewhere", this.template.destination); assertSame("request", this.template.requestMessage.getPayload()); assertSame("response", response); assertSame(this.postProcessor.getMessage(), this.template.requestMessage); }
@Test public void convertAndSendToDestinationWithHeadersAndPostProcessor() { Message<?> responseMessage = new GenericMessage<Object>("response"); this.template.setReceiveMessage(responseMessage); String response = this.template.convertSendAndReceive("somewhere", "request", this.headers, String.class, this.postProcessor); assertEquals("somewhere", this.template.destination); assertEquals("value", this.template.requestMessage.getHeaders().get("key")); assertSame("request", this.template.requestMessage.getPayload()); assertSame("response", response); assertSame(this.postProcessor.getMessage(), this.template.requestMessage); }
@Test public void convertAndSendWithPostProcessor() { Message<?> responseMessage = new GenericMessage<Object>("response"); this.template.setDefaultDestination("home"); this.template.setReceiveMessage(responseMessage); String response = this.template.convertSendAndReceive("request", String.class, this.postProcessor); assertEquals("home", this.template.destination); assertSame("request", this.template.requestMessage.getPayload()); assertSame("response", response); assertSame(this.postProcessor.getMessage(), this.template.requestMessage); }
@Test public void receiveAndConvertFailed() { Message<?> expected = new GenericMessage<>("not a number test"); this.template.setReceiveMessage(expected); this.template.setMessageConverter(new GenericMessageConverter()); thrown.expect(MessageConversionException.class); thrown.expectCause(isA(ConversionFailedException.class)); this.template.receiveAndConvert("somewhere", Integer.class); }