Added test for a <priority-channel/> with "datatype" attribute. Also, the MessageSelectingInterceptor now provides the rejected Message to the MessageDeliveryException.

This commit is contained in:
Mark Fisher
2008-03-04 22:46:22 +00:00
parent 1bed4b19e9
commit 4d6292b35a
4 changed files with 61 additions and 5 deletions

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2002-2007 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;
import java.util.Comparator;
import org.springframework.integration.message.Message;
/**
* @author Mark Fisher
*/
public class MessagePayloadTestComparator implements Comparator<Message<Comparable<Object>>> {
public int compare(Message<Comparable<Object>> message1, Message<Comparable<Object>> message2) {
return message1.getPayload().compareTo(message2.getPayload());
}
}

View File

@@ -246,6 +246,28 @@ public class ChannelParserTests {
assertEquals("D", reply4.getPayload());
}
@Test
public void testPriorityChannelWithIntegerDatatypeEnforced() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"priorityChannelParserTests.xml", this.getClass());
MessageChannel channel = (MessageChannel) context.getBean("integerOnlyPriorityChannel");
channel.send(new GenericMessage<Integer>(3));
channel.send(new GenericMessage<Integer>(2));
channel.send(new GenericMessage<Integer>(1));
assertEquals(1, channel.receive(0).getPayload());
assertEquals(2, channel.receive(0).getPayload());
assertEquals(3, channel.receive(0).getPayload());
boolean threwException = false;
try {
channel.send(new StringMessage("wrong type"));
}
catch (MessageDeliveryException e) {
assertEquals("wrong type", e.getUndeliveredMessage().getPayload());
threwException = true;
}
assertTrue(threwException);
}
private static class TestHandler implements MessageHandler {

View File

@@ -9,9 +9,11 @@
<priority-channel id="priorityChannelWithDefaultComparator"/>
<priority-channel id="priorityChannelWithCustomComparator" comparator-ref="stringPayloadComparator"/>
<priority-channel id="priorityChannelWithCustomComparator" comparator-ref="payloadComparator"/>
<beans:bean id="stringPayloadComparator"
class="org.springframework.integration.channel.PriorityChannelTests$StringPayloadComparator"/>
<priority-channel id="integerOnlyPriorityChannel" datatype="java.lang.Integer" comparator-ref="payloadComparator"/>
<beans:bean id="payloadComparator"
class="org.springframework.integration.channel.MessagePayloadTestComparator"/>
</beans:beans>