Polish
This commit is contained in:
parent
c5ba55ffc2
commit
7aa956a920
|
|
@ -54,6 +54,8 @@ import static org.junit.Assert.*;
|
|||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* Tests for {@link JmsMessagingTemplate}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class JmsMessagingTemplateTests {
|
||||
|
|
@ -73,12 +75,12 @@ public class JmsMessagingTemplateTests {
|
|||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
messagingTemplate = new JmsMessagingTemplate(jmsTemplate);
|
||||
this.messagingTemplate = new JmsMessagingTemplate(this.jmsTemplate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateJmsTemplate() {
|
||||
assertSame(this.jmsTemplate, messagingTemplate.getJmsTemplate());
|
||||
assertSame(this.jmsTemplate, this.messagingTemplate.getJmsTemplate());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -86,110 +88,110 @@ public class JmsMessagingTemplateTests {
|
|||
Destination destination = new Destination() {};
|
||||
Message<String> message = createTextMessage();
|
||||
|
||||
messagingTemplate.send(destination, message);
|
||||
verify(jmsTemplate).send(eq(destination), messageCreator.capture());
|
||||
assertTextMessage(messageCreator.getValue());
|
||||
this.messagingTemplate.send(destination, message);
|
||||
verify(this.jmsTemplate).send(eq(destination), this.messageCreator.capture());
|
||||
assertTextMessage(this.messageCreator.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendName() {
|
||||
Message<String> message = createTextMessage();
|
||||
|
||||
messagingTemplate.send("myQueue", message);
|
||||
verify(jmsTemplate).send(eq("myQueue"), messageCreator.capture());
|
||||
assertTextMessage(messageCreator.getValue());
|
||||
this.messagingTemplate.send("myQueue", message);
|
||||
verify(this.jmsTemplate).send(eq("myQueue"), this.messageCreator.capture());
|
||||
assertTextMessage(this.messageCreator.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendDefaultDestination() {
|
||||
Destination destination = new Destination() {};
|
||||
messagingTemplate.setDefaultDestination(destination);
|
||||
this.messagingTemplate.setDefaultDestination(destination);
|
||||
Message<String> message = createTextMessage();
|
||||
|
||||
messagingTemplate.send(message);
|
||||
verify(jmsTemplate).send(eq(destination), messageCreator.capture());
|
||||
assertTextMessage(messageCreator.getValue());
|
||||
this.messagingTemplate.send(message);
|
||||
verify(this.jmsTemplate).send(eq(destination), this.messageCreator.capture());
|
||||
assertTextMessage(this.messageCreator.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendDefaultDestinationName() {
|
||||
messagingTemplate.setDefaultDestinationName("myQueue");
|
||||
this.messagingTemplate.setDefaultDestinationName("myQueue");
|
||||
Message<String> message = createTextMessage();
|
||||
|
||||
messagingTemplate.send(message);
|
||||
verify(jmsTemplate).send(eq("myQueue"), messageCreator.capture());
|
||||
assertTextMessage(messageCreator.getValue());
|
||||
this.messagingTemplate.send(message);
|
||||
verify(this.jmsTemplate).send(eq("myQueue"), this.messageCreator.capture());
|
||||
assertTextMessage(this.messageCreator.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendNoDefaultSet() {
|
||||
Message<String> message = createTextMessage();
|
||||
|
||||
thrown.expect(IllegalStateException.class);
|
||||
messagingTemplate.send(message);
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.messagingTemplate.send(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendPropertyInjection() {
|
||||
JmsMessagingTemplate t = new JmsMessagingTemplate();
|
||||
t.setJmsTemplate(jmsTemplate);
|
||||
t.setJmsTemplate(this.jmsTemplate);
|
||||
t.setDefaultDestinationName("myQueue");
|
||||
t.afterPropertiesSet();
|
||||
Message<String> message = createTextMessage();
|
||||
|
||||
t.send(message);
|
||||
verify(jmsTemplate).send(eq("myQueue"), messageCreator.capture());
|
||||
assertTextMessage(messageCreator.getValue());
|
||||
verify(this.jmsTemplate).send(eq("myQueue"), this.messageCreator.capture());
|
||||
assertTextMessage(this.messageCreator.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertAndSendPayload() throws JMSException {
|
||||
Destination destination = new Destination() {};
|
||||
|
||||
messagingTemplate.convertAndSend(destination, "my Payload");
|
||||
verify(jmsTemplate).send(eq(destination), messageCreator.capture());
|
||||
TextMessage textMessage = createTextMessage(messageCreator.getValue());
|
||||
this.messagingTemplate.convertAndSend(destination, "my Payload");
|
||||
verify(this.jmsTemplate).send(eq(destination), this.messageCreator.capture());
|
||||
TextMessage textMessage = createTextMessage(this.messageCreator.getValue());
|
||||
assertEquals("my Payload", textMessage.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertAndSendPayloadName() throws JMSException {
|
||||
messagingTemplate.convertAndSend("myQueue", "my Payload");
|
||||
verify(jmsTemplate).send(eq("myQueue"), messageCreator.capture());
|
||||
TextMessage textMessage = createTextMessage(messageCreator.getValue());
|
||||
this.messagingTemplate.convertAndSend("myQueue", "my Payload");
|
||||
verify(this.jmsTemplate).send(eq("myQueue"), this.messageCreator.capture());
|
||||
TextMessage textMessage = createTextMessage(this.messageCreator.getValue());
|
||||
assertEquals("my Payload", textMessage.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertAndSendDefaultDestination() throws JMSException {
|
||||
Destination destination = new Destination() {};
|
||||
messagingTemplate.setDefaultDestination(destination);
|
||||
this.messagingTemplate.setDefaultDestination(destination);
|
||||
|
||||
messagingTemplate.convertAndSend("my Payload");
|
||||
verify(jmsTemplate).send(eq(destination), messageCreator.capture());
|
||||
TextMessage textMessage = createTextMessage(messageCreator.getValue());
|
||||
this.messagingTemplate.convertAndSend("my Payload");
|
||||
verify(this.jmsTemplate).send(eq(destination), this.messageCreator.capture());
|
||||
TextMessage textMessage = createTextMessage(this.messageCreator.getValue());
|
||||
assertEquals("my Payload", textMessage.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertAndSendDefaultDestinationName() throws JMSException {
|
||||
messagingTemplate.setDefaultDestinationName("myQueue");
|
||||
this.messagingTemplate.setDefaultDestinationName("myQueue");
|
||||
|
||||
messagingTemplate.convertAndSend("my Payload");
|
||||
verify(jmsTemplate).send(eq("myQueue"), messageCreator.capture());
|
||||
TextMessage textMessage = createTextMessage(messageCreator.getValue());
|
||||
this.messagingTemplate.convertAndSend("my Payload");
|
||||
verify(this.jmsTemplate).send(eq("myQueue"), this.messageCreator.capture());
|
||||
TextMessage textMessage = createTextMessage(this.messageCreator.getValue());
|
||||
assertEquals("my Payload", textMessage.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertAndSendNoDefaultSet() throws JMSException {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
messagingTemplate.convertAndSend("my Payload");
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.messagingTemplate.convertAndSend("my Payload");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertAndSendCustomJmsMessageConverter() throws JMSException {
|
||||
messagingTemplate.setJmsMessageConverter(new SimpleMessageConverter() {
|
||||
this.messagingTemplate.setJmsMessageConverter(new SimpleMessageConverter() {
|
||||
@Override
|
||||
public javax.jms.Message toMessage(Object object, Session session)
|
||||
throws JMSException, org.springframework.jms.support.converter.MessageConversionException {
|
||||
|
|
@ -197,12 +199,12 @@ public class JmsMessagingTemplateTests {
|
|||
}
|
||||
});
|
||||
|
||||
messagingTemplate.convertAndSend("myQueue", "msg to convert");
|
||||
verify(jmsTemplate).send(eq("myQueue"), messageCreator.capture());
|
||||
this.messagingTemplate.convertAndSend("myQueue", "msg to convert");
|
||||
verify(this.jmsTemplate).send(eq("myQueue"), this.messageCreator.capture());
|
||||
|
||||
thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
thrown.expectMessage(new StringContains("Test exception"));
|
||||
messageCreator.getValue().createMessage(mock(Session.class));
|
||||
this.thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
this.thrown.expectMessage(new StringContains("Test exception"));
|
||||
this.messageCreator.getValue().createMessage(mock(Session.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -211,9 +213,9 @@ public class JmsMessagingTemplateTests {
|
|||
Map<String, Object> headers = new HashMap<>();
|
||||
headers.put("foo", "bar");
|
||||
|
||||
messagingTemplate.convertAndSend(destination, "Hello", headers);
|
||||
verify(jmsTemplate).send(eq(destination), messageCreator.capture());
|
||||
assertTextMessage(messageCreator.getValue()); // see createTextMessage
|
||||
this.messagingTemplate.convertAndSend(destination, "Hello", headers);
|
||||
verify(this.jmsTemplate).send(eq(destination), this.messageCreator.capture());
|
||||
assertTextMessage(this.messageCreator.getValue()); // see createTextMessage
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -221,131 +223,131 @@ public class JmsMessagingTemplateTests {
|
|||
Map<String, Object> headers = new HashMap<>();
|
||||
headers.put("foo", "bar");
|
||||
|
||||
messagingTemplate.convertAndSend("myQueue", "Hello", headers);
|
||||
verify(jmsTemplate).send(eq("myQueue"), messageCreator.capture());
|
||||
assertTextMessage(messageCreator.getValue()); // see createTextMessage
|
||||
this.messagingTemplate.convertAndSend("myQueue", "Hello", headers);
|
||||
verify(this.jmsTemplate).send(eq("myQueue"), this.messageCreator.capture());
|
||||
assertTextMessage(this.messageCreator.getValue()); // see createTextMessage
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receive() {
|
||||
Destination destination = new Destination() {};
|
||||
javax.jms.Message jmsMessage = createJmsTextMessage();
|
||||
given(jmsTemplate.receive(destination)).willReturn(jmsMessage);
|
||||
given(this.jmsTemplate.receive(destination)).willReturn(jmsMessage);
|
||||
|
||||
Message<?> message = messagingTemplate.receive(destination);
|
||||
verify(jmsTemplate).receive(destination);
|
||||
Message<?> message = this.messagingTemplate.receive(destination);
|
||||
verify(this.jmsTemplate).receive(destination);
|
||||
assertTextMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveName() {
|
||||
javax.jms.Message jmsMessage = createJmsTextMessage();
|
||||
given(jmsTemplate.receive("myQueue")).willReturn(jmsMessage);
|
||||
given(this.jmsTemplate.receive("myQueue")).willReturn(jmsMessage);
|
||||
|
||||
Message<?> message = messagingTemplate.receive("myQueue");
|
||||
verify(jmsTemplate).receive("myQueue");
|
||||
Message<?> message = this.messagingTemplate.receive("myQueue");
|
||||
verify(this.jmsTemplate).receive("myQueue");
|
||||
assertTextMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveDefaultDestination() {
|
||||
Destination destination = new Destination() {};
|
||||
messagingTemplate.setDefaultDestination(destination);
|
||||
this.messagingTemplate.setDefaultDestination(destination);
|
||||
javax.jms.Message jmsMessage = createJmsTextMessage();
|
||||
given(jmsTemplate.receive(destination)).willReturn(jmsMessage);
|
||||
given(this.jmsTemplate.receive(destination)).willReturn(jmsMessage);
|
||||
|
||||
Message<?> message = messagingTemplate.receive();
|
||||
verify(jmsTemplate).receive(destination);
|
||||
Message<?> message = this.messagingTemplate.receive();
|
||||
verify(this.jmsTemplate).receive(destination);
|
||||
assertTextMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveDefaultDestinationName() {
|
||||
messagingTemplate.setDefaultDestinationName("myQueue");
|
||||
this.messagingTemplate.setDefaultDestinationName("myQueue");
|
||||
javax.jms.Message jmsMessage = createJmsTextMessage();
|
||||
given(jmsTemplate.receive("myQueue")).willReturn(jmsMessage);
|
||||
given(this.jmsTemplate.receive("myQueue")).willReturn(jmsMessage);
|
||||
|
||||
Message<?> message = messagingTemplate.receive();
|
||||
verify(jmsTemplate).receive("myQueue");
|
||||
Message<?> message = this.messagingTemplate.receive();
|
||||
verify(this.jmsTemplate).receive("myQueue");
|
||||
assertTextMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveNoDefaultSet() {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
messagingTemplate.receive();
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.messagingTemplate.receive();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveAndConvert() {
|
||||
Destination destination = new Destination() {};
|
||||
javax.jms.Message jmsMessage = createJmsTextMessage("my Payload");
|
||||
given(jmsTemplate.receive(destination)).willReturn(jmsMessage);
|
||||
given(this.jmsTemplate.receive(destination)).willReturn(jmsMessage);
|
||||
|
||||
String payload = messagingTemplate.receiveAndConvert(destination, String.class);
|
||||
String payload = this.messagingTemplate.receiveAndConvert(destination, String.class);
|
||||
assertEquals("my Payload", payload);
|
||||
verify(jmsTemplate).receive(destination);
|
||||
verify(this.jmsTemplate).receive(destination);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveAndConvertName() {
|
||||
javax.jms.Message jmsMessage = createJmsTextMessage("my Payload");
|
||||
given(jmsTemplate.receive("myQueue")).willReturn(jmsMessage);
|
||||
given(this.jmsTemplate.receive("myQueue")).willReturn(jmsMessage);
|
||||
|
||||
String payload = messagingTemplate.receiveAndConvert("myQueue", String.class);
|
||||
String payload = this.messagingTemplate.receiveAndConvert("myQueue", String.class);
|
||||
assertEquals("my Payload", payload);
|
||||
verify(jmsTemplate).receive("myQueue");
|
||||
verify(this.jmsTemplate).receive("myQueue");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveAndConvertDefaultDestination() {
|
||||
Destination destination = new Destination() {};
|
||||
messagingTemplate.setDefaultDestination(destination);
|
||||
this.messagingTemplate.setDefaultDestination(destination);
|
||||
javax.jms.Message jmsMessage = createJmsTextMessage("my Payload");
|
||||
given(jmsTemplate.receive(destination)).willReturn(jmsMessage);
|
||||
given(this.jmsTemplate.receive(destination)).willReturn(jmsMessage);
|
||||
|
||||
String payload = messagingTemplate.receiveAndConvert(String.class);
|
||||
String payload = this.messagingTemplate.receiveAndConvert(String.class);
|
||||
assertEquals("my Payload", payload);
|
||||
verify(jmsTemplate).receive(destination);
|
||||
verify(this.jmsTemplate).receive(destination);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveAndConvertDefaultDestinationName() {
|
||||
messagingTemplate.setDefaultDestinationName("myQueue");
|
||||
this.messagingTemplate.setDefaultDestinationName("myQueue");
|
||||
javax.jms.Message jmsMessage = createJmsTextMessage("my Payload");
|
||||
given(jmsTemplate.receive("myQueue")).willReturn(jmsMessage);
|
||||
given(this.jmsTemplate.receive("myQueue")).willReturn(jmsMessage);
|
||||
|
||||
String payload = messagingTemplate.receiveAndConvert(String.class);
|
||||
String payload = this.messagingTemplate.receiveAndConvert(String.class);
|
||||
assertEquals("my Payload", payload);
|
||||
verify(jmsTemplate).receive("myQueue");
|
||||
verify(this.jmsTemplate).receive("myQueue");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveAndConvertWithConversion() {
|
||||
javax.jms.Message jmsMessage = createJmsTextMessage("123");
|
||||
given(jmsTemplate.receive("myQueue")).willReturn(jmsMessage);
|
||||
given(this.jmsTemplate.receive("myQueue")).willReturn(jmsMessage);
|
||||
|
||||
messagingTemplate.setMessageConverter(new GenericMessageConverter());
|
||||
this.messagingTemplate.setMessageConverter(new GenericMessageConverter());
|
||||
|
||||
Integer payload = messagingTemplate.receiveAndConvert("myQueue", Integer.class);
|
||||
Integer payload = this.messagingTemplate.receiveAndConvert("myQueue", Integer.class);
|
||||
assertEquals(Integer.valueOf(123), payload);
|
||||
verify(jmsTemplate).receive("myQueue");
|
||||
verify(this.jmsTemplate).receive("myQueue");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveAndConvertNoConverter() {
|
||||
javax.jms.Message jmsMessage = createJmsTextMessage("Hello");
|
||||
given(jmsTemplate.receive("myQueue")).willReturn(jmsMessage);
|
||||
given(this.jmsTemplate.receive("myQueue")).willReturn(jmsMessage);
|
||||
|
||||
thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
messagingTemplate.receiveAndConvert("myQueue", Writer.class);
|
||||
this.thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
this.messagingTemplate.receiveAndConvert("myQueue", Writer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveAndConvertNoInput() {
|
||||
given(jmsTemplate.receive("myQueue")).willReturn(null);
|
||||
given(this.jmsTemplate.receive("myQueue")).willReturn(null);
|
||||
|
||||
assertNull(messagingTemplate.receiveAndConvert("myQueue", String.class));
|
||||
assertNull(this.messagingTemplate.receiveAndConvert("myQueue", String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -353,10 +355,10 @@ public class JmsMessagingTemplateTests {
|
|||
Destination destination = new Destination() {};
|
||||
Message<String> request = createTextMessage();
|
||||
javax.jms.Message replyJmsMessage = createJmsTextMessage();
|
||||
given(jmsTemplate.sendAndReceive(eq(destination), any())).willReturn(replyJmsMessage);
|
||||
given(this.jmsTemplate.sendAndReceive(eq(destination), any())).willReturn(replyJmsMessage);
|
||||
|
||||
Message<?> actual = messagingTemplate.sendAndReceive(destination, request);
|
||||
verify(jmsTemplate, times(1)).sendAndReceive(eq(destination), any());
|
||||
Message<?> actual = this.messagingTemplate.sendAndReceive(destination, request);
|
||||
verify(this.jmsTemplate, times(1)).sendAndReceive(eq(destination), any());
|
||||
assertTextMessage(actual);
|
||||
}
|
||||
|
||||
|
|
@ -364,35 +366,35 @@ public class JmsMessagingTemplateTests {
|
|||
public void sendAndReceiveName() {
|
||||
Message<String> request = createTextMessage();
|
||||
javax.jms.Message replyJmsMessage = createJmsTextMessage();
|
||||
given(jmsTemplate.sendAndReceive(eq("myQueue"), any())).willReturn(replyJmsMessage);
|
||||
given(this.jmsTemplate.sendAndReceive(eq("myQueue"), any())).willReturn(replyJmsMessage);
|
||||
|
||||
Message<?> actual = messagingTemplate.sendAndReceive("myQueue", request);
|
||||
verify(jmsTemplate, times(1)).sendAndReceive(eq("myQueue"), any());
|
||||
Message<?> actual = this.messagingTemplate.sendAndReceive("myQueue", request);
|
||||
verify(this.jmsTemplate, times(1)).sendAndReceive(eq("myQueue"), any());
|
||||
assertTextMessage(actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendAndReceiveDefaultDestination() {
|
||||
Destination destination = new Destination() {};
|
||||
messagingTemplate.setDefaultDestination(destination);
|
||||
this.messagingTemplate.setDefaultDestination(destination);
|
||||
Message<String> request = createTextMessage();
|
||||
javax.jms.Message replyJmsMessage = createJmsTextMessage();
|
||||
given(jmsTemplate.sendAndReceive(eq(destination), any())).willReturn(replyJmsMessage);
|
||||
given(this.jmsTemplate.sendAndReceive(eq(destination), any())).willReturn(replyJmsMessage);
|
||||
|
||||
Message<?> actual = messagingTemplate.sendAndReceive(request);
|
||||
verify(jmsTemplate, times(1)).sendAndReceive(eq(destination), any());
|
||||
Message<?> actual = this.messagingTemplate.sendAndReceive(request);
|
||||
verify(this.jmsTemplate, times(1)).sendAndReceive(eq(destination), any());
|
||||
assertTextMessage(actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendAndReceiveDefaultDestinationName() {
|
||||
messagingTemplate.setDefaultDestinationName("myQueue");
|
||||
this.messagingTemplate.setDefaultDestinationName("myQueue");
|
||||
Message<String> request = createTextMessage();
|
||||
javax.jms.Message replyJmsMessage = createJmsTextMessage();
|
||||
given(jmsTemplate.sendAndReceive(eq("myQueue"), any())).willReturn(replyJmsMessage);
|
||||
given(this.jmsTemplate.sendAndReceive(eq("myQueue"), any())).willReturn(replyJmsMessage);
|
||||
|
||||
Message<?> actual = messagingTemplate.sendAndReceive(request);
|
||||
verify(jmsTemplate, times(1)).sendAndReceive(eq("myQueue"), any());
|
||||
Message<?> actual = this.messagingTemplate.sendAndReceive(request);
|
||||
verify(this.jmsTemplate, times(1)).sendAndReceive(eq("myQueue"), any());
|
||||
assertTextMessage(actual);
|
||||
}
|
||||
|
||||
|
|
@ -400,58 +402,58 @@ public class JmsMessagingTemplateTests {
|
|||
public void sendAndReceiveNoDefaultSet() {
|
||||
Message<String> message = createTextMessage();
|
||||
|
||||
thrown.expect(IllegalStateException.class);
|
||||
messagingTemplate.sendAndReceive(message);
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.messagingTemplate.sendAndReceive(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertSendAndReceivePayload() throws JMSException {
|
||||
Destination destination = new Destination() {};
|
||||
javax.jms.Message replyJmsMessage = createJmsTextMessage("My reply");
|
||||
given(jmsTemplate.sendAndReceive(eq(destination), any())).willReturn(replyJmsMessage);
|
||||
given(this.jmsTemplate.sendAndReceive(eq(destination), any())).willReturn(replyJmsMessage);
|
||||
|
||||
String reply = messagingTemplate.convertSendAndReceive(destination, "my Payload", String.class);
|
||||
verify(jmsTemplate, times(1)).sendAndReceive(eq(destination), any());
|
||||
String reply = this.messagingTemplate.convertSendAndReceive(destination, "my Payload", String.class);
|
||||
verify(this.jmsTemplate, times(1)).sendAndReceive(eq(destination), any());
|
||||
assertEquals("My reply", reply);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertSendAndReceivePayloadName() throws JMSException {
|
||||
javax.jms.Message replyJmsMessage = createJmsTextMessage("My reply");
|
||||
given(jmsTemplate.sendAndReceive(eq("myQueue"), any())).willReturn(replyJmsMessage);
|
||||
given(this.jmsTemplate.sendAndReceive(eq("myQueue"), any())).willReturn(replyJmsMessage);
|
||||
|
||||
String reply = messagingTemplate.convertSendAndReceive("myQueue", "my Payload", String.class);
|
||||
verify(jmsTemplate, times(1)).sendAndReceive(eq("myQueue"), any());
|
||||
String reply = this.messagingTemplate.convertSendAndReceive("myQueue", "my Payload", String.class);
|
||||
verify(this.jmsTemplate, times(1)).sendAndReceive(eq("myQueue"), any());
|
||||
assertEquals("My reply", reply);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertSendAndReceiveDefaultDestination() throws JMSException {
|
||||
Destination destination = new Destination() {};
|
||||
messagingTemplate.setDefaultDestination(destination);
|
||||
this.messagingTemplate.setDefaultDestination(destination);
|
||||
javax.jms.Message replyJmsMessage = createJmsTextMessage("My reply");
|
||||
given(jmsTemplate.sendAndReceive(eq(destination), any())).willReturn(replyJmsMessage);
|
||||
given(this.jmsTemplate.sendAndReceive(eq(destination), any())).willReturn(replyJmsMessage);
|
||||
|
||||
String reply = messagingTemplate.convertSendAndReceive("my Payload", String.class);
|
||||
verify(jmsTemplate, times(1)).sendAndReceive(eq(destination), any());
|
||||
String reply = this.messagingTemplate.convertSendAndReceive("my Payload", String.class);
|
||||
verify(this.jmsTemplate, times(1)).sendAndReceive(eq(destination), any());
|
||||
assertEquals("My reply", reply);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertSendAndReceiveDefaultDestinationName() throws JMSException {
|
||||
messagingTemplate.setDefaultDestinationName("myQueue");
|
||||
this.messagingTemplate.setDefaultDestinationName("myQueue");
|
||||
javax.jms.Message replyJmsMessage = createJmsTextMessage("My reply");
|
||||
given(jmsTemplate.sendAndReceive(eq("myQueue"), any())).willReturn(replyJmsMessage);
|
||||
given(this.jmsTemplate.sendAndReceive(eq("myQueue"), any())).willReturn(replyJmsMessage);
|
||||
|
||||
String reply = messagingTemplate.convertSendAndReceive("my Payload", String.class);
|
||||
verify(jmsTemplate, times(1)).sendAndReceive(eq("myQueue"), any());
|
||||
String reply = this.messagingTemplate.convertSendAndReceive("my Payload", String.class);
|
||||
verify(this.jmsTemplate, times(1)).sendAndReceive(eq("myQueue"), any());
|
||||
assertEquals("My reply", reply);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertSendAndReceiveNoDefaultSet() throws JMSException {
|
||||
thrown.expect(IllegalStateException.class);
|
||||
messagingTemplate.convertSendAndReceive("my Payload", String.class);
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.messagingTemplate.convertSendAndReceive("my Payload", String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -460,11 +462,11 @@ public class JmsMessagingTemplateTests {
|
|||
MessageConverter messageConverter = mock(MessageConverter.class);
|
||||
willThrow(org.springframework.jms.support.converter.MessageConversionException.class)
|
||||
.given(messageConverter).toMessage(eq(message), any());
|
||||
messagingTemplate.setJmsMessageConverter(messageConverter);
|
||||
invokeMessageCreator("myQueue");
|
||||
this.messagingTemplate.setJmsMessageConverter(messageConverter);
|
||||
invokeMessageCreator();
|
||||
|
||||
thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
messagingTemplate.send("myQueue", message);
|
||||
this.thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
this.messagingTemplate.send("myQueue", message);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -473,37 +475,37 @@ public class JmsMessagingTemplateTests {
|
|||
MessageConverter messageConverter = mock(MessageConverter.class);
|
||||
willThrow(org.springframework.jms.support.converter.MessageConversionException.class)
|
||||
.given(messageConverter).fromMessage(message);
|
||||
messagingTemplate.setJmsMessageConverter(messageConverter);
|
||||
given(jmsTemplate.receive("myQueue")).willReturn(message);
|
||||
this.messagingTemplate.setJmsMessageConverter(messageConverter);
|
||||
given(this.jmsTemplate.receive("myQueue")).willReturn(message);
|
||||
|
||||
thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
messagingTemplate.receive("myQueue");
|
||||
this.thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
this.messagingTemplate.receive("myQueue");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertMessageNotReadableException() throws JMSException {
|
||||
willThrow(MessageNotReadableException.class).given(jmsTemplate).receive("myQueue");
|
||||
willThrow(MessageNotReadableException.class).given(this.jmsTemplate).receive("myQueue");
|
||||
|
||||
thrown.expect(MessagingException.class);
|
||||
messagingTemplate.receive("myQueue");
|
||||
this.thrown.expect(MessagingException.class);
|
||||
this.messagingTemplate.receive("myQueue");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertDestinationResolutionExceptionOnSend() {
|
||||
Destination destination = new Destination() {};
|
||||
willThrow(DestinationResolutionException.class).given(jmsTemplate).send(eq(destination), any());
|
||||
willThrow(DestinationResolutionException.class).given(this.jmsTemplate).send(eq(destination), any());
|
||||
|
||||
thrown.expect(org.springframework.messaging.core.DestinationResolutionException.class);
|
||||
messagingTemplate.send(destination, createTextMessage());
|
||||
this.thrown.expect(org.springframework.messaging.core.DestinationResolutionException.class);
|
||||
this.messagingTemplate.send(destination, createTextMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertDestinationResolutionExceptionOnReceive() {
|
||||
Destination destination = new Destination() {};
|
||||
willThrow(DestinationResolutionException.class).given(jmsTemplate).receive(destination);
|
||||
willThrow(DestinationResolutionException.class).given(this.jmsTemplate).receive(destination);
|
||||
|
||||
thrown.expect(org.springframework.messaging.core.DestinationResolutionException.class);
|
||||
messagingTemplate.receive(destination);
|
||||
this.thrown.expect(org.springframework.messaging.core.DestinationResolutionException.class);
|
||||
this.messagingTemplate.receive(destination);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -511,11 +513,11 @@ public class JmsMessagingTemplateTests {
|
|||
Message<String> message = createTextMessage();
|
||||
MessageConverter messageConverter = mock(MessageConverter.class);
|
||||
willThrow(MessageFormatException.class).given(messageConverter).toMessage(eq(message), any());
|
||||
messagingTemplate.setJmsMessageConverter(messageConverter);
|
||||
invokeMessageCreator("myQueue");
|
||||
this.messagingTemplate.setJmsMessageConverter(messageConverter);
|
||||
invokeMessageCreator();
|
||||
|
||||
thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
messagingTemplate.send("myQueue", message);
|
||||
this.thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
this.messagingTemplate.send("myQueue", message);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -523,39 +525,36 @@ public class JmsMessagingTemplateTests {
|
|||
Message<String> message = createTextMessage();
|
||||
MessageConverter messageConverter = mock(MessageConverter.class);
|
||||
willThrow(MessageNotWriteableException.class).given(messageConverter).toMessage(eq(message), any());
|
||||
messagingTemplate.setJmsMessageConverter(messageConverter);
|
||||
invokeMessageCreator("myQueue");
|
||||
this.messagingTemplate.setJmsMessageConverter(messageConverter);
|
||||
invokeMessageCreator();
|
||||
|
||||
thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
messagingTemplate.send("myQueue", message);
|
||||
this.thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
this.messagingTemplate.send("myQueue", message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertInvalidDestinationExceptionOnSendAndReceiveWithName() {
|
||||
willThrow(InvalidDestinationException.class).given(jmsTemplate).sendAndReceive(eq("unknownQueue"), any());
|
||||
willThrow(InvalidDestinationException.class).given(this.jmsTemplate).sendAndReceive(eq("unknownQueue"), any());
|
||||
|
||||
thrown.expect(org.springframework.messaging.core.DestinationResolutionException.class);
|
||||
messagingTemplate.sendAndReceive("unknownQueue", createTextMessage());
|
||||
this.thrown.expect(org.springframework.messaging.core.DestinationResolutionException.class);
|
||||
this.messagingTemplate.sendAndReceive("unknownQueue", createTextMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertInvalidDestinationExceptionOnSendAndReceive() {
|
||||
Destination destination = new Destination() {};
|
||||
willThrow(InvalidDestinationException.class).given(jmsTemplate).sendAndReceive(eq(destination), any());
|
||||
willThrow(InvalidDestinationException.class).given(this.jmsTemplate).sendAndReceive(eq(destination), any());
|
||||
|
||||
thrown.expect(org.springframework.messaging.core.DestinationResolutionException.class);
|
||||
messagingTemplate.sendAndReceive(destination, createTextMessage());
|
||||
this.thrown.expect(org.springframework.messaging.core.DestinationResolutionException.class);
|
||||
this.messagingTemplate.sendAndReceive(destination, createTextMessage());
|
||||
}
|
||||
|
||||
private void invokeMessageCreator(String destinationName) {
|
||||
willAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
MessageCreator messageCreator = (MessageCreator) invocation.getArguments()[1];
|
||||
messageCreator.createMessage(null);
|
||||
return null;
|
||||
}
|
||||
}).given(jmsTemplate).send(eq("myQueue"), any());
|
||||
private void invokeMessageCreator() {
|
||||
willAnswer(invocation -> {
|
||||
MessageCreator messageCreator = (MessageCreator) invocation.getArguments()[1];
|
||||
messageCreator.createMessage(null);
|
||||
return null;
|
||||
}).given(this.jmsTemplate).send(eq("myQueue"), any());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -604,15 +603,11 @@ public class JmsMessagingTemplateTests {
|
|||
|
||||
protected TextMessage createTextMessage(MessageCreator creator) throws JMSException {
|
||||
Session mock = mock(Session.class);
|
||||
given(mock.createTextMessage(BDDMockito.<String> any())).willAnswer(
|
||||
new Answer<TextMessage>() {
|
||||
@Override
|
||||
public TextMessage answer(InvocationOnMock invocation) throws Throwable {
|
||||
return new StubTextMessage((String) invocation.getArguments()[0]);
|
||||
}
|
||||
});
|
||||
given(mock.createTextMessage(BDDMockito.any())).willAnswer(
|
||||
(Answer<TextMessage>) invocation ->
|
||||
new StubTextMessage((String) invocation.getArguments()[0]));
|
||||
javax.jms.Message message = creator.createMessage(mock);
|
||||
verify(mock).createTextMessage(BDDMockito.<String> any());
|
||||
verify(mock).createTextMessage(BDDMockito.any());
|
||||
return TextMessage.class.cast(message);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue