use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.
the class XPathExpressionParserTests method testNamespacedStringExpression.
@Test
public void testNamespacedStringExpression() throws Exception {
String xmlDoc = "<si-xml:xpath-expression id='xpathExpression' expression='/ns1:name' ns-prefix='ns1' ns-uri='www.example.org' />";
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>")));
}
use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.
the class XPathRouterTests method multipleNodeValuesAsString.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public /*
* Will return only one (the first node text in the collection), since
* the evaluation return type use is String (not NODESET)
* This test is just for sanity and the reminder that setting 'evaluateAsNode'
* to 'false' would still result in no exception but result will most likely be
* not what is expected.
*/
void multipleNodeValuesAsString() throws Exception {
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/book");
XPathRouter router = new XPathRouter(expression);
router.setEvaluateAsString(true);
Object[] channelNames = router.getChannelKeys(new GenericMessage("<doc type=\"one\"><book>bOne</book><book>bTwo</book></doc>")).toArray();
assertEquals("Wrong number of channels returned", 1, channelNames.length);
assertEquals("Wrong channel name", "bOne", channelNames[0]);
}
use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.
the class XPathRouterTests method testNonNodePayload.
@Test(expected = MessagingException.class)
public void testNonNodePayload() 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 camel by apache.
the class SpringWebserviceComponent method addConsumerConfiguration.
private void addConsumerConfiguration(String remaining, Map<String, Object> parameters, SpringWebserviceConfiguration configuration) {
EndpointMappingType type = EndpointMappingType.getTypeFromUriPrefix(remaining);
if (type != null) {
LOG.debug("Building Spring Web Services consumer of type " + type);
String lookupKey = getLookupKey(remaining, type);
if (EndpointMappingType.BEANNAME.equals(type)) {
addEndpointDispatcherToConfiguration(configuration, lookupKey);
} else {
addEndpointMappingToConfiguration(parameters, configuration);
}
XPathExpression xPathExpression = null;
if (type.equals(EndpointMappingType.XPATHRESULT)) {
String expression = getAndRemoveParameter(parameters, "expression", String.class);
configuration.setExpression(expression);
xPathExpression = createXPathExpression(expression);
}
configuration.setEndpointMappingKey(new EndpointMappingKey(type, lookupKey, xPathExpression));
}
}
use of org.springframework.xml.xpath.XPathExpression in project spring-integration by spring-projects.
the class BooleanTestXpathMessageSelectorTests method testStringWithXPathExpressionProvided.
@Test
public void testStringWithXPathExpressionProvided() {
XPathExpression xpathExpression = XPathExpressionFactory.createXPathExpression("boolean(/one/two)");
BooleanTestXPathMessageSelector selector = new BooleanTestXPathMessageSelector(xpathExpression);
assertTrue(selector.accept(new GenericMessage<String>("<one><two/></one>")));
assertFalse(selector.accept(new GenericMessage<String>("<one><three/></one>")));
}
Aggregations