ApplicationContextMessageBus now implements the ChannelResolver interface. The MessagePublishingErrorHandler for the SimpleTaskScheduler is now created in the MessageBusParser rather than in the initialization code of the MessageBus.

This commit is contained in:
Mark Fisher
2008-10-20 13:50:22 +00:00
parent 7124894646
commit f8b2724f7a
4 changed files with 28 additions and 25 deletions

View File

@@ -30,6 +30,10 @@ import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.integration.channel.BeanFactoryChannelResolver;
import org.springframework.integration.channel.ChannelResolutionException;
import org.springframework.integration.channel.ChannelResolver;
import org.springframework.integration.channel.MessagePublishingErrorHandler;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.channel.PublishSubscribeChannel;
import org.springframework.integration.channel.QueueChannel;
@@ -47,6 +51,7 @@ import org.springframework.integration.message.MessageBuilder;
import org.springframework.integration.message.MessageSource;
import org.springframework.integration.message.StringMessage;
import org.springframework.integration.scheduling.IntervalTrigger;
import org.springframework.integration.scheduling.SimpleTaskScheduler;
import org.springframework.integration.util.TestUtils;
/**
@@ -222,7 +227,12 @@ public class ApplicationContextMessageBusTests {
channelAdapter.setBeanName("testChannel");
context.getBeanFactory().registerSingleton("testChannel", channelAdapter);
ApplicationContextMessageBus bus = new ApplicationContextMessageBus();
bus.setTaskScheduler(TestUtils.createTaskScheduler(10));
SimpleTaskScheduler taskScheduler = (SimpleTaskScheduler) TestUtils.createTaskScheduler(10);
ChannelResolver channelResolver = new BeanFactoryChannelResolver(context);
MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler(channelResolver);
errorHandler.setDefaultErrorChannel(errorChannel);
taskScheduler.setErrorHandler(errorHandler);
bus.setTaskScheduler(taskScheduler);
bus.setApplicationContext(context);
context.refresh();
bus.start();
@@ -274,18 +284,17 @@ public class ApplicationContextMessageBusTests {
context.getBeanFactory().registerSingleton("testChannel", testChannel);
ApplicationContextMessageBus messageBus = new ApplicationContextMessageBus();
messageBus.setApplicationContext(context);
MessageChannel lookedUpChannel = messageBus.lookupChannel("testChannel");
MessageChannel lookedUpChannel = messageBus.resolveChannelName("testChannel");
assertNotNull(testChannel);
assertSame(testChannel, lookedUpChannel);
}
@Test
@Test(expected = ChannelResolutionException.class)
public void lookupNonRegisteredChannel() {
GenericApplicationContext context = new GenericApplicationContext();
ApplicationContextMessageBus messageBus = new ApplicationContextMessageBus();
messageBus.setApplicationContext(context);
MessageChannel noSuchChannel = messageBus.lookupChannel("noSuchChannel");
assertNull(noSuchChannel);
messageBus.resolveChannelName("noSuchChannel");
}
@Test

View File

@@ -51,7 +51,7 @@ public class MessageBusParserTests {
ApplicationContext context = new ClassPathXmlApplicationContext(
"messageBusWithErrorChannel.xml", this.getClass());
ApplicationContextMessageBus bus = (ApplicationContextMessageBus) context.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME);
MessageChannel channel = bus.lookupChannel(ApplicationContextMessageBus.ERROR_CHANNEL_BEAN_NAME);
MessageChannel channel = bus.resolveChannelName(ApplicationContextMessageBus.ERROR_CHANNEL_BEAN_NAME);
assertEquals(context.getBean("errorChannel"), channel);
}
@@ -61,7 +61,7 @@ public class MessageBusParserTests {
"messageBusWithDefaults.xml", this.getClass());
ApplicationContextMessageBus bus = (ApplicationContextMessageBus) context.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME);
assertNotNull("parser should have created a default error channel",
bus.lookupChannel(ApplicationContextMessageBus.ERROR_CHANNEL_BEAN_NAME));
bus.resolveChannelName(ApplicationContextMessageBus.ERROR_CHANNEL_BEAN_NAME));
}
@Test