Author: ningjiang
Date: Fri Aug 31 08:24:15 2012
New Revision: 1379353
URL: http://svn.apache.org/viewvc?rev=1379353&view=rev
Log:
CAMEL-5550 Added the unit test on Spring Xpath
Added:
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathHeaderNameResultTypeAndNamespaceTest.java
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathHeaderNameTest.java
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xPathHeaderNameContext.xml
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xPathHeaderNameResultTypeAndNamespaceContext.xml
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java?rev=1379353&r1=1379352&r2=1379353&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java
Fri Aug 31 08:24:15 2012
@@ -852,7 +852,11 @@ public class XPathBuilder implements Exp
}
}
} catch (XPathExpressionException e) {
- throw new InvalidXPathExpression(getText(), e);
+ String message = getText();
+ if (ObjectHelper.isNotEmpty(getHeaderName())) {
+ message = message + " with headerName " + getHeaderName();
+ }
+ throw new InvalidXPathExpression(message, e);
} finally {
// IOHelper can handle if is is null
IOHelper.close(is);
Added:
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathHeaderNameResultTypeAndNamespaceTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathHeaderNameResultTypeAndNamespaceTest.java?rev=1379353&view=auto
==============================================================================
---
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathHeaderNameResultTypeAndNamespaceTest.java
(added)
+++
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathHeaderNameResultTypeAndNamespaceTest.java
Fri Aug 31 08:24:15 2012
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spring.processor;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.xml.XPathHeaderNameResultTypeAndNamespaceTest;
+
+import static
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringXPathHeaderNameResultTypeAndNamespaceTest extends
XPathHeaderNameResultTypeAndNamespaceTest {
+
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this,
"org/apache/camel/spring/processor/xPathHeaderNameResultTypeAndNamespaceContext.xml");
+ }
+
+}
Added:
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathHeaderNameTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathHeaderNameTest.java?rev=1379353&view=auto
==============================================================================
---
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathHeaderNameTest.java
(added)
+++
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathHeaderNameTest.java
Fri Aug 31 08:24:15 2012
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spring.processor;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.xml.XPathHeaderNameTest;
+
+import static
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringXPathHeaderNameTest extends XPathHeaderNameTest {
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this,
"org/apache/camel/spring/processor/xPathHeaderNameContext.xml");
+ }
+}
Added:
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xPathHeaderNameContext.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xPathHeaderNameContext.xml?rev=1379353&view=auto
==============================================================================
---
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xPathHeaderNameContext.xml
(added)
+++
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xPathHeaderNameContext.xml
Fri Aug 31 08:24:15 2012
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- START SNIPPET: example -->
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:in"/>
+ <choice>
+ <when>
+ <xpath
headerName="invoiceDetails">/invoice/@orderType='premium'</xpath>
+ <to uri="mock:premium"/>
+ </when>
+ <when>
+ <xpath
headerName="invoiceDetails">/invoice/@orderType='standard'</xpath>
+ <to uri="mock:standard"/>
+ </when>
+ <otherwise>
+ <to uri="mock:unknown"/>
+ </otherwise>
+ </choice>
+ </route>
+ </camelContext>
+ <!-- END SNIPPET: example -->
+</beans>
Added:
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xPathHeaderNameResultTypeAndNamespaceContext.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xPathHeaderNameResultTypeAndNamespaceContext.xml?rev=1379353&view=auto
==============================================================================
---
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xPathHeaderNameResultTypeAndNamespaceContext.xml
(added)
+++
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xPathHeaderNameResultTypeAndNamespaceContext.xml
Fri Aug 31 08:24:15 2012
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:c="http://acme.com/cheese"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- START SNIPPET: example -->
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:in"/>
+ <choice>
+ <when>
+ <xpath headerName="cheeseDetails"
resultType="java.lang.Integer">/c:number = 55</xpath>
+ <to uri="mock:55"/>
+ </when>
+ <otherwise>
+ <to uri="mock:other"/>
+ </otherwise>
+ </choice>
+ </route>
+ </camelContext>
+ <!-- END SNIPPET: example -->
+</beans>