use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.
the class XPathRouterTests method multipleNodeValues.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void multipleNodeValues() throws Exception {
Document doc = XmlTestUtil.getDocumentForString("<doc type=\"one\"><book>bOne</book><book>bTwo</book></doc>");
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/book");
XPathRouter router = new XPathRouter(expression);
Object[] channelNames = router.getChannelKeys(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]);
}
use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.
the class XPathRouterTests method testSimpleDocType.
@Test
public void testSimpleDocType() throws Exception {
Document doc = XmlTestUtil.getDocumentForString("<doc type='one' />");
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/@type");
XPathRouter router = new XPathRouter(expression);
Object channelName = router.getChannelKeys(new GenericMessage<Document>(doc)).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 testEvaluationReturnsEmptyString.
@Test
public void testEvaluationReturnsEmptyString() throws Exception {
Document doc = XmlTestUtil.getDocumentForString("<doc type='one' />");
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/somethingelse/@type");
XPathRouter router = new XPathRouter(expression);
List<Object> channelNames = router.getChannelKeys(new GenericMessage<Document>(doc));
assertEquals(0, channelNames.size());
}
use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.
the class XPathRouterTests method simpleSingleAttribute.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void simpleSingleAttribute() throws Exception {
Document doc = XmlTestUtil.getDocumentForString("<doc type=\"one\" />");
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/@type");
XPathRouter router = new XPathRouter(expression);
Object[] channelNames = router.getChannelKeys(new GenericMessage(doc)).toArray();
assertEquals("Wrong number of channels returned", 1, channelNames.length);
assertEquals("Wrong channel name", "one", channelNames[0]);
}
use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.
the class XPathExpressionParserTests method testNamespacePrefixButNoUri.
@Test(expected = BeanDefinitionStoreException.class)
public void testNamespacePrefixButNoUri() throws Exception {
String xmlDoc = "<si-xml:xpath-expression id='xpathExpression' expression='/ns1:name' ns-prefix='ns1' />";
XPathExpression xPathExpression = getXPathExpression(xmlDoc);
assertEquals("outputOne", xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>")));
assertEquals("", xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<name>outputOne</name>")));
}
Aggregations