refactored namespace support for xpath-router and xpath-selector

This commit is contained in:
Jonas Partner
2008-10-01 17:21:32 +00:00
parent 13100735e0
commit 7843007930
10 changed files with 74 additions and 189 deletions

View File

@@ -26,14 +26,14 @@ public class XPathExpressionParserTests {
@Test
public void testSimpleStringExpression() throws Exception {
String xmlDoc = "<si-xml:xpath-expression id='xpathExpression' xpath-expression='/name' />";
String xmlDoc = "<si-xml:xpath-expression id='xpathExpression' expression='/name' />";
XPathExpression xPathExpression = getXPathExpression(xmlDoc);
assertEquals("outputOne",xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<name>outputOne</name>")));
}
@Test
public void testNamespacedStringExpression() throws Exception {
String xmlDoc = "<si-xml:xpath-expression id='xpathExpression' xpath-expression='/ns1:name' ns-prefix='ns1' ns-uri='www.example.org' />";
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>")));
@@ -41,7 +41,7 @@ public class XPathExpressionParserTests {
@Test
public void testStringExpressionWithNamespaceMapReference() throws Exception {
StringBuffer xmlDoc = new StringBuffer("<si-xml:xpath-expression id='xpathExpression' xpath-expression='/ns1:name' namespace-map='myNamespaces' />");
StringBuffer xmlDoc = new StringBuffer("<si-xml:xpath-expression id='xpathExpression' expression='/ns1:name' namespace-map='myNamespaces' />");
xmlDoc.append("<util:map id='myNamespaces'><entry key='ns1' value='www.example.org' /></util:map>");
XPathExpression xPathExpression = getXPathExpression(xmlDoc.toString());
assertEquals("outputOne",xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>")));
@@ -50,7 +50,7 @@ public class XPathExpressionParserTests {
@Test
public void testStringExpressionWithNamespaceInnerBean() throws Exception {
StringBuffer xmlDoc = new StringBuffer("<si-xml:xpath-expression id='xpathExpression' xpath-expression='/ns1:name' >");
StringBuffer xmlDoc = new StringBuffer("<si-xml:xpath-expression id='xpathExpression' expression='/ns1:name' >");
xmlDoc.append("<map><entry key='ns1' value='www.example.org' /></map>").append("</si-xml:xpath-expression>");
XPathExpression xPathExpression = getXPathExpression(xmlDoc.toString());
assertEquals("outputOne",xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>")));
@@ -60,7 +60,7 @@ public class XPathExpressionParserTests {
@Test(expected=BeanDefinitionStoreException.class)
public void testNamespacePrefixButNoUri() throws Exception {
String xmlDoc = "<si-xml:xpath-expression id='xpathExpression' xpath-expression='/ns1:name' ns-prefix='ns1' />";
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>")));

View File

@@ -36,7 +36,7 @@ public class XPathRouterParserTests {
Document doc = XmlTestUtil.getDocumentForString("<name>outputOne</name>");
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
TestXmlApplicationContext ctx = TestXmlApplicationContextHelper.getTestAppContext("<si-xml:xpath-router id='router' xpath-expression='/name' />");
TestXmlApplicationContext ctx = TestXmlApplicationContextHelper.getTestAppContext("<si-xml:xpath-router id='router'><si-xml:xpath-expression expression='/name'/></si-xml:xpath-router>");
XPathSingleChannelNameResolver router = (XPathSingleChannelNameResolver) ctx.getBean("router");
String[] channelNames = router.resolveChannelNames(docMessage);
@@ -50,7 +50,8 @@ public class XPathRouterParserTests {
Document doc = XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>");
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
TestXmlApplicationContext ctx = TestXmlApplicationContextHelper.getTestAppContext("<si-xml:xpath-router id='router' xpath-expression='/ns2:name' ns-prefix='ns2' ns-uri='www.example.org' />");
TestXmlApplicationContext ctx =
TestXmlApplicationContextHelper.getTestAppContext("<si-xml:xpath-router id='router'><si-xml:xpath-expression expression='/ns2:name' ns-prefix='ns2' ns-uri='www.example.org' /></si-xml:xpath-router>");
XPathSingleChannelNameResolver router = (XPathSingleChannelNameResolver) ctx.getBean("router");
String[] channelNames = router.resolveChannelNames(docMessage);
@@ -65,10 +66,10 @@ public class XPathRouterParserTests {
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
StringBuffer buffer = new StringBuffer(
"<si-xml:xpath-router id='router' xpath-expression='/ns1:name/ns2:type' >");
"<si-xml:xpath-router id='router'><si-xml:xpath-expression expression='/ns1:name/ns2:type'> ");
buffer
.append("<map><entry key='ns1' value='www.example.org' /> <entry key='ns2' value='www.example.org2'/></map>");
buffer.append("</si-xml:xpath-router>");
buffer.append("</si-xml:xpath-expression></si-xml:xpath-router>");
TestXmlApplicationContext ctx = TestXmlApplicationContextHelper.getTestAppContext(buffer.toString());
XPathSingleChannelNameResolver router = (XPathSingleChannelNameResolver) ctx.getBean("router");
@@ -84,7 +85,7 @@ public class XPathRouterParserTests {
.getDocumentForString("<ns1:name xmlns:ns1='www.example.org' xmlns:ns2='www.example.org2'><ns2:type>outputOne</ns2:type></ns1:name>");
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
StringBuffer buffer = new StringBuffer(
"<si-xml:xpath-router id='router' xpath-expression='/ns1:name/ns2:type' namespace-map='nsMap'>");
"<si-xml:xpath-router id='router' ><si-xml:xpath-expression expression='/ns1:name/ns2:type' namespace-map='nsMap'/>");
buffer
.append("</si-xml:xpath-router>")
.append("<util:map id='nsMap'><entry key='ns1' value='www.example.org' /><entry key='ns2' value='www.example.org2' /></util:map>");
@@ -98,14 +99,6 @@ public class XPathRouterParserTests {
}
@Test(expected = Exception.class)
public void testNamespacedWithNoPrefixStringExpression() throws Exception {
TestXmlApplicationContextHelper.getTestAppContext("<si-xml:xpath-router id='router' xpath-expression='/ns2:name' xpath-namespace='www.example.org' />");
}
@Test(expected = Exception.class)
public void testPrefixWithNoNamespaceStringExpression() throws Exception {
TestXmlApplicationContextHelper.getTestAppContext("<si-xml:xpath-router id='router' xpath-expression='/ns2:name' xpath-prefix='ns2' />");
}
}

View File

@@ -28,7 +28,7 @@ public class XPathSelectorParserTests {
@Test
public void testSimpleStringExpressionBoolean() throws Exception {
String contextXml = "<si-xml:xpath-selector id='selector' xpath-expression='/name' evaluation-result-type='boolean' />";
String contextXml = "<si-xml:xpath-selector id='selector' evaluation-result-type='boolean' ><si-xml:xpath-expression expression='/name'/></si-xml:xpath-selector>";
MessageSelector selector =getSelector( contextXml);
assertTrue(selector.accept(new GenericMessage<Document>(XmlTestUtil.getDocumentForString("<name>outputOne</name>"))));
@@ -37,7 +37,7 @@ public class XPathSelectorParserTests {
@Test
public void testStringExpressionWithNamespaceBoolean() throws Exception {
String contextXml = "<si-xml:xpath-selector id='selector' xpath-expression='/ns:name' ns-prefix='ns' ns-uri='www.example.org' evaluation-result-type='boolean' />";
String contextXml = "<si-xml:xpath-selector id='selector' evaluation-result-type='boolean'><si-xml:xpath-expression expression='/ns:name' ns-prefix='ns' ns-uri='www.example.org'/> </si-xml:xpath-selector>";
MessageSelector selector = getSelector(contextXml);
assertTrue(selector.accept(new GenericMessage<Document>(XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>"))));
@@ -47,7 +47,7 @@ public class XPathSelectorParserTests {
@Test
public void testStringExpressionWithNestedMap() throws Exception {
String contextXml = "<si-xml:xpath-selector id='selector' xpath-expression='/ns:name' ns-prefix='ns' ns-uri='www.example.org' evaluation-result-type='boolean' />";
String contextXml = "<si-xml:xpath-selector id='selector' evaluation-result-type='boolean'><si-xml:xpath-expression expression='/ns:name' ns-prefix='ns' ns-uri='www.example.org' /></si-xml:xpath-selector>";
MessageSelector selector = getSelector(contextXml);
assertTrue(selector.accept(new GenericMessage<Document>(XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>"))));

View File

@@ -16,7 +16,8 @@
package org.springframework.integration.xml.transformer;
import static org.custommonkey.xmlunit.XMLAssert.*;
import static junit.framework.Assert.assertTrue;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.sax.SAXResult;
@@ -26,7 +27,6 @@ import org.junit.Test;
import org.springframework.integration.message.MessagingException;
import org.springframework.integration.xml.util.XmlTestUtil;
import org.springframework.xml.transform.StringResult;
import org.w3c.dom.Document;
public class ResultToStringTransfomerTests {

View File

@@ -18,7 +18,6 @@ package org.springframework.integration.xml.util;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;