JmsMessagingTemplate uses local convertJmsException template method instead of generic MessagingExceptionTranslator interface
This commit also turns MessagingException into a NestedRuntimeException subclass which delivers a root message that has the cause message appended to it. That's a common expectation with the use of Spring exceptions since all of our exception hierarchies have historically been designed that way. Issue: SPR-12064 Issue: SPR-12038
This commit is contained in:
@@ -26,6 +26,7 @@ import javax.jms.MessageNotWriteableException;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.hamcrest.core.StringContains;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -47,14 +48,12 @@ import org.springframework.jms.support.destination.DestinationResolutionExceptio
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.converter.GenericMessageConverter;
|
||||
import org.springframework.messaging.converter.MessageConversionException;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class JmsMessagingTemplateTests {
|
||||
@@ -193,16 +192,16 @@ public class JmsMessagingTemplateTests {
|
||||
messagingTemplate.setJmsMessageConverter(new SimpleMessageConverter() {
|
||||
@Override
|
||||
public javax.jms.Message toMessage(Object object, Session session)
|
||||
throws JMSException, MessageConversionException {
|
||||
throw new MessageConversionException("Test exception");
|
||||
throws JMSException, org.springframework.jms.support.converter.MessageConversionException {
|
||||
throw new org.springframework.jms.support.converter.MessageConversionException("Test exception");
|
||||
}
|
||||
});
|
||||
|
||||
messagingTemplate.convertAndSend("myQueue", "msg to convert");
|
||||
verify(jmsTemplate).send(eq("myQueue"), messageCreator.capture());
|
||||
|
||||
thrown.expect(MessageConversionException.class);
|
||||
thrown.expectMessage("Test exception");
|
||||
thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
thrown.expectMessage(new StringContains("Test exception"));
|
||||
messageCreator.getValue().createMessage(mock(Session.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.jms.support;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class JmsMessagingExceptionTranslatorTests {
|
||||
|
||||
private final JmsMessagingExceptionTranslator translator = new JmsMessagingExceptionTranslator();
|
||||
|
||||
@Test
|
||||
public void translateNonJmsException() {
|
||||
assertNull(translator.translateExceptionIfPossible(new NullPointerException()));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user