use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.
the class BooleanTestXpathMessageSelectorTests method testNodeWithXPathExpressionAsString.
@Test
public void testNodeWithXPathExpressionAsString() throws Exception {
XPathExpression xpathExpression = XPathExpressionFactory.createXPathExpression("boolean(./three)");
BooleanTestXPathMessageSelector selector = new BooleanTestXPathMessageSelector(xpathExpression);
Document testDocument = XmlTestUtil.getDocumentForString("<one><two><three/></two></one>");
assertTrue(selector.accept(new GenericMessage<Node>(testDocument.getElementsByTagName("two").item(0))));
assertFalse(selector.accept(new GenericMessage<Node>(testDocument.getElementsByTagName("three").item(0))));
}
use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.
the class XPathRouterTests method nonNodePayload.
@Test(expected = MessagingException.class)
public void nonNodePayload() throws Exception {
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/@type");
XPathRouter router = new XPathRouter(expression);
router.getChannelKeys(new GenericMessage<String>("test"));
}
use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.
the class XPathRouterTests method testSimpleStringDoc.
@Test
public void testSimpleStringDoc() throws Exception {
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/@type");
XPathRouter router = new XPathRouter(expression);
Object channelName = router.getChannelKeys(new GenericMessage<String>("<doc type='one' />")).toArray()[0];
assertEquals("Wrong channel name", "one", channelName);
}
use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.
the class XPathRouterTests method simpleRootNode.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void simpleRootNode() throws Exception {
Document doc = XmlTestUtil.getDocumentForString("<doc><foo>oleg</foo><bar>bang</bar></doc>");
XPathExpression expression = XPathExpressionFactory.createXPathExpression("name(./node())");
XPathRouter router = new XPathRouter(expression);
router.setEvaluateAsString(true);
Object[] channelNames = router.getChannelKeys(new GenericMessage(doc)).toArray();
assertEquals("Wrong number of channels returned", 1, channelNames.length);
assertEquals("Wrong channel name", "doc", channelNames[0]);
}
use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.
the class XPathRouterTests method simpleSingleAttributeAsString.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void simpleSingleAttributeAsString() throws Exception {
Document doc = XmlTestUtil.getDocumentForString("<doc type=\"one\" />");
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/@type");
XPathRouter router = new XPathRouter(expression);
router.setEvaluateAsString(true);
Object[] channelNames = router.getChannelKeys(new GenericMessage(doc)).toArray();
assertEquals("Wrong number of channels returned", 1, channelNames.length);
assertEquals("Wrong channel name", "one", channelNames[0]);
}
Aggregations