Search in sources :

Example 16 with XPathExpression

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]);
}
Also used : XPathExpression(org.springframework.xml.xpath.XPathExpression) GenericMessage(org.springframework.messaging.support.GenericMessage) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 17 with XPathExpression

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);
}
Also used : XPathExpression(org.springframework.xml.xpath.XPathExpression) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 18 with XPathExpression

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());
}
Also used : XPathExpression(org.springframework.xml.xpath.XPathExpression) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 19 with XPathExpression

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]);
}
Also used : XPathExpression(org.springframework.xml.xpath.XPathExpression) GenericMessage(org.springframework.messaging.support.GenericMessage) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 20 with XPathExpression

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>")));
}
Also used : XPathExpression(org.springframework.xml.xpath.XPathExpression) Test(org.junit.Test)

Aggregations

XPathExpression (org.springframework.xml.xpath.XPathExpression)21 Test (org.junit.Test)18 Document (org.w3c.dom.Document)9 GenericMessage (org.springframework.messaging.support.GenericMessage)7 Node (org.w3c.dom.Node)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 EndpointMappingKey (org.apache.camel.component.spring.ws.type.EndpointMappingKey)1 EndpointMappingType (org.apache.camel.component.spring.ws.type.EndpointMappingType)1 HttpMessageConversionException (org.springframework.http.converter.HttpMessageConversionException)1 HttpMessageNotReadableException (org.springframework.http.converter.HttpMessageNotReadableException)1 HttpMessageNotWritableException (org.springframework.http.converter.HttpMessageNotWritableException)1 XPathException (org.springframework.xml.xpath.XPathException)1