Refactor/Standardize Router XSD Schema Attributes
- Add more documentation for schema elements in spring-integration-xml-2.1.xsd - Simplify Handling of Channel Resolution (Failures) for Routers - Fix PayloadTypeRouterTests - Update reference docs, XSD Schemas - Rename 'channel-resolution-required' to 'resolution-required' - Updated all tests accordingly
This commit is contained in:
committed by
Mark Fisher
parent
b55520369d
commit
2c023f6fd1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -19,6 +19,7 @@ package org.springframework.integration.router;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
@@ -28,6 +29,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.MessageDeliveryException;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
@@ -134,7 +136,15 @@ public class MethodInvokingRouterTests {
|
||||
Message<?> result2 = barChannel.receive(0);
|
||||
assertNotNull(result2);
|
||||
assertEquals("bar", result2.getPayload());
|
||||
router.handleMessage(badMessage);
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -171,7 +181,14 @@ public class MethodInvokingRouterTests {
|
||||
Message<?> result2 = barChannel.receive(0);
|
||||
assertNotNull(result2);
|
||||
assertEquals("bar", result2.getPayload());
|
||||
router.handleMessage(badMessage);
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -208,7 +225,14 @@ public class MethodInvokingRouterTests {
|
||||
Message<?> result2 = barChannel.receive(0);
|
||||
assertNotNull(result2);
|
||||
assertEquals("bar", result2.getPayload());
|
||||
router.handleMessage(badMessage);
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -251,7 +275,13 @@ public class MethodInvokingRouterTests {
|
||||
assertEquals("bar", result2a.getPayload());
|
||||
assertNotNull(result2b);
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
router.handleMessage(badMessage);
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -294,7 +324,13 @@ public class MethodInvokingRouterTests {
|
||||
Message<?> result2b = barChannel.receive(0);
|
||||
assertNotNull(result2b);
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
router.handleMessage(badMessage);
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -337,7 +373,13 @@ public class MethodInvokingRouterTests {
|
||||
Message<?> result2b = barChannel.receive(0);
|
||||
assertNotNull(result2b);
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
router.handleMessage(badMessage);
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -380,7 +422,14 @@ public class MethodInvokingRouterTests {
|
||||
assertEquals("bar", result2a.getPayload());
|
||||
assertNotNull(result2b);
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
router.handleMessage(badMessage);
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -423,7 +472,14 @@ public class MethodInvokingRouterTests {
|
||||
assertEquals("bar", result2a.getPayload());
|
||||
assertNotNull(result2b);
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
router.handleMessage(badMessage);
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -466,7 +522,14 @@ public class MethodInvokingRouterTests {
|
||||
assertEquals("bar", result2a.getPayload());
|
||||
assertNotNull(result2b);
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
router.handleMessage(badMessage);
|
||||
|
||||
try {
|
||||
router.handleMessage(badMessage);
|
||||
fail();
|
||||
} catch (MessageDeliveryException e) {
|
||||
/* Success */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -67,14 +67,15 @@ public class PayloadTypeRouterTests {
|
||||
router.setChannelMapping(String.class.getName(), "newChannel");
|
||||
assertEquals(1, router.getChannelIdentifiers(message1).size());
|
||||
assertEquals("newChannel", router.getChannelIdentifiers(message1).iterator().next());
|
||||
|
||||
// validate exception is thrown if mappings were removed and
|
||||
// channelResolutionRequires = true (which is the default)
|
||||
|
||||
// validate nothing happens if mappings were removed and resolutionRequires = false
|
||||
router.removeChannelMapping(String.class.getName());
|
||||
router.removeChannelMapping(Integer.class.getName());
|
||||
router.handleMessage(message1);
|
||||
|
||||
// validate exception is thrown if mappings were removed and resolutionRequires = true
|
||||
|
||||
router.setResolutionRequired(true);
|
||||
|
||||
try {
|
||||
router.handleMessage(message1);
|
||||
fail();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -27,6 +27,7 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.MessageDeliveryException;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
@@ -37,11 +38,12 @@ import org.springframework.util.CollectionUtils;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gunnar Hillert
|
||||
*/
|
||||
public class RouterTests {
|
||||
|
||||
@Test
|
||||
public void nullChannelIgnoredByDefault() {
|
||||
@Test(expected = MessageDeliveryException.class)
|
||||
public void nullChannelRaisesMessageDeliveryExceptionByDefault() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@Override
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
@@ -53,45 +55,7 @@ public class RouterTests {
|
||||
}
|
||||
|
||||
@Test(expected = MessageDeliveryException.class)
|
||||
public void nullChannelThrowsExceptionWhenResolutionRequired() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@Override
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
router.setResolutionRequired(true);
|
||||
Message<String> message = new GenericMessage<String>("test");
|
||||
router.handleMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyChannelListIgnoredByDefault() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@Override
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Message<String> message = new GenericMessage<String>("test");
|
||||
router.handleMessage(message);
|
||||
}
|
||||
|
||||
@Test(expected = MessageDeliveryException.class)
|
||||
public void emptyChannelListThrowsExceptionWhenResolutionRequired() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@Override
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
router.setResolutionRequired(true);
|
||||
Message<String> message = new GenericMessage<String>("test");
|
||||
router.handleMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullChannelIdentifierIgnoredByDefault() {
|
||||
public void nullChannelIdentifierUsingChannelResolverRaisesMessageDeliveryExceptionByDefault() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@Override
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
@@ -104,8 +68,8 @@ public class RouterTests {
|
||||
router.handleMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullChannelIdentifierInListIgnoredByDefault() {
|
||||
@Test(expected = MessageDeliveryException.class)
|
||||
public void nullChannelIdentifierInListRaisesMessageDeliveryExceptionByDefault() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@Override
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
@@ -119,35 +83,7 @@ public class RouterTests {
|
||||
}
|
||||
|
||||
@Test(expected = MessageDeliveryException.class)
|
||||
public void nullChannelIdentifierTriggersExceptionWhenResolutionRequired() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
TestChannelResolver channelResolver = new TestChannelResolver();
|
||||
router.setChannelResolver(channelResolver);
|
||||
router.setResolutionRequired(true);
|
||||
Message<String> message = new GenericMessage<String>("test");
|
||||
router.handleMessage(message);
|
||||
}
|
||||
|
||||
@Test(expected = MessageDeliveryException.class)
|
||||
public void nullChannelIdentifierInListTriggersExceptionWhenResolutionRequired() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return Collections.singletonList(null);
|
||||
}
|
||||
};
|
||||
TestChannelResolver channelResolver = new TestChannelResolver();
|
||||
router.setChannelResolver(channelResolver);
|
||||
router.setResolutionRequired(true);
|
||||
Message<String> message = new GenericMessage<String>("test");
|
||||
router.handleMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyChannelNameArrayIgnoredByDefault() {
|
||||
public void emptyChannelNameArrayRaisesMessageDeliveryExceptionByDefault() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return new ArrayList<Object>();
|
||||
@@ -159,21 +95,6 @@ public class RouterTests {
|
||||
router.handleMessage(message);
|
||||
}
|
||||
|
||||
@Test(expected = MessageDeliveryException.class)
|
||||
public void emptyChannelNameArrayThrowsExceptionWhenResolutionRequired() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return CollectionUtils.arrayToList(new String[] {});
|
||||
}
|
||||
};
|
||||
TestChannelResolver channelResolver = new TestChannelResolver();
|
||||
router.setChannelResolver(channelResolver);
|
||||
router.setResolutionRequired(true);
|
||||
Message<String> message = new GenericMessage<String>("test");
|
||||
router.handleMessage(message);
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
public void channelMappingIsRequiredWhenResolvingChannelNames() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@@ -203,4 +124,282 @@ public class RouterTests {
|
||||
assertEquals("test", reply.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanFactoryWithRouterAndMultipleCommaSeparatedChannelNames() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return CollectionUtils.arrayToList(new String[] { "testChannel1,testChannel2" });
|
||||
}
|
||||
};
|
||||
|
||||
QueueChannel testChannel1 = new QueueChannel();
|
||||
QueueChannel testChannel2 = new QueueChannel();
|
||||
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
|
||||
context.getBeanFactory().registerSingleton("testChannel1", testChannel1);
|
||||
context.getBeanFactory().registerSingleton("testChannel2", testChannel2);
|
||||
|
||||
router.setBeanFactory(context);
|
||||
router.handleMessage(new GenericMessage<String>("test"));
|
||||
|
||||
Message<?> reply1 = testChannel1.receive(0);
|
||||
assertEquals("test", reply1.getPayload());
|
||||
|
||||
Message<?> reply2 = testChannel2.receive(0);
|
||||
assertEquals("test", reply2.getPayload());
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
public void channelResolutionIsRequiredByDefault() {
|
||||
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return CollectionUtils.arrayToList(new String[] { "testChannelDoesNotExist", "testChannel" });
|
||||
}
|
||||
};
|
||||
|
||||
QueueChannel testChannel = new QueueChannel();
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.getBeanFactory().registerSingleton("testChannel", testChannel);
|
||||
router.setBeanFactory(context);
|
||||
router.handleMessage(new GenericMessage<String>("test"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unresolvableChannelIdentifierInListAreIgnoredWhenResolutionRequiredIsFalse() {
|
||||
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return CollectionUtils.arrayToList(new String[] { "testChannelDoesNotExist", "testChannel" });
|
||||
}
|
||||
};
|
||||
|
||||
router.setResolutionRequired(false);
|
||||
|
||||
QueueChannel testChannel = new QueueChannel();
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.getBeanFactory().registerSingleton("testChannel", testChannel);
|
||||
router.setBeanFactory(context);
|
||||
router.handleMessage(new GenericMessage<String>("test"));
|
||||
Message<?> reply = testChannel.receive(0);
|
||||
assertEquals("test", reply.getPayload());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanFactoryWithRouterAndChannelPrefix() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return CollectionUtils.arrayToList(new String[] { "MyChannel" });
|
||||
}
|
||||
};
|
||||
|
||||
router.setPrefix("testing_");
|
||||
|
||||
QueueChannel testChannel = new QueueChannel();
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.getBeanFactory().registerSingleton("testing_MyChannel", testChannel);
|
||||
router.setBeanFactory(context);
|
||||
router.handleMessage(new GenericMessage<String>("test"));
|
||||
Message<?> reply = testChannel.receive(0);
|
||||
assertEquals("test", reply.getPayload());
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
public void beanFactoryWithRouterAndChannelPrefixFailing() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return CollectionUtils.arrayToList(new String[] { "testing_MyChannel" });
|
||||
}
|
||||
};
|
||||
|
||||
router.setPrefix("testing_");
|
||||
|
||||
QueueChannel testChannel = new QueueChannel();
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.getBeanFactory().registerSingleton("testing_MyChannel", testChannel);
|
||||
router.setBeanFactory(context);
|
||||
router.handleMessage(new GenericMessage<String>("test"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanFactoryWithRouterAndChannelSuffix() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return CollectionUtils.arrayToList(new String[] { "MyChannel" });
|
||||
}
|
||||
};
|
||||
|
||||
router.setSuffix("_withSuffix");
|
||||
|
||||
QueueChannel testChannel = new QueueChannel();
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.getBeanFactory().registerSingleton("MyChannel_withSuffix", testChannel);
|
||||
router.setBeanFactory(context);
|
||||
router.handleMessage(new GenericMessage<String>("test"));
|
||||
Message<?> reply = testChannel.receive(0);
|
||||
assertEquals("test", reply.getPayload());
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
public void beanFactoryWithRouterAndChannelSuffixFailing() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return CollectionUtils.arrayToList(new String[] { "MyChannel_withSuffix" });
|
||||
}
|
||||
};
|
||||
|
||||
router.setSuffix("_withSuffix");
|
||||
|
||||
QueueChannel testChannel = new QueueChannel();
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.getBeanFactory().registerSingleton("MyChannel_withSuffix", testChannel);
|
||||
router.setBeanFactory(context);
|
||||
router.handleMessage(new GenericMessage<String>("test"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanFactoryWithRouterAndChannelIdentifiersInListWithinAList() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
|
||||
List<String> channelNames1 = CollectionUtils.arrayToList(new String[] { "channel1" });
|
||||
List<String> channelNames2 = CollectionUtils.arrayToList(new String[] { "channel2" });
|
||||
|
||||
List<Object> listWithListOfChannelNames = new ArrayList<Object>();
|
||||
|
||||
listWithListOfChannelNames.add(channelNames1);
|
||||
listWithListOfChannelNames.add(channelNames2);
|
||||
|
||||
return listWithListOfChannelNames;
|
||||
}
|
||||
};
|
||||
|
||||
QueueChannel testChannel1 = new QueueChannel();
|
||||
QueueChannel testChannel2 = new QueueChannel();
|
||||
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
|
||||
context.getBeanFactory().registerSingleton("channel1", testChannel1);
|
||||
context.getBeanFactory().registerSingleton("channel2", testChannel2);
|
||||
|
||||
router.setBeanFactory(context);
|
||||
router.handleMessage(new GenericMessage<String>("test"));
|
||||
|
||||
Message<?> reply1 = testChannel1.receive(0);
|
||||
assertEquals("test", reply1.getPayload());
|
||||
|
||||
Message<?> reply2 = testChannel2.receive(0);
|
||||
assertEquals("test", reply2.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanFactoryWithRouterAndChannelIdentifiersInMessageChannelArrayWithinAList() {
|
||||
|
||||
final QueueChannel testChannel1 = new QueueChannel();
|
||||
final QueueChannel testChannel2 = new QueueChannel();
|
||||
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
|
||||
MessageChannel[] channelNames1 = new MessageChannel[] { testChannel1 };
|
||||
MessageChannel[] channelNames2 = new MessageChannel[] { testChannel2 };
|
||||
|
||||
List<Object> listWithListOfChannelNames = new ArrayList<Object>();
|
||||
|
||||
listWithListOfChannelNames.add(channelNames1);
|
||||
listWithListOfChannelNames.add(channelNames2);
|
||||
|
||||
return listWithListOfChannelNames;
|
||||
}
|
||||
};
|
||||
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
|
||||
context.getBeanFactory().registerSingleton("channel1", testChannel1);
|
||||
context.getBeanFactory().registerSingleton("channel2", testChannel2);
|
||||
|
||||
router.setBeanFactory(context);
|
||||
router.handleMessage(new GenericMessage<String>("test"));
|
||||
|
||||
Message<?> reply1 = testChannel1.receive(0);
|
||||
assertEquals("test", reply1.getPayload());
|
||||
|
||||
Message<?> reply2 = testChannel2.receive(0);
|
||||
assertEquals("test", reply2.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanFactoryWithRouterAndRetrieveChannelIdentifiersUsingDefaultConversionService() {
|
||||
|
||||
final QueueChannel testChannel1 = new QueueChannel();
|
||||
final QueueChannel testChannel2 = new QueueChannel();
|
||||
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return CollectionUtils.arrayToList(new Integer[] { 100, 200 });
|
||||
}
|
||||
};
|
||||
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
|
||||
context.getBeanFactory().registerSingleton("100", testChannel1);
|
||||
context.getBeanFactory().registerSingleton("200", testChannel2);
|
||||
|
||||
router.setBeanFactory(context);
|
||||
router.handleMessage(new GenericMessage<String>("test"));
|
||||
|
||||
Message<?> reply1 = testChannel1.receive(0);
|
||||
assertEquals("test", reply1.getPayload());
|
||||
|
||||
Message<?> reply2 = testChannel2.receive(0);
|
||||
assertEquals("test", reply2.getPayload());
|
||||
}
|
||||
|
||||
private class CustomObjectWithChannelName {
|
||||
|
||||
String channel = "channel1";
|
||||
|
||||
public String getChannel() {
|
||||
return this.channel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
public void beanFactoryWithRouterAndRetrieveChannelIdentifierUsingDefaultConversionServiceFailing() {
|
||||
|
||||
final QueueChannel testChannel1 = new QueueChannel();
|
||||
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return CollectionUtils.arrayToList(new CustomObjectWithChannelName[] { new CustomObjectWithChannelName() });
|
||||
}
|
||||
};
|
||||
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
|
||||
context.getBeanFactory().registerSingleton("channel1", testChannel1);
|
||||
|
||||
router.setBeanFactory(context);
|
||||
router.handleMessage(new GenericMessage<String>("test"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd">
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
|
||||
<int:router input-channel="inputChannel" default-output-channel="errorChannel" ignore-channel-name-resolution-failures="true" >
|
||||
<int:router input-channel="inputChannel" default-output-channel="errorChannel" resolution-required="false">
|
||||
<bean class="org.springframework.integration.router.config.RouterParserTests.NonExistingChannelRouter"/>
|
||||
</int:router>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -49,6 +49,7 @@ import org.springframework.integration.test.util.TestUtils;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Jonas Partner
|
||||
* @author Gunnar Hillert
|
||||
*/
|
||||
public class RouterParserTests {
|
||||
|
||||
@@ -121,12 +122,11 @@ public class RouterParserTests {
|
||||
input.send(new GenericMessage<Integer>(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreChannelNameResolutionFailures() {
|
||||
public void testResolutionRequiredIsTrue() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"routerParserTests.xml", this.getClass());
|
||||
context.start();
|
||||
MessageChannel input = (MessageChannel) context.getBean("ignoreChannelNameResolutionFailuresInput");
|
||||
MessageChannel input = (MessageChannel) context.getBean("resolutionRequiredIsTrueInput");
|
||||
input.send(new GenericMessage<String>("channelThatDoesNotExist"));
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ public class RouterParserTests {
|
||||
assertEquals(new Integer(3), message3.getHeaders().getSequenceNumber());
|
||||
assertEquals(new Integer(3), message3.getHeaders().getSequenceSize());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testErrorChannel(){
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
<router id="spelRouter" input-channel="expressionRouter" expression="payload.name"
|
||||
default-output-channel="defaultChannelForExpression"
|
||||
ignore-channel-name-resolution-failures="true">
|
||||
resolution-required="false">
|
||||
<mapping value="foo" channel="fooChannelForExpression"/>
|
||||
<mapping value="bar" channel="barChannelForExpression"/>
|
||||
</router>
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
<router input-channel="pojoRouter" ref="testBean"
|
||||
default-output-channel="defaultChannelForPojo"
|
||||
ignore-channel-name-resolution-failures="true">
|
||||
resolution-required="false">
|
||||
<mapping value="foo" channel="fooChannelForPojo"/>
|
||||
<mapping value="bar" channel="barChannelForPojo"/>
|
||||
</router>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -69,7 +69,6 @@ public class RouterWithMappingTests {
|
||||
@Autowired
|
||||
private PollableChannel defaultChannelForPojo;
|
||||
|
||||
|
||||
@Test
|
||||
public void expressionRouter() {
|
||||
Message<?> message1 = MessageBuilder.withPayload(new TestBean("foo")).build();
|
||||
@@ -115,7 +114,6 @@ public class RouterWithMappingTests {
|
||||
assertNull(barChannelForPojo.receive(0));
|
||||
}
|
||||
|
||||
|
||||
private static class TestBean {
|
||||
|
||||
private final String name;
|
||||
|
||||
@@ -73,9 +73,9 @@
|
||||
|
||||
<router id="resolutionRequiredRouter" ref="pojo" method="route" input-channel="inputForRouterRequiringResolution" resolution-required="true" />
|
||||
|
||||
<channel id="ignoreChannelNameResolutionFailuresInput"/>
|
||||
<channel id="resolutionRequiredIsTrueInput"/>
|
||||
<beans:bean id="payloadAsChannelNameRouter" class="org.springframework.integration.router.config.RouterParserTests$ReturnStringPassedInAsChannelNameRouter" />
|
||||
<router id="ignoreChannelNameResolutionFailuresRouter" ref="payloadAsChannelNameRouter" input-channel="ignoreChannelNameResolutionFailuresInput" ignore-channel-name-resolution-failures="true" />
|
||||
<router id="resolutionRequiredFalseRouter" ref="payloadAsChannelNameRouter" input-channel="resolutionRequiredIsTrueInput" resolution-required="false" />
|
||||
|
||||
<channel id="timeoutRouterChannel"/>
|
||||
<router id="routerWithTimeout" ref="payloadAsChannelNameRouter" timeout="1234" input-channel="timeoutRouterChannel"/>
|
||||
|
||||
Reference in New Issue
Block a user