Removed ChannelFactory strategy and implementations prior to general channel refactoring.

This commit is contained in:
Mark Fisher
2008-08-31 21:20:16 +00:00
parent 68035e091d
commit 4b8a32456e
18 changed files with 1 additions and 754 deletions

View File

@@ -1,40 +0,0 @@
/*
* Copyright 2002-2008 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.integration.channel.config;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.factory.StubChannel;
/**
* @author Marius Bogoevici
*/
public class DefaultChannelParserTests {
@Test
public void testDefaultChannel() {
ApplicationContext context = new ClassPathXmlApplicationContext("defaultChannelParserTests.xml", this.getClass());
MessageChannel channel = (MessageChannel) context.getBean("defaultChannel");
assertEquals(StubChannel.class, channel.getClass());
}
}

View File

@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
<beans:bean id="channelFactory" class="org.springframework.integration.channel.factory.StubChannelFactory"/>
<channel id="defaultChannel"/>
</beans:beans>

View File

@@ -1,149 +0,0 @@
/*
* Copyright 2002-2008 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.integration.channel.factory;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.integration.bus.DefaultChannelFactoryBean;
import org.springframework.integration.channel.AbstractMessageChannel;
import org.springframework.integration.channel.ChannelInterceptor;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.PriorityChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.channel.RendezvousChannel;
import org.springframework.integration.channel.ThreadLocalChannel;
import org.springframework.integration.channel.interceptor.ChannelInterceptorAdapter;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageBuilder;
/**
* @author Marius Bogoevici
* @author Mark Fisher
*/
public class ChannelFactoryTests {
private final ArrayList<ChannelInterceptor> interceptors = new ArrayList<ChannelInterceptor>();
private final ArrayList<ChannelInterceptor> appliedInterceptors = new ArrayList<ChannelInterceptor>();
@Before
public void initInterceptorsList() {
interceptors.add(new TestChannelInterceptor());
interceptors.add(new TestChannelInterceptor());
}
@Test
public void testQueueChannelFactory() {
QueueChannelFactory channelFactory = new QueueChannelFactory();
channelFactory.setQueueCapacity(99);
genericChannelFactoryTests(channelFactory, QueueChannel.class);
assertEquals(99, channelFactory.getQueueCapacity());
}
@Test
public void testDirectChannelFactory() {
DirectChannelFactory channelFactory = new DirectChannelFactory();
assertNotNull(interceptors);
AbstractMessageChannel channel = (AbstractMessageChannel)
channelFactory.getChannel("testChannel", interceptors);
assertEquals(DirectChannel.class, channel.getClass());
assertEquals("testChannel", channel.getName());
assertInterceptors(channel);
}
@Test
public void testRendezvousChannelFactory() {
RendezvousChannelFactory channelFactory = new RendezvousChannelFactory();
genericChannelFactoryTests(channelFactory, RendezvousChannel.class);
}
@Test
public void testPriorityChannelFactory() {
PriorityChannelFactory channelFactory = new PriorityChannelFactory();
genericChannelFactoryTests(channelFactory, PriorityChannel.class);
}
@Test
public void testThreadLocalChannelFactory() {
ThreadLocalChannelFactory channelFactory = new ThreadLocalChannelFactory();
assertNotNull(interceptors);
AbstractMessageChannel channel = (AbstractMessageChannel)
channelFactory.getChannel("testChannel", interceptors);
assertEquals(ThreadLocalChannel.class, channel.getClass());
assertEquals("testChannel", channel.getName());
assertInterceptors(channel);
}
@Test
public void testDefaultChannelFactoryBean() throws Exception{
StaticApplicationContext applicationContext = new StaticApplicationContext();
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(StubChannelFactory.class);
applicationContext.registerBeanDefinition("channelFactory", builder.getBeanDefinition());
DefaultChannelFactoryBean channelFactoryBean = new DefaultChannelFactoryBean();
channelFactoryBean.setBeanName("testChannel");
channelFactoryBean.setApplicationContext(applicationContext);
channelFactoryBean.setInterceptors(interceptors);
MessageChannel channel = (MessageChannel) channelFactoryBean.getObject();
channel.getName();
assertEquals(StubChannel.class, channel.getClass());
assertEquals("testChannel", channel.getName());
channel.send(MessageBuilder.fromPayload("").build());
assertTrue(appliedInterceptors.get(0) == interceptors.get(0));
assertTrue(appliedInterceptors.get(1) == interceptors.get(1));
}
private void genericChannelFactoryTests(ChannelFactory channelFactory, Class<?> expectedChannelClass) {
assertNotNull(interceptors);
AbstractMessageChannel channel = (AbstractMessageChannel) channelFactory.getChannel("testChannel", interceptors);
assertEquals(expectedChannelClass, channel.getClass());
assertEquals("testChannel", channel.getName());
assertInterceptors(channel);
}
@SuppressWarnings("unchecked")
private void assertInterceptors(AbstractMessageChannel channel) {
Object interceptorsWrapper = new DirectFieldAccessor(channel).getPropertyValue("interceptors");
List<ChannelInterceptor> interceptors = (List<ChannelInterceptor>)
new DirectFieldAccessor(interceptorsWrapper).getPropertyValue("interceptors");
assertTrue(interceptors.get(0) == this.interceptors.get(0));
assertTrue(interceptors.get(1) == this.interceptors.get(1));
}
private class TestChannelInterceptor extends ChannelInterceptorAdapter {
public Message<?> preSend(Message<?> message, MessageChannel channel) {
appliedInterceptors.add(this);
return message;
}
}
}

View File

@@ -1,48 +0,0 @@
/*
* Copyright 2002-2008 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.integration.channel.factory;
import java.util.List;
import org.springframework.integration.channel.AbstractPollableChannel;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.selector.MessageSelector;
/**
* @author Marius Bogoevici
*/
public class StubChannel extends AbstractPollableChannel {
@Override
protected Message<?> doReceive(long timeout) {
return null;
}
@Override
protected boolean doSend(Message<?> message, long timeout) {
return false;
}
public List<Message<?>> clear() {
return null;
}
public List<Message<?>> purge(MessageSelector selector) {
return null;
}
}

View File

@@ -1,31 +0,0 @@
/*
* Copyright 2002-2008 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.integration.channel.factory;
import org.springframework.integration.channel.AbstractMessageChannel;
/**
* @author Marius Bogoevici
*/
public class StubChannelFactory extends AbstractChannelFactory {
@Override
protected AbstractMessageChannel createChannelInternal() {
return new StubChannel();
}
}

View File

@@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
<message-bus channel-factory="factory"/>
<beans:bean id="factory" class="org.springframework.integration.channel.factory.StubChannelFactory"/>
<beans:bean id="testChannel" class="org.springframework.integration.bus.DefaultChannelFactoryBean"/>
</beans:beans>

View File

@@ -37,9 +37,6 @@ import org.springframework.integration.bus.MessageBusInterceptorTests;
import org.springframework.integration.bus.TestMessageBusAwareImpl;
import org.springframework.integration.bus.TestMessageBusStartInterceptor;
import org.springframework.integration.bus.TestMessageBusStopInterceptor;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.scheduling.TaskScheduler;
import org.springframework.integration.scheduling.spi.ProviderTaskScheduler;
@@ -115,15 +112,6 @@ public class MessageBusParserTests {
assertTrue(messageBusAware.getMessageBus() == context.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME));
}
@Test
public void testMessageBusWithChannelFactory() {
ApplicationContext context = new ClassPathXmlApplicationContext("messageBusWithChannelFactory.xml",
this.getClass());
((MessageChannel)context.getBean("defaultTypeChannel")).getName();
assertEquals(DirectChannel.class, context.getBean("defaultTypeChannel").getClass());
assertEquals(QueueChannel.class, context.getBean("specifiedTypeChannel").getClass());
}
@Test
public void testMulticasterIsSyncByDefault() {
ApplicationContext context = new ClassPathXmlApplicationContext(

View File

@@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
<message-bus/>
<beans:bean id="channelFactory" class="org.springframework.integration.channel.factory.DirectChannelFactory"/>
<channel id="defaultTypeChannel"/>
<queue-channel id="specifiedTypeChannel"/>
</beans:beans>