Search in sources :

Example 11 with XPathExpression

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

Example 12 with XPathExpression

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

Example 13 with XPathExpression

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

Example 14 with XPathExpression

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

Example 15 with XPathExpression

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