use of org.springframework.jms.support.converter.SimpleMessageConverter in project spring-framework by spring-projects.
the class SimpleMessageConverterTests method testSerializableConversion.
@Test
public void testSerializableConversion() throws JMSException {
Session session = mock(Session.class);
ObjectMessage message = mock(ObjectMessage.class);
Integer content = new Integer(5);
given(session.createObjectMessage(content)).willReturn(message);
given(message.getObject()).willReturn(content);
SimpleMessageConverter converter = new SimpleMessageConverter();
Message msg = converter.toMessage(content, session);
assertEquals(content, converter.fromMessage(msg));
}
use of org.springframework.jms.support.converter.SimpleMessageConverter in project spring-framework by spring-projects.
the class SimpleMessageConverterTests method testMapConversion.
@Test
public void testMapConversion() throws JMSException {
Session session = mock(Session.class);
MapMessage message = mock(MapMessage.class);
Map<String, String> content = new HashMap<>(2);
content.put("key1", "value1");
content.put("key2", "value2");
given(session.createMapMessage()).willReturn(message);
given(message.getMapNames()).willReturn(Collections.enumeration(content.keySet()));
given(message.getObject("key1")).willReturn("value1");
given(message.getObject("key2")).willReturn("value2");
SimpleMessageConverter converter = new SimpleMessageConverter();
Message msg = converter.toMessage(content, session);
assertEquals(content, converter.fromMessage(msg));
verify(message).setObject("key1", "value1");
verify(message).setObject("key2", "value2");
}
use of org.springframework.jms.support.converter.SimpleMessageConverter in project spring-framework by spring-projects.
the class SimpleMessageConverterTests method testToMessageSimplyReturnsMessageAsIsIfSuppliedWithMessage.
@Test
public void testToMessageSimplyReturnsMessageAsIsIfSuppliedWithMessage() throws JMSException {
Session session = mock(Session.class);
ObjectMessage message = mock(ObjectMessage.class);
SimpleMessageConverter converter = new SimpleMessageConverter();
Message msg = converter.toMessage(message, session);
assertSame(message, msg);
}
use of org.springframework.jms.support.converter.SimpleMessageConverter in project spring-framework by spring-projects.
the class SimpleMessageConverterTests method testFromMessageSimplyReturnsMessageAsIsIfSuppliedWithMessage.
@Test
public void testFromMessageSimplyReturnsMessageAsIsIfSuppliedWithMessage() throws JMSException {
Message message = mock(Message.class);
SimpleMessageConverter converter = new SimpleMessageConverter();
Object msg = converter.fromMessage(message);
assertSame(message, msg);
}
use of org.springframework.jms.support.converter.SimpleMessageConverter in project spring-framework by spring-projects.
the class JmsTemplateTests method testConverter.
@Test
public void testConverter() throws Exception {
JmsTemplate template = createTemplate();
template.setConnectionFactory(connectionFactory);
template.setMessageConverter(new SimpleMessageConverter());
String s = "Hello world";
MessageProducer messageProducer = mock(MessageProducer.class);
TextMessage textMessage = mock(TextMessage.class);
given(session.createProducer(queue)).willReturn(messageProducer);
given(session.createTextMessage("Hello world")).willReturn(textMessage);
template.convertAndSend(queue, s);
verify(messageProducer).send(textMessage);
verify(messageProducer).close();
if (useTransactedTemplate()) {
verify(session).commit();
}
verify(session).close();
verify(connection).close();
}
Aggregations