svn commit: r595721 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/builder/ main/java/org/apache/camel/model/language/ main/resources/org/apache/camel/model/language/ test/java/org/apache/camel/processor/

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r595721 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/builder/ main/java/org/apache/camel/model/language/ main/resources/org/apache/camel/model/language/ test/java/org/apache/camel/processor/

jstrachan-2
Author: jstrachan
Date: Fri Nov 16 08:20:42 2007
New Revision: 595721

URL: http://svn.apache.org/viewvc?rev=595721&view=rev
Log:
minor refactor of the code for http://issues.apache.org/activemq/browse/CAMEL-226 to make it a bit more consistent. Also added a new test case

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java   (contents, props changed)
      - copied, changed from r595654, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCall.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MethodFilterTest.java
      - copied, changed from r594497, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/XPathFilterTest.java
Removed:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCall.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
    activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/XPathFilterTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java?rev=595721&r1=595720&r2=595721&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java Fri Nov 16 08:20:42 2007
@@ -21,7 +21,7 @@
 
 import org.apache.camel.builder.xml.Namespaces;
 import org.apache.camel.model.ExpressionNode;
-import org.apache.camel.model.language.MethodCall;
+import org.apache.camel.model.language.MethodCallExpression;
 import org.apache.camel.model.language.ExpressionType;
 import org.apache.camel.model.language.XPathExpression;
 import org.apache.camel.model.language.XQueryExpression;
@@ -57,8 +57,8 @@
      * @param bean the name of the bean looked up the registry
      * @return the builder to continue processing the DSL
      */
-    public T bean(String bean) {
-        MethodCall expression = new MethodCall(bean);
+    public T method(String bean) {
+        MethodCallExpression expression = new MethodCallExpression(bean);
         setExpressionType(expression);
         return result;
     }
@@ -72,8 +72,8 @@
      * @param method the name of the method to invoke on the bean
      * @return the builder to continue processing the DSL
      */
-    public T bean(String bean, String method) {
-        MethodCall expression = new MethodCall(bean, method);
+    public T method(String bean, String method) {
+        MethodCallExpression expression = new MethodCallExpression(bean, method);
         setExpressionType(expression);
         return result;
     }

Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java (from r595654, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCall.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java?p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java&p1=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCall.java&r1=595654&r2=595721&rev=595721&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCall.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java Fri Nov 16 08:20:42 2007
@@ -32,20 +32,20 @@
  * @version $Revision: 1.1 $
  */
 @XmlRootElement(name = "methodCall")
-public class MethodCall extends ExpressionType {
+public class MethodCallExpression extends ExpressionType {
     @XmlAttribute(required = false)
     private String bean;
     @XmlAttribute(required = false)
     private String method;
 
-    public MethodCall() {
+    public MethodCallExpression() {
     }
 
-    public MethodCall(String beanName) {
+    public MethodCallExpression(String beanName) {
         super(beanName);
     }
 
-    public MethodCall(String beanName, String method) {
+    public MethodCallExpression(String beanName, String method) {
         super(beanName);
         this.method = method;
     }

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index?rev=595721&r1=595720&r2=595721&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index (original)
+++ activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index Fri Nov 16 08:20:42 2007
@@ -20,7 +20,7 @@
 HeaderExpression
 JavaScriptExpression
 LanguageExpression
-MethodCall
+MethodCallExpression
 OgnlExpression
 PhpExpression
 PythonExpression

Copied: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MethodFilterTest.java (from r594497, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/XPathFilterTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MethodFilterTest.java?p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MethodFilterTest.java&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/XPathFilterTest.java&r1=594497&r2=595721&rev=595721&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/XPathFilterTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MethodFilterTest.java Fri Nov 16 08:20:42 2007
@@ -16,43 +16,32 @@
  */
 package org.apache.camel.processor;
 
+import javax.naming.Context;
+
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
+import org.apache.camel.Header;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * @version $Revision: 1.1 $
  */
-public class XPathFilterTest extends ContextTestSupport {
-    protected Endpoint<Exchange> startEndpoint;
-    protected MockEndpoint resultEndpoint;
-    protected String matchingBody = "<person name='James' city='London'/>";
-    protected String notMatchingBody = "<person name='Hiram' city='Tampa'/>";
-
+public class MethodFilterTest extends ContextTestSupport {
     public void testSendMatchingMessage() throws Exception {
-        resultEndpoint.expectedMessageCount(1);
+        String body = "<person name='James' city='London'/>";
+        getMockEndpoint("mock:result").expectedBodiesReceived(body);
 
-        sendBody("direct:start", matchingBody);
+        template.sendBodyAndHeader("direct:start", body, "foo", "London");
 
-        resultEndpoint.assertIsSatisfied();
+        assertMockEndpointsSatisifed();
     }
 
     public void testSendNotMatchingMessage() throws Exception {
-        resultEndpoint.expectedMessageCount(0);
-
-        sendBody("direct:start", notMatchingBody);
+        String body = "<person name='Hiram' city='Tampa'/>";
+        getMockEndpoint("mock:result").expectedMessageCount(0);
 
-        resultEndpoint.assertIsSatisfied();
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+        template.sendBodyAndHeader("direct:start", body, "foo", "Tampa");
 
-        startEndpoint = resolveMandatoryEndpoint("direct:start");
-        resultEndpoint = getMockEndpoint("mock:result");
+        assertMockEndpointsSatisifed();
     }
 
     protected RouteBuilder createRouteBuilder() {
@@ -60,10 +49,25 @@
             public void configure() {
                 // START SNIPPET: example
                 from("direct:start").
-                        filter().xpath("/person[@name='James']").
+                        filter().method("myBean", "matches").
                         to("mock:result");
                 // END SNIPPET: example
             }
         };
     }
-}
+
+    @Override
+    protected Context createJndiContext() throws Exception {
+        Context context = super.createJndiContext();
+        context.bind("myBean", new MyBean());
+        return context;
+    }
+
+    // START SNIPPET: filter
+    public static class MyBean {
+        public boolean matches(@Header(name = "foo")String location) {
+            return "London".equals(location);
+        }
+    }
+    // END SNIPPET: filter
+}
\ No newline at end of file

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/XPathFilterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/XPathFilterTest.java?rev=595721&r1=595720&r2=595721&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/XPathFilterTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/XPathFilterTest.java Fri Nov 16 08:20:42 2007
@@ -23,20 +23,21 @@
  * @version $Revision: 1.1 $
  */
 public class XPathFilterTest extends ContextTestSupport {
+    protected String matchingBody = "<person name='James' city='London'/>";
+    protected String notMatchingBody = "<person name='Hiram' city='Tampa'/>";
+
     public void testSendMatchingMessage() throws Exception {
-        String body = "<person name='James' city='London'/>";
-        getMockEndpoint("mock:result").expectedBodiesReceived(body);
+        getMockEndpoint("mock:result").expectedBodiesReceived(matchingBody);
 
-        sendBody("direct:start", body);
+        sendBody("direct:start", matchingBody);
 
         assertMockEndpointsSatisifed();
     }
 
     public void testSendNotMatchingMessage() throws Exception {
-        String body = "<person name='Hiram' city='Tampa'/>";
         getMockEndpoint("mock:result").expectedMessageCount(0);
 
-        sendBody("direct:start", body);
+        sendBody("direct:start", notMatchingBody);
 
         assertMockEndpointsSatisifed();
     }