use of org.springframework.jms.support.converter.SimpleMessageConverter in project spring-framework by spring-projects.
the class SimpleMessageConverterTests method testStringConversion.
@Test
public void testStringConversion() throws JMSException {
Session session = mock(Session.class);
TextMessage message = mock(TextMessage.class);
String content = "test";
given(session.createTextMessage(content)).willReturn(message);
given(message.getText()).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 testByteArrayConversion.
@Test
public void testByteArrayConversion() throws JMSException {
Session session = mock(Session.class);
BytesMessage message = mock(BytesMessage.class);
byte[] content = "test".getBytes();
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(content);
given(session.createBytesMessage()).willReturn(message);
given(message.getBodyLength()).willReturn((long) content.length);
given(message.readBytes(any(byte[].class))).willAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
return byteArrayInputStream.read((byte[]) invocation.getArguments()[0]);
}
});
SimpleMessageConverter converter = new SimpleMessageConverter();
Message msg = converter.toMessage(content, session);
assertEquals(content.length, ((byte[]) converter.fromMessage(msg)).length);
verify(message).writeBytes(content);
}
use of org.springframework.jms.support.converter.SimpleMessageConverter in project spring-framework by spring-projects.
the class SimpleMessageConverterTests method testMapConversionWhereMapHasNonStringTypesForKeys.
@Test
public void testMapConversionWhereMapHasNonStringTypesForKeys() throws JMSException {
MapMessage message = mock(MapMessage.class);
Session session = mock(Session.class);
given(session.createMapMessage()).willReturn(message);
Map<Integer, String> content = new HashMap<>(1);
content.put(1, "value1");
SimpleMessageConverter converter = new SimpleMessageConverter();
try {
converter.toMessage(content, session);
fail("expected MessageConversionException");
} catch (MessageConversionException ex) {
/* expected */
}
}
use of org.springframework.jms.support.converter.SimpleMessageConverter in project camel by apache.
the class JmsEndpointConfigurationTest method testSettingEndpointOptions.
@SuppressWarnings("deprecation")
@Test
public void testSettingEndpointOptions() throws Exception {
JmsEndpoint endpoint = resolveMandatoryEndpoint("jms:queue:Foo", JmsEndpoint.class);
endpoint.setAcceptMessagesWhileStopping(true);
assertTrue(endpoint.isAcceptMessagesWhileStopping());
endpoint.setAllowReplyManagerQuickStop(true);
assertTrue(endpoint.isAllowReplyManagerQuickStop());
endpoint.setAcknowledgementMode(2);
assertEquals(2, endpoint.getAcknowledgementMode());
endpoint.setAcknowledgementModeName("CLIENT_ACKNOWLEDGE");
assertEquals("CLIENT_ACKNOWLEDGE", endpoint.getAcknowledgementModeName());
endpoint.setAlwaysCopyMessage(true);
assertTrue(endpoint.isAlwaysCopyMessage());
endpoint.setCacheLevel(2);
assertEquals(2, endpoint.getCacheLevel());
endpoint.setCacheLevelName("foo");
assertEquals("foo", endpoint.getCacheLevelName());
endpoint.setClientId("bar");
assertEquals("bar", endpoint.getClientId());
endpoint.setConcurrentConsumers(5);
assertEquals(5, endpoint.getConcurrentConsumers());
endpoint.setDeliveryPersistent(true);
assertTrue(endpoint.isDeliveryPersistent());
endpoint.setDestinationName("cool");
assertEquals("cool", endpoint.getDestinationName());
endpoint.setDisableReplyTo(true);
assertTrue(endpoint.isDisableReplyTo());
endpoint.setEagerLoadingOfProperties(true);
assertTrue(endpoint.isEagerLoadingOfProperties());
endpoint.setExceptionListener(new ExceptionListener() {
public void onException(JMSException exception) {
}
});
assertNotNull(endpoint.getExceptionListener());
endpoint.setErrorHandler(new ErrorHandler() {
public void handleError(Throwable t) {
}
});
assertNotNull(endpoint.getErrorHandler());
endpoint.setExplicitQosEnabled(true);
assertTrue(endpoint.isExplicitQosEnabled());
endpoint.setExposeListenerSession(true);
assertTrue(endpoint.isExposeListenerSession());
endpoint.setIdleTaskExecutionLimit(5);
assertEquals(5, endpoint.getIdleTaskExecutionLimit());
endpoint.setIdleConsumerLimit(5);
assertEquals(5, endpoint.getIdleConsumerLimit());
endpoint.setMaxConcurrentConsumers(4);
assertEquals(4, endpoint.getMaxConcurrentConsumers());
endpoint.setMaxMessagesPerTask(9);
assertEquals(9, endpoint.getMaxMessagesPerTask());
endpoint.setMessageConverter(new SimpleMessageConverter());
assertNotNull(endpoint.getMessageConverter());
endpoint.setMessageIdEnabled(true);
assertTrue(endpoint.isMessageIdEnabled());
endpoint.setMessageTimestampEnabled(true);
assertTrue(endpoint.isMessageTimestampEnabled());
endpoint.setPreserveMessageQos(true);
assertTrue(endpoint.isPreserveMessageQos());
endpoint.setPriority(6);
assertEquals(6, endpoint.getPriority());
endpoint.setPubSubNoLocal(true);
assertTrue(endpoint.isPubSubNoLocal());
endpoint.setPubSubNoLocal(true);
assertTrue(endpoint.isPubSubNoLocal());
assertFalse(endpoint.isPubSubDomain());
endpoint.setReceiveTimeout(5000);
assertEquals(5000, endpoint.getReceiveTimeout());
endpoint.setRecoveryInterval(6000);
assertEquals(6000, endpoint.getRecoveryInterval());
endpoint.setReplyTo("bar");
assertEquals("bar", endpoint.getReplyTo());
endpoint.setReplyToDeliveryPersistent(true);
assertTrue(endpoint.isReplyToDeliveryPersistent());
endpoint.setReplyToDestinationSelectorName("me");
assertEquals("me", endpoint.getReplyToDestinationSelectorName());
endpoint.setRequestTimeout(3000);
assertEquals(3000, endpoint.getRequestTimeout());
endpoint.setSelector("you");
assertEquals("you", endpoint.getSelector());
endpoint.setTimeToLive(4000);
assertEquals(4000, endpoint.getTimeToLive());
endpoint.setTransacted(true);
assertTrue(endpoint.isTransacted());
endpoint.setTransactedInOut(true);
assertTrue(endpoint.isTransactedInOut());
endpoint.setTransferExchange(true);
assertTrue(endpoint.isTransferExchange());
endpoint.setTransferException(true);
assertTrue(endpoint.isTransferException());
endpoint.setJmsMessageType(JmsMessageType.Text);
assertEquals(JmsMessageType.Text, endpoint.getJmsMessageType());
}
use of org.springframework.jms.support.converter.SimpleMessageConverter in project spring-framework by spring-projects.
the class SimpleMessageConverterTests method testMapConversionWhereMapHasNNullForKey.
@Test
public void testMapConversionWhereMapHasNNullForKey() throws JMSException {
MapMessage message = mock(MapMessage.class);
Session session = mock(Session.class);
given(session.createMapMessage()).willReturn(message);
Map<Object, String> content = new HashMap<>(1);
content.put(null, "value1");
SimpleMessageConverter converter = new SimpleMessageConverter();
try {
converter.toMessage(content, session);
fail("expected MessageConversionException");
} catch (MessageConversionException ex) {
/* expected */
}
}
Aggregations