resolves INT-582
Includes refactoring of router hierarchy to avoid duplication of channel resolution logic Subclasses of AbstractChannelNameResolvingMessageRouter can return MessageChannel , MessageChannel[], collection ... in addition to String MethodInvokingRouter now extends AbstractChannelNameResolvingMessageRouter and is simplified as a result
This commit is contained in:
@@ -40,7 +40,7 @@ public class XPathMultiChannelRouterTests {
|
||||
Document doc = XmlTestUtil.getDocumentForString("<doc type=\"one\" />");
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/@type");
|
||||
XPathMultiChannelRouter router = new XPathMultiChannelRouter(expression);
|
||||
String[] channelNames = router.determineTargetChannelNames(new GenericMessage(doc));
|
||||
Object[] channelNames = router.getChannelIndicatorList(new GenericMessage(doc)).toArray();
|
||||
assertEquals("Wrong number of channels returned", 1, channelNames.length);
|
||||
assertEquals("Wrong channel name", "one", channelNames[0]);
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class XPathMultiChannelRouterTests {
|
||||
Document doc = XmlTestUtil.getDocumentForString("<doc type=\"one\"><book>bOne</book><book>bTwo</book></doc>");
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/book");
|
||||
XPathMultiChannelRouter router = new XPathMultiChannelRouter(expression);
|
||||
String[] channelNames = router.determineTargetChannelNames(new GenericMessage(doc));
|
||||
Object[] channelNames = router.getChannelIndicatorList(new GenericMessage(doc)).toArray();
|
||||
assertEquals("Wrong number of channels returned", 2, channelNames.length);
|
||||
assertEquals("Wrong channel name", "bOne", channelNames[0]);
|
||||
assertEquals("Wrong channel name", "bTwo", channelNames[1]);
|
||||
@@ -62,7 +62,7 @@ public class XPathMultiChannelRouterTests {
|
||||
public void multipleNodeValuesAsString() throws Exception {
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/book");
|
||||
XPathMultiChannelRouter router = new XPathMultiChannelRouter(expression);
|
||||
String[] channelNames = router.determineTargetChannelNames(new GenericMessage("<doc type=\"one\"><book>bOne</book><book>bTwo</book></doc>"));
|
||||
Object[] channelNames = router.getChannelIndicatorList(new GenericMessage("<doc type=\"one\"><book>bOne</book><book>bTwo</book></doc>")).toArray();
|
||||
assertEquals("Wrong number of channels returned", 2, channelNames.length);
|
||||
assertEquals("Wrong channel name", "bOne", channelNames[0]);
|
||||
assertEquals("Wrong channel name", "bTwo", channelNames[1]);
|
||||
@@ -72,14 +72,14 @@ public class XPathMultiChannelRouterTests {
|
||||
public void nonNodePayload() throws Exception {
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/@type");
|
||||
XPathMultiChannelRouter router = new XPathMultiChannelRouter(expression);
|
||||
router.determineTargetChannelNames(new StringMessage("test"));
|
||||
router.getChannelIndicatorList(new StringMessage("test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nodePayload() throws Exception {
|
||||
XPathMultiChannelRouter router = new XPathMultiChannelRouter("./three/text()");
|
||||
Document testDocument = XmlTestUtil.getDocumentForString("<one><two><three>bob</three><three>dave</three></two></one>");
|
||||
String[] channelNames = router.determineTargetChannelNames(new GenericMessage<Node>(testDocument.getElementsByTagName("two").item(0)));
|
||||
Object[] channelNames = router.getChannelIndicatorList(new GenericMessage<Node>(testDocument.getElementsByTagName("two").item(0))).toArray();
|
||||
assertEquals("bob",channelNames[0]);
|
||||
assertEquals("dave",channelNames[1]);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class XPathSingleChannelRouterTests {
|
||||
Document doc = XmlTestUtil.getDocumentForString("<doc type='one' />");
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/@type");
|
||||
XPathSingleChannelRouter router = new XPathSingleChannelRouter(expression);
|
||||
String channelName = router.determineTargetChannelNames(new GenericMessage<Document>(doc))[0];
|
||||
Object channelName = router.getChannelIndicatorList(new GenericMessage<Document>(doc)).toArray()[0];
|
||||
assertEquals("Wrong channel name", "one", channelName);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class XPathSingleChannelRouterTests {
|
||||
public void testSimpleStringDoc() throws Exception {
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/@type");
|
||||
XPathSingleChannelRouter router = new XPathSingleChannelRouter(expression);
|
||||
String channelName = router.determineTargetChannelNames(new GenericMessage<String>("<doc type='one' />"))[0];
|
||||
Object channelName = router.getChannelIndicatorList(new GenericMessage<String>("<doc type='one' />")).toArray()[0];
|
||||
assertEquals("Wrong channel name", "one", channelName);
|
||||
}
|
||||
|
||||
@@ -54,15 +54,15 @@ public class XPathSingleChannelRouterTests {
|
||||
public void testNonNodePayload() throws Exception {
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/@type");
|
||||
XPathSingleChannelRouter router = new XPathSingleChannelRouter(expression);
|
||||
router.determineTargetChannelNames(new StringMessage("test"));
|
||||
router.getChannelIndicatorList(new StringMessage("test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNodePayload() throws Exception {
|
||||
XPathSingleChannelRouter router = new XPathSingleChannelRouter("./three/text()");
|
||||
Document testDocument = XmlTestUtil.getDocumentForString("<one><two><three>bob</three></two></one>");
|
||||
String[] channelNames = router.determineTargetChannelNames(new GenericMessage<Node>(testDocument
|
||||
.getElementsByTagName("two").item(0)));
|
||||
Object[] channelNames = router.getChannelIndicatorList(new GenericMessage<Node>(testDocument
|
||||
.getElementsByTagName("two").item(0))).toArray();
|
||||
assertEquals("bob", channelNames[0]);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class XPathSingleChannelRouterTests {
|
||||
Document doc = XmlTestUtil.getDocumentForString("<doc type='one' />");
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/somethingelse/@type");
|
||||
XPathSingleChannelRouter router = new XPathSingleChannelRouter(expression);
|
||||
Object channelNames = router.determineTargetChannelNames(new GenericMessage<Document>(doc));
|
||||
Object channelNames = router.getChannelIndicatorList(new GenericMessage<Document>(doc));
|
||||
assertEquals("Wrong channel name", null, channelNames);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user