camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r753316 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/bean/ test/java/org/apache/camel/component/bean/ test/java/org/apache/camel/processor/
Date Fri, 13 Mar 2009 16:46:36 GMT
Author: davsclaus
Date: Fri Mar 13 16:46:33 2009
New Revision: 753316

URL: http://svn.apache.org/viewvc?rev=753316&view=rev
Log:
CAMEL-1424: A bit more work on BeanInfo. Adding unit tests for missing gaps in code coverage
reports.

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanConstants.java
  (with props)
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/CustomParameterMappingStrategyTest.java
      - copied, changed from r753289, camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/DefaultParameterMappingStrategyTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterMappingStrategy.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExceptionTest.java

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanConstants.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanConstants.java?rev=753316&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanConstants.java
(added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanConstants.java
Fri Mar 13 16:46:33 2009
@@ -0,0 +1,29 @@
+/**
+ * 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;
+
+/**
+ * @version $Revision$
+ */
+public final class BeanConstants {
+
+    public static final String BEAN_PARAMETER_MAPPING_STRATEGY = "CamelBeanParameterMappingStrategy";
+
+    private BeanConstants() {
+        // Utility class
+    }
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanConstants.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java?rev=753316&r1=753315&r2=753316&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java Fri
Mar 13 16:46:33 2009
@@ -93,10 +93,9 @@
     }
 
     public static ParameterMappingStrategy createParameterMappingStrategy(CamelContext camelContext)
{
-        // lookup in registry first if there is a strategy defined
+        // lookup in registry first if there is a user define strategy
         Registry registry = camelContext.getRegistry();
-        ParameterMappingStrategy answer = registry.lookup(ParameterMappingStrategy.class.getName(),
-                                                          ParameterMappingStrategy.class);
+        ParameterMappingStrategy answer = registry.lookup(BeanConstants.BEAN_PARAMETER_MAPPING_STRATEGY,
ParameterMappingStrategy.class);
         if (answer == null) {
             // no then use the default one
             answer = new DefaultParameterMappingStrategy();
@@ -105,6 +104,10 @@
         return answer;
     }
 
+    /**
+     * @deprecated not used
+     */
+    @Deprecated
     public MethodInvocation createInvocation(Method method, Object pojo, Exchange exchange)
throws RuntimeCamelException {
         MethodInfo methodInfo = introspect(type, method);
         if (methodInfo != null) {
@@ -354,11 +357,11 @@
         } else if (possibles.size() == 1) {
             return possibles.get(0);
         } else if (possibles.isEmpty()) {
+            // TODO: This code is not covered by existing unit test in camel-core, need to
be tested
             if (LOG.isTraceEnabled()) {
                 LOG.trace("No poosible methods trying to convert body to parameter types");
             }
 
-            // TODO: Make sure this is properly unit tested
             // lets try converting
             Object newBody = null;
             MethodInfo matched = null;

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterMappingStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterMappingStrategy.java?rev=753316&r1=753315&r2=753316&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterMappingStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterMappingStrategy.java
Fri Mar 13 16:46:33 2009
@@ -25,5 +25,12 @@
  */
 public interface ParameterMappingStrategy {
 
+    /**
+     * Gets an expression used for evaluation with the current Exchange and its result
+     * is used as parameter value for the given type
+     *
+     * @param parameterType the parameter type
+     * @return the expression to evalute as value
+     */
     Expression getDefaultParameterTypeExpression(Class parameterType);
 }

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/CustomParameterMappingStrategyTest.java
(from r753289, camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/DefaultParameterMappingStrategyTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/CustomParameterMappingStrategyTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/CustomParameterMappingStrategyTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/DefaultParameterMappingStrategyTest.java&r1=753289&r2=753316&rev=753316&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/DefaultParameterMappingStrategyTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/CustomParameterMappingStrategyTest.java
Fri Mar 13 16:46:33 2009
@@ -18,50 +18,27 @@
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
-import org.apache.camel.TypeConverter;
+import org.apache.camel.Expression;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.ExpressionAdapter;
 import org.apache.camel.impl.JndiRegistry;
 
 /**
  * @version $Revision$
  */
-public class DefaultParameterMappingStrategyTest extends ContextTestSupport {
+public class CustomParameterMappingStrategyTest extends ContextTestSupport {
 
     @Override
     protected JndiRegistry createRegistry() throws Exception {
         JndiRegistry jndi = super.createRegistry();
         jndi.bind("foo", new MyFooBean());
+        jndi.bind(BeanConstants.BEAN_PARAMETER_MAPPING_STRATEGY, new MyCustomStrategy());
         return jndi;
     }
 
     public void testExchange() throws Exception {
-        getMockEndpoint("mock:result").expectedBodiesReceived("Exchange");
-        template.sendBody("direct:a", "Hello");
-        assertMockEndpointsSatisfied();
-    }
-
-    public void testMessage() throws Exception {
-        getMockEndpoint("mock:result").expectedBodiesReceived("Message");
-        template.sendBody("direct:b", "Hello");
-        assertMockEndpointsSatisfied();
-    }
-
-    public void testException() throws Exception {
-        getMockEndpoint("mock:result").expectedBodiesReceived("Exception");
-        template.send("direct:c", new Processor() {
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setBody("Hello");
-                exchange.setException(new IllegalArgumentException("Forced by unit test"));
-            }
-        });
-        assertMockEndpointsSatisfied();
-    }
-
-    public void testTypeConverter() throws Exception {
-        getMockEndpoint("mock:result").expectedBodiesReceived("TypeConverter");
-        template.sendBody("direct:d", "Hello");
+        getMockEndpoint("mock:result").expectedBodiesReceived("You said: Hello Claus");
+        template.sendBody("direct:a", "Claus");
         assertMockEndpointsSatisfied();
     }
 
@@ -70,49 +47,30 @@
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                errorHandler(deadLetterChannel().logStackTrace(false).disableRedelivery());
-
-                onException(Exception.class).handled(true).beanRef("foo", "withException").to("mock:result");
-
-                from("direct:a").beanRef("foo", "withExchange").to("mock:result");
-
-                from("direct:b").beanRef("foo", "withMessage").to("mock:result");
-
-                from("direct:c").to("mock:foo");
-
-                from("direct:d").beanRef("foo", "withTypeConverter").to("mock:result");
+                from("direct:a").beanRef("foo").to("mock:result");
             }
         };
     }
 
     public static class MyFooBean {
-
-        public String withExchange(Exchange exchange) {
-            assertNotNull(exchange);
-            assertEquals("Hello", exchange.getIn().getBody(String.class));
-            return "Exchange";
-        }
-
-        public String withMessage(Message message) {
-            assertNotNull(message);
-            assertEquals("Hello", message.getBody(String.class));
-            return "Message";
+        public String cheese(String body) {
+            return "You said: " + body;
         }
+    }
 
-        public String withException(Message in, Exception cause) {
-            assertNotNull(in);
-            assertNotNull(cause);
-            assertEquals("Hello", in.getBody(String.class));
-            return "Exception";
-        }
+    public static class MyCustomStrategy implements ParameterMappingStrategy {
 
-        public String withTypeConverter(String body, TypeConverter converter) {
-            assertNotNull(body);
-            assertNotNull(converter);
-            assertEquals("Hello", body);
-            assertEquals(new Integer(123), converter.convertTo(Integer.class, "123"));
-            return "TypeConverter";
+        public Expression getDefaultParameterTypeExpression(Class parameterType) {
+            if (String.class.isAssignableFrom(parameterType)) {
+                return new ExpressionAdapter() {
+                    @Override
+                    public Object evaluate(Exchange exchange) {
+                        return "Hello " + exchange.getIn().getBody(String.class);
+                    }
+                };
+            }
+            return null;
         }
-
     }
-}
+
+}
\ No newline at end of file

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExceptionTest.java?rev=753316&r1=753315&r2=753316&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExceptionTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExceptionTest.java
Fri Mar 13 16:46:33 2009
@@ -19,8 +19,10 @@
 import javax.naming.Context;
 
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
 import org.apache.camel.Header;
 import org.apache.camel.Processor;
+import org.apache.camel.Property;
 import org.apache.camel.ValidationException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -39,7 +41,13 @@
     public void testValidMessage() throws Exception {
         validEndpoint.expectedMessageCount(1);
 
-        template.sendBodyAndHeader("direct:start", "<valid/>", "foo", "bar");
+        template.send("direct:start", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody("<valid/>");
+                exchange.getIn().setHeader("foo", "bar");
+                exchange.setProperty("cheese", "old");
+            }
+        });
 
         assertMockEndpointsSatisfied();
     }
@@ -48,7 +56,13 @@
         invalidEndpoint.expectedMessageCount(1);
 
         try {
-            template.sendBodyAndHeader("direct:start", "<invalid/>", "foo", "notMatchedHeaderValue");
+            template.send("direct:start", new Processor() {
+                public void process(Exchange exchange) throws Exception {
+                    exchange.getIn().setBody("<invalid/>");
+                    exchange.getIn().setHeader("foo", "notMatchedHeaderValue");
+                    exchange.setProperty("cheese", "old");
+                }
+            });
         } catch (Exception e) {
             // expected
         }
@@ -85,7 +99,9 @@
         private static final transient Log LOG = LogFactory.getLog(ValidationBean.class);
 
         public void someMethod(String body, @Header("foo")
-                               String header) throws ValidationException {
+                               String header, @Property("cheese") String cheese) throws ValidationException
{
+            assertEquals("old", cheese);
+
             if ("bar".equals(header)) {
                 LOG.info("someMethod() called with valid header and body: " + body);
             } else {



Mime
View raw message