OPEN - issue INT-634: Allow queue customization

http://jira.springframework.org/browse/INT-634

Added ref attribute to <queue/> and implemented parser logic for it
This commit is contained in:
Iwein Fuld
2009-06-07 11:49:25 +00:00
parent 84481c892a
commit b49fc7c11e
6 changed files with 123 additions and 15 deletions

View File

@@ -17,8 +17,6 @@ package org.springframework.integration.aggregator;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.awt.Button;
import java.io.Serializable;
@@ -29,9 +27,11 @@ import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.integration.core.Message;
import org.springframework.integration.message.MessageBuilder;
/**
* @author Alex Peters
* @author Iwein Fuld
*
*/
public class DefaultMessageAggregatorTests {
@@ -44,14 +44,12 @@ public class DefaultMessageAggregatorTests {
}
@SuppressWarnings("unchecked")
@Test
@Test(timeout=1000)
public void aggregateMessages_withMultiplePayloads_allAsListInResultMsg() {
List<Serializable> anyPayloads = Arrays.asList("foo", "bar", 123L, new Button());
List<Message<?>> messageGroup = new ArrayList<Message<?>>(anyPayloads.size());
for (Serializable payload : anyPayloads) {
Message<Serializable> mock = mock(Message.class);
when(mock.getPayload()).thenReturn(payload);
messageGroup.add(mock);
messageGroup.add(MessageBuilder.withPayload(payload).build());
}
Message<?> result = aggregator.aggregateMessages(messageGroup);
assertThat((List<Serializable>) result.getPayload(), is(anyPayloads));

View File

@@ -48,6 +48,8 @@ import org.springframework.integration.util.ErrorHandlingTaskExecutor;
/**
* @author Mark Fisher
* @author Iwein Fuld
*
* @see ChannelWithCustomQueueParserTests
*/
public class ChannelParserTests {

View File

@@ -0,0 +1,19 @@
<?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-1.0.xsd">
<channel id="customQueueChannel">
<queue ref="queue" />
</channel>
<beans:bean id="queue" class="java.util.concurrent.ArrayBlockingQueue">
<beans:constructor-arg value="2" />
</beans:bean>
</beans:beans>

View File

@@ -0,0 +1,65 @@
/*
* 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.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Testcases for detailed namespace support for &lt;queue/> element under
* &lt;channel/>
*
* @author Iwein Fuld
*
* @see ChannelWithCustomQueueParserTests
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class ChannelWithCustomQueueParserTests {
@Qualifier("customQueueChannel")
@Autowired
QueueChannel customQueueChannel;
@Test
public void parseConfig() throws Exception {
assertNotNull(customQueueChannel);
}
@Test
public void queueTypeSet() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(customQueueChannel);
Object queue = accessor.getPropertyValue("queue");
assertNotNull(queue);
assertThat(queue, is(ArrayBlockingQueue.class));
assertThat(((BlockingQueue<?>)queue).remainingCapacity(), is(2));
}
}