Removed the 'registerChannel' method from DefaultMessageBus; all channels must be registered within the ApplicationContext. The MessageBusParser now creates the 'errorChannel' if no bean with that name is explicitly defined rather than creating it within the DefaultMessageBus initialization.
This commit is contained in:
@@ -239,15 +239,6 @@ public class DefaultMessageBusTests {
|
||||
new ClassPathXmlApplicationContext("multipleMessageBusBeans.xml", this.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void errorChannelRegistration() {
|
||||
DefaultMessageBus bus = new DefaultMessageBus();
|
||||
QueueChannel errorChannel = new QueueChannel();
|
||||
errorChannel.setBeanName(ChannelRegistry.ERROR_CHANNEL_NAME);
|
||||
bus.registerChannel(errorChannel);
|
||||
assertEquals(errorChannel, bus.getErrorChannel());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void consumerSubscribedToErrorChannel() throws InterruptedException {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
@@ -275,10 +266,12 @@ public class DefaultMessageBusTests {
|
||||
|
||||
@Test
|
||||
public void lookupRegisteredChannel() {
|
||||
DefaultMessageBus messageBus = new DefaultMessageBus();
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
QueueChannel testChannel = new QueueChannel();
|
||||
testChannel.setBeanName("testChannel");
|
||||
messageBus.registerChannel(testChannel);
|
||||
context.getBeanFactory().registerSingleton("testChannel", testChannel);
|
||||
DefaultMessageBus messageBus = new DefaultMessageBus();
|
||||
messageBus.setApplicationContext(context);
|
||||
MessageChannel lookedUpChannel = messageBus.lookupChannel("testChannel");
|
||||
assertNotNull(testChannel);
|
||||
assertSame(testChannel, lookedUpChannel);
|
||||
@@ -286,7 +279,9 @@ public class DefaultMessageBusTests {
|
||||
|
||||
@Test
|
||||
public void lookupNonRegisteredChannel() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
DefaultMessageBus messageBus = new DefaultMessageBus();
|
||||
messageBus.setApplicationContext(context);
|
||||
MessageChannel noSuchChannel = messageBus.lookupChannel("noSuchChannel");
|
||||
assertNull(noSuchChannel);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ import org.springframework.integration.util.TestUtils;
|
||||
*/
|
||||
public class DirectChannelSubscriptionTests {
|
||||
|
||||
private GenericApplicationContext context = new GenericApplicationContext();
|
||||
|
||||
private DefaultMessageBus bus = new DefaultMessageBus();
|
||||
|
||||
private DirectChannel sourceChannel = new DirectChannel();
|
||||
@@ -54,14 +56,16 @@ public class DirectChannelSubscriptionTests {
|
||||
public void setupChannels() {
|
||||
sourceChannel.setBeanName("sourceChannel");
|
||||
targetChannel.setBeanName("targetChannel");
|
||||
bus.registerChannel(sourceChannel);
|
||||
bus.registerChannel(targetChannel);
|
||||
context.getBeanFactory().registerSingleton("sourceChannel", sourceChannel);
|
||||
context.getBeanFactory().registerSingleton("targetChannel", targetChannel);
|
||||
context.getBeanFactory().registerSingleton(MessageBusParser.MESSAGE_BUS_BEAN_NAME, bus);
|
||||
bus.setApplicationContext(context);
|
||||
bus.setTaskScheduler(TestUtils.createTaskScheduler(10));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSendAndReceiveForRegisteredEndpoint() {
|
||||
public void sendAndReceiveForRegisteredEndpoint() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ServiceActivatorEndpoint serviceActivator = new ServiceActivatorEndpoint(new TestBean(), "handle");
|
||||
serviceActivator.setOutputChannel(targetChannel);
|
||||
@@ -76,10 +80,7 @@ public class DirectChannelSubscriptionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendAndReceiveForAnnotatedEndpoint() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
bus.setApplicationContext(context);
|
||||
context.getBeanFactory().registerSingleton(MessageBusParser.MESSAGE_BUS_BEAN_NAME, bus);
|
||||
public void sendAndReceiveForAnnotatedEndpoint() {
|
||||
MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor();
|
||||
postProcessor.setBeanFactory(context.getBeanFactory());
|
||||
postProcessor.afterPropertiesSet();
|
||||
@@ -92,11 +93,8 @@ public class DirectChannelSubscriptionTests {
|
||||
bus.stop();
|
||||
}
|
||||
|
||||
@Test(expected=RuntimeException.class)
|
||||
public void testExceptionThrownFromRegisteredEndpoint() {
|
||||
QueueChannel errorChannel = new QueueChannel();
|
||||
errorChannel.setBeanName(ChannelRegistry.ERROR_CHANNEL_NAME);
|
||||
bus.registerChannel(errorChannel);
|
||||
@Test(expected = MessagingException.class)
|
||||
public void exceptionThrownFromRegisteredEndpoint() {
|
||||
AbstractReplyProducingMessageConsumer consumer = new AbstractReplyProducingMessageConsumer() {
|
||||
public Message<?> handle(Message<?> message) {
|
||||
throw new RuntimeException("intentional test failure");
|
||||
@@ -109,11 +107,8 @@ public class DirectChannelSubscriptionTests {
|
||||
this.sourceChannel.send(new StringMessage("foo"));
|
||||
}
|
||||
|
||||
@Test(expected=MessagingException.class)
|
||||
public void testExceptionThrownFromAnnotatedEndpoint() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
bus.setApplicationContext(context);
|
||||
context.getBeanFactory().registerSingleton(MessageBusParser.MESSAGE_BUS_BEAN_NAME, bus);
|
||||
@Test(expected = MessagingException.class)
|
||||
public void exceptionThrownFromAnnotatedEndpoint() {
|
||||
QueueChannel errorChannel = new QueueChannel();
|
||||
errorChannel.setBeanName(ChannelRegistry.ERROR_CHANNEL_NAME);
|
||||
context.getBeanFactory().registerSingleton(ChannelRegistry.ERROR_CHANNEL_NAME, errorChannel);
|
||||
|
||||
@@ -61,7 +61,7 @@ public class MessageBusParserTests {
|
||||
"messageBusWithDefaults.xml", this.getClass());
|
||||
DefaultMessageBus bus = (DefaultMessageBus) context.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME);
|
||||
bus.initialize();
|
||||
assertNotNull("bus should have created a default error channel", bus.getErrorChannel());
|
||||
assertNotNull("parser should have created a default error channel", bus.getErrorChannel());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -62,13 +62,13 @@ public class MessagingAnnotationPostProcessorTests {
|
||||
@Test
|
||||
public void testServiceActivatorAnnotation() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
QueueChannel inputChannel = new QueueChannel();
|
||||
inputChannel.setBeanName("inputChannel");
|
||||
context.getBeanFactory().registerSingleton("inputChannel", inputChannel);
|
||||
DefaultMessageBus messageBus = new DefaultMessageBus();
|
||||
context.getBeanFactory().registerSingleton(
|
||||
MessageBusParser.MESSAGE_BUS_BEAN_NAME, messageBus);
|
||||
messageBus.setApplicationContext(context);
|
||||
QueueChannel inputChannel = new QueueChannel();
|
||||
inputChannel.setBeanName("inputChannel");
|
||||
messageBus.registerChannel(inputChannel);
|
||||
MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor();
|
||||
postProcessor.setBeanFactory(context.getBeanFactory());
|
||||
postProcessor.afterPropertiesSet();
|
||||
@@ -181,13 +181,13 @@ public class MessagingAnnotationPostProcessorTests {
|
||||
@Test
|
||||
public void testChannelRegistryAwareBean() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
QueueChannel inputChannel = new QueueChannel();
|
||||
inputChannel.setBeanName("inputChannel");
|
||||
context.getBeanFactory().registerSingleton("inputChannel", inputChannel);
|
||||
DefaultMessageBus messageBus = new DefaultMessageBus();
|
||||
context.getBeanFactory().registerSingleton(
|
||||
MessageBusParser.MESSAGE_BUS_BEAN_NAME, messageBus);
|
||||
messageBus.setApplicationContext(context);
|
||||
QueueChannel inputChannel = new QueueChannel();
|
||||
inputChannel.setBeanName("inputChannel");
|
||||
messageBus.registerChannel(inputChannel);
|
||||
MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor();
|
||||
postProcessor.setBeanFactory(context.getBeanFactory());
|
||||
postProcessor.afterPropertiesSet();
|
||||
|
||||
Reference in New Issue
Block a user