From 1f23bf8f0b82fe076776e3580fc1bdc2ed295b1f Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 8 Dec 2014 12:27:47 +0200 Subject: [PATCH] INT-3563: Add router's `id` to the MDException JIRA: https://jira.spring.io/browse/INT-3563 --- .../router/AbstractMessageRouter.java | 4 ++-- .../ErrorMessageExceptionTypeRouterTests.java | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageRouter.java b/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageRouter.java index 88775122db..5e6300abae 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageRouter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageRouter.java @@ -191,8 +191,8 @@ public abstract class AbstractMessageRouter extends AbstractMessageHandler { this.messagingTemplate.send(this.defaultOutputChannel, message); } else { - throw new MessageDeliveryException(message, - "no channel resolved by router and no default output channel defined"); + throw new MessageDeliveryException(message, "No channel resolved by router '" + this.getComponentName() + + "' and no 'defaultOutputChannel' defined."); } } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/ErrorMessageExceptionTypeRouterTests.java b/spring-integration-core/src/test/java/org/springframework/integration/router/ErrorMessageExceptionTypeRouterTests.java index 247d5085ea..59460c5a19 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/router/ErrorMessageExceptionTypeRouterTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/ErrorMessageExceptionTypeRouterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * 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. @@ -16,8 +16,12 @@ package org.springframework.integration.router; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; import java.util.HashMap; import java.util.Map; @@ -36,6 +40,7 @@ import org.springframework.messaging.support.ErrorMessage; /** * @author Mark Fisher * @author Oleg Zhurakousky + * @author Artem Bilan */ public class ErrorMessageExceptionTypeRouterTests { @@ -143,7 +148,7 @@ public class ErrorMessageExceptionTypeRouterTests { assertNull(messageHandlingExceptionChannel.receive(0)); } - @Test(expected = MessageDeliveryException.class) + @Test public void noMatchAndNoDefaultChannel() { Message failedMessage = new GenericMessage("foo"); IllegalArgumentException rootCause = new IllegalArgumentException("bad argument"); @@ -156,7 +161,15 @@ public class ErrorMessageExceptionTypeRouterTests { router.setChannelMappings(exceptionTypeChannelMap); router.setBeanFactory(beanFactory); router.setResolutionRequired(true); - router.handleMessage(message); + router.setBeanName("fooRouter"); + try { + router.handleMessage(message); + fail("MessageDeliveryException expected"); + } + catch (Exception e) { + assertThat(e, instanceOf(MessageDeliveryException.class)); + assertThat(e.getMessage(), containsString("'fooRouter'")); + } } @Test