camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r612729 - in /activemq/camel/trunk/camel-core: pom.xml src/main/java/org/apache/camel/component/bean/BeanProcessor.java src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java
Date Thu, 17 Jan 2008 06:26:25 GMT
Author: ningjiang
Date: Wed Jan 16 22:26:21 2008
New Revision: 612729

URL: http://svn.apache.org/viewvc?rev=612729&view=rev
Log:
CAMEL-279 patch applied with thanks to Roman

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/pom.xml
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java

Modified: activemq/camel/trunk/camel-core/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/pom.xml?rev=612729&r1=612728&r2=612729&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/pom.xml (original)
+++ activemq/camel/trunk/camel-core/pom.xml Wed Jan 16 22:26:21 2008
@@ -83,7 +83,11 @@
       <artifactId>log4j</artifactId>
       <scope>test</scope>
     </dependency>
-
+    <dependency>
+      <groupId>org.easymock</groupId>
+      <artifactId>easymockclassextension</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
 

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java?rev=612729&r1=612728&r2=612729&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
Wed Jan 16 22:26:21 2008
@@ -95,12 +95,20 @@
             invocation = beanInfo.createInvocation(methodObject, bean, exchange);
         } else {
             // lets pass in the method name to use if its specified
-            if (ObjectHelper.isNotNullAndNonEmpty(method)) {
-                if (isNullOrBlank(in.getHeader(METHOD_NAME, String.class))) {
-                    in.setHeader(METHOD_NAME, method);
+            boolean hasToClearMethod = false;
+            try {
+                if (ObjectHelper.isNotNullAndNonEmpty(method)) {
+                    if (isNullOrBlank(in.getHeader(METHOD_NAME, String.class))) {
+                        in.setHeader(METHOD_NAME, method);
+                        hasToClearMethod = true;
+                    }
+                }
+                invocation = beanInfo.createInvocation(bean, exchange);
+            } finally {
+                if (hasToClearMethod) {
+                    in.removeHeader(METHOD_NAME);
                 }
             }
-            invocation = beanInfo.createInvocation(bean, exchange);
         }
         if (invocation == null) {
             throw new IllegalStateException("No method invocation could be created, no maching
method could be found on: " + bean);

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java?rev=612729&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java
Wed Jan 16 22:26:21 2008
@@ -0,0 +1,84 @@
+/**
+ * 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.component.bean;
+
+import javax.naming.Context;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.util.jndi.JndiContext;
+import org.easymock.EasyMock;
+
+public class ChainedBeanInvocationTest extends ContextTestSupport {
+    protected MyBean beanMock;
+
+    @Override
+    protected void setUp() throws Exception {
+        beanMock = EasyMock.createStrictMock(MyBean.class);
+        super.setUp();
+    }
+
+    @Override
+    protected Context createJndiContext() throws Exception {
+        JndiContext context = new JndiContext();
+        context.bind("myBean", beanMock);
+        return context;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .to("bean:myBean?methodName=a")
+                    .bean(beanMock, "b")
+                    .beanRef("myBean", "c");
+            }
+        };
+    }
+
+    public void testNormalInvocation() throws Throwable {
+        beanMock.a();
+        beanMock.b();
+        beanMock.c();
+        EasyMock.replay(beanMock);
+        Exchange result = template.send("direct:start", new DefaultExchange(context));
+        if (result.getException() != null) {
+            throw result.getException();
+        }
+        EasyMock.verify(beanMock);
+    }
+
+    public void testMethodHeaderSet() throws Exception {
+        beanMock.b();
+        EasyMock.expectLastCall().times(3);
+        EasyMock.replay(beanMock);
+        template.sendBodyAndHeader("direct:start", "test", BeanProcessor.METHOD_NAME, "b");
+        EasyMock.verify(beanMock);
+    }
+
+    public interface MyBean {
+        void a();
+        void b();
+        void c();
+        void d();
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message