|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
40 | 40 | import org.springframework.jms.support.converter.MappingJackson2MessageConverter;
|
41 | 41 | import org.springframework.jms.support.converter.MessageConverter;
|
42 | 42 | import org.springframework.jms.support.converter.MessageType;
|
| 43 | +import org.springframework.jms.support.converter.MessagingMessageConverter; |
43 | 44 | import org.springframework.messaging.Message;
|
44 | 45 | import org.springframework.messaging.converter.MessageConversionException;
|
45 | 46 | import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
|
@@ -340,6 +341,45 @@ public TextMessage testReplyWithJackson(String methodName, String replyContent)
|
340 | 341 | return responseMessage;
|
341 | 342 | }
|
342 | 343 |
|
| 344 | + @Test |
| 345 | + void lazyResolutionMessageToStringProvidesBestEffortWithUnresolvedPayload() throws JMSException { |
| 346 | + MessagingMessageListenerAdapter adapter = getSimpleInstance("echo", Message.class); |
| 347 | + MessagingMessageConverter messagingMessageConverter = adapter.getMessagingMessageConverter(); |
| 348 | + assertThat(messagingMessageConverter).isNotNull(); |
| 349 | + TextMessage message = new StubTextMessage(); |
| 350 | + assertThat(messagingMessageConverter.fromMessage(message)).isInstanceOfSatisfying(Message.class, msg -> |
| 351 | + assertThat(msg.toString()).contains("rawMessage=").contains(message.toString()) |
| 352 | + .doesNotContain("payload=").doesNotContain("headers=")); |
| 353 | + } |
| 354 | + |
| 355 | + @Test |
| 356 | + void lazyResolutionMessageToStringWithResolvedPayload() throws JMSException { |
| 357 | + MessagingMessageListenerAdapter adapter = getSimpleInstance("echo", Message.class); |
| 358 | + MessagingMessageConverter messagingMessageConverter = adapter.getMessagingMessageConverter(); |
| 359 | + assertThat(messagingMessageConverter).isNotNull(); |
| 360 | + TextMessage message = new StubTextMessage("Hello"); |
| 361 | + assertThat(messagingMessageConverter.fromMessage(message)).isInstanceOfSatisfying(Message.class, msg -> { |
| 362 | + msg.getPayload(); // force resolution |
| 363 | + assertThat(msg.toString()).contains("payload=Hello") |
| 364 | + .doesNotContain("rawMessage=").doesNotContain("headers="); |
| 365 | + }); |
| 366 | + } |
| 367 | + |
| 368 | + @Test |
| 369 | + void lazyResolutionMessageToStringWithResolvedPayloadAndHeaders() throws JMSException { |
| 370 | + MessagingMessageListenerAdapter adapter = getSimpleInstance("echo", Message.class); |
| 371 | + MessagingMessageConverter messagingMessageConverter = adapter.getMessagingMessageConverter(); |
| 372 | + assertThat(messagingMessageConverter).isNotNull(); |
| 373 | + TextMessage message = new StubTextMessage("Hello"); |
| 374 | + message.setJMSPriority(7); |
| 375 | + assertThat(messagingMessageConverter.fromMessage(message)).isInstanceOfSatisfying(Message.class, msg -> { |
| 376 | + msg.getPayload(); |
| 377 | + msg.getHeaders(); // force resolution |
| 378 | + assertThat(msg.toString()).contains("payload=Hello").contains("headers=").contains("jms_priority=7") |
| 379 | + .doesNotContain("rawMessage="); |
| 380 | + }); |
| 381 | + } |
| 382 | + |
343 | 383 |
|
344 | 384 | protected MessagingMessageListenerAdapter getSimpleInstance(String methodName, Class<?>... parameterTypes) {
|
345 | 385 | Method m = ReflectionUtils.findMethod(SampleBean.class, methodName, parameterTypes);
|
|
0 commit comments