@Test public void receiveAndConvertNoConverter() { Message<?> expected = new GenericMessage<>("payload"); this.template.setDefaultDestination("home"); this.template.setReceiveMessage(expected); this.template.setMessageConverter(new GenericMessageConverter()); try { this.template.receiveAndConvert(Writer.class); } catch (MessageConversionException ex) { assertTrue("Invalid exception message '" + ex.getMessage() + "'", ex.getMessage().contains("payload")); assertSame(expected, ex.getFailedMessage()); } }
@Test(expected = IllegalStateException.class) public void receiveMissingDefaultDestination() { this.template.receive(); }
@Test public void receiveAndConvertFromDestination() { Message<?> expected = new GenericMessage<>("payload"); this.template.setReceiveMessage(expected); String payload = this.template.receiveAndConvert("somewhere", String.class); assertEquals("somewhere", this.template.destination); assertSame("payload", payload); }
@Before public void setup() { this.template = new TestMessagingTemplate(); }
@Test public void receiveFromDestination() { Message<?> expected = new GenericMessage<>("payload"); this.template.setReceiveMessage(expected); Message<?> actual = this.template.receive("somewhere"); assertEquals("somewhere", this.template.destination); assertSame(expected, actual); }
@Test public void receive() { Message<?> expected = new GenericMessage<>("payload"); this.template.setDefaultDestination("home"); this.template.setReceiveMessage(expected); Message<?> actual = this.template.receive(); assertEquals("home", this.template.destination); assertSame(expected, actual); }
@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); }
@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); }