servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r778756 [1/2] - in /servicemix/components/engines/servicemix-bean/trunk: ./ src/main/java/org/apache/servicemix/bean/ src/main/java/org/apache/servicemix/bean/pojos/ src/main/java/org/apache/servicemix/bean/support/ src/test/java/org/apache...
Date Tue, 26 May 2009 15:38:26 GMT
Author: gertv
Date: Tue May 26 15:38:25 2009
New Revision: 778756

URL: http://svn.apache.org/viewvc?rev=778756&view=rev
Log:
SMXCOMP-527: Improve test coverage for servicemix-bean

Added:
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/BeanEndpointTest.java   (with props)
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/EndpointFinderTest.java   (with props)
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/MethodInvocationFailedExceptionTest.java   (with props)
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/ParameterAnnotationsTest.java   (with props)
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/beans/ParameterAnnotationsBean.java   (with props)
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/BeanInfoTest.java   (with props)
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/BeanSupportTest.java   (with props)
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/DefaultMethodInvocationStrategyTest.java   (with props)
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ExchangeTargetTest.java   (with props)
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/HolderTest.java   (with props)
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ReflectionUtilsTest.java   (with props)
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ResolverUtilTest.java   (with props)
    servicemix/components/engines/servicemix-bean/trunk/src/test/resources/attachment.png   (with props)
Modified:
    servicemix/components/engines/servicemix-bean/trunk/pom.xml
    servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/BeanEndpoint.java
    servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/EndpointFinder.java
    servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/pojos/LoggingPojo.java
    servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/BeanInfo.java
    servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/BeanSupport.java
    servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/MethodInfo.java
    servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/ReflectionUtils.java
    servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/Request.java
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/AbstractBeanComponentTest.java
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/BeanEndpointInOptionalOutTest.java
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/ConsumerBeanTest.java
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/LoggingPojoTest.java
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/TransformBeanSupportSedaFlowTest.java
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/TransformBeanSupportTest.java
    servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/RequestTest.java

Modified: servicemix/components/engines/servicemix-bean/trunk/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/pom.xml?rev=778756&r1=778755&r2=778756&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/pom.xml (original)
+++ servicemix/components/engines/servicemix-bean/trunk/pom.xml Tue May 26 15:38:25 2009
@@ -123,6 +123,11 @@
       <version>1.2.14</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.easymock</groupId>
+      <artifactId>easymock</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
@@ -168,6 +173,18 @@
           </excludes>
         </configuration>
       </plugin>
+      <!-- exclude generated DefaultBootstrap class from Cobertura reports -->
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>cobertura-maven-plugin</artifactId>
+        <configuration>
+          <instrumentation>
+            <excludes>
+              <exclude>org/apache/servicemix/common/DefaultBootstrap.class</exclude>
+            </excludes>
+          </instrumentation>
+        </configuration>
+      </plugin>
     </plugins>
 
   </build>

Modified: servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/BeanEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/BeanEndpoint.java?rev=778756&r1=778755&r2=778756&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/BeanEndpoint.java (original)
+++ servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/BeanEndpoint.java Tue May 26 15:38:25 2009
@@ -17,6 +17,7 @@
 package org.apache.servicemix.bean;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.Map;
 import java.util.MissingResourceException;
@@ -212,55 +213,58 @@
     public void process(MessageExchange exchange) throws Exception {
         if (exchange.getRole() == Role.CONSUMER) {
             onConsumerExchange(exchange);
-        // Find or create the request for this provider exchange
-        } else if (exchange.getRole() == MessageExchange.Role.PROVIDER) {
-            onProviderExchange(exchange);
         } else {
-            throw new IllegalStateException("Unknown role: " + exchange.getRole());
+            onProviderExchange(exchange);
         }
     }
 
     protected void onProviderExchange(MessageExchange exchange) throws Exception {
         Request req = getOrCreateCurrentRequest(exchange);
         currentRequest.set(req);
-        synchronized (req) {
-            // If the bean implements MessageExchangeListener,
-            // just call the method
-            if (req.getBean() instanceof MessageExchangeListener) {
-                ((MessageExchangeListener) req.getBean()).onMessageExchange(exchange);
-            } else {
-                // Exchange is finished
-                if (exchange.getStatus() == ExchangeStatus.DONE) {
-                    return;
-                // Exchange has been aborted with an exception
-                } else if (exchange.getStatus() == ExchangeStatus.ERROR) {
-                    return;
-                // Fault message
-                } else if (exchange.getFault() != null) {
-                    // TODO: find a way to send it back to the bean before setting the DONE status
-                    done(exchange);
+        try {
+            // Find or create the request for this provider exchange
+            synchronized (req) {
+                // If the bean implements MessageExchangeListener,
+                // just call the method
+                if (req.getBean() instanceof MessageExchangeListener) {
+                    ((MessageExchangeListener) req.getBean()).onMessageExchange(exchange);
                 } else {
-                    MethodInvocation invocation = getMethodInvocationStrategy().createInvocation(
-                            req.getBean(), getBeanInfo(), exchange, this);
-                    if (invocation == null) {
-                        throw new UnknownMessageExchangeTypeException(exchange, this);
-                    }
-                    try {
-                        invocation.proceed();
-                    } catch (Exception e) {
-                        throw e;
-                    } catch (Throwable throwable) {
-                        throw new MethodInvocationFailedException(req.getBean(), invocation, exchange, this, throwable);
-                    }
-                    if (exchange.getStatus() == ExchangeStatus.ERROR) {
-                        send(exchange);
-                    }
-                    if (exchange.getFault() == null && exchange.getMessage("out") == null)  {
-                        // TODO: handle MEP correctly (DONE should only be sent for InOnly)
+                    // Exchange is finished
+                    if (exchange.getStatus() == ExchangeStatus.DONE) {
+                        return;
+                    // Exchange has been aborted with an exception
+                    } else if (exchange.getStatus() == ExchangeStatus.ERROR) {
+                        return;
+                    // Fault message
+                    } else if (exchange.getFault() != null) {
+                        // TODO: find a way to send it back to the bean before setting the DONE status
                         done(exchange);
+                    } else {
+                        MethodInvocation invocation = getMethodInvocationStrategy().createInvocation(
+                                req.getBean(), getBeanInfo(), exchange, this);
+                        if (invocation == null) {
+                            throw new UnknownMessageExchangeTypeException(exchange, this);
+                        }
+                        try {
+                            invocation.proceed();
+                        } catch (InvocationTargetException e) {
+                            throw new MethodInvocationFailedException(req.getBean(), invocation, exchange, this, e.getCause());
+                        } catch (Exception e) {
+                            throw e;
+                        } catch (Throwable throwable) {
+                            throw new MethodInvocationFailedException(req.getBean(), invocation, exchange, this, throwable);
+                        }
+                        if (exchange.getStatus() == ExchangeStatus.ERROR) {
+                            send(exchange);
+                        }
+                        if (exchange.getFault() == null && exchange.getMessage("out") == null)  {
+                            // TODO: handle MEP correctly (DONE should only be sent for InOnly)
+                            done(exchange);
+                        }
                     }
                 }
             }
+        } finally {
             checkEndOfRequest(req);
             currentRequest.set(null);
         }
@@ -326,12 +330,11 @@
         if (beanName == null && beanType == null) {
             throw new IllegalArgumentException("Property 'bean', 'beanName' or 'beanClassName' has not been set!");
         }
+        if (beanName != null && applicationContext == null) {
+            throw new IllegalArgumentException("Property 'beanName' specified, but no BeanFactory set!");
+        }
         if (beanType != null) {
             return beanType.newInstance();
-        } else if (beanName == null) {
-            throw new IllegalArgumentException("Property 'beanName', 'beanType' or 'beanClassName' must be set!");
-        } else if (applicationContext == null) {
-            throw new IllegalArgumentException("Property 'beanName' specified, but no BeanFactory set!");
         } else {
             Object answer = applicationContext.getBean(beanName);
             if (answer == null) {

Modified: servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/EndpointFinder.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/EndpointFinder.java?rev=778756&r1=778755&r2=778756&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/EndpointFinder.java (original)
+++ servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/EndpointFinder.java Tue May 26 15:38:25 2009
@@ -69,17 +69,12 @@
             if (shouldIgnoreBean(aClass)) {
                 continue;
             }
-            if (isClient(aClass)) {
-                registerClient(aClass);
-            } else if (!Modifier.isAbstract(aClass.getModifiers())) {
+            if (!isClient(aClass)) {
                 list.add(createBeanEndpoint(aClass));
             }
         }
     }
 
-    public void destroy() throws Exception {
-    }
-
     /**
      * Should the bean be ignored?
      */
@@ -99,11 +94,6 @@
         return type.isInterface() || Modifier.isAbstract(type.getModifiers());
     }
 
-    protected void registerClient(Class type) {
-        /** TODO */
-    }
-
-
     protected BeanEndpoint createBeanEndpoint(Class serviceType) {
         Endpoint endpointAnnotation = (Endpoint) serviceType.getAnnotation(Endpoint.class);
         if (endpointAnnotation == null) {

Modified: servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/pojos/LoggingPojo.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/pojos/LoggingPojo.java?rev=778756&r1=778755&r2=778756&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/pojos/LoggingPojo.java (original)
+++ servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/pojos/LoggingPojo.java Tue May 26 15:38:25 2009
@@ -47,7 +47,7 @@
 
     private Log log = LogFactory.getLog(LoggingPojo.class);
 
-    private SourceTransformer sourceTransformer = new SourceTransformer();
+    private final SourceTransformer sourceTransformer = new SourceTransformer();
 
     private int maxMsgDisplaySize = 1500;
 
@@ -59,14 +59,6 @@
         this.log = log;
     }
 
-    public SourceTransformer getSourceTransformer() {
-        return sourceTransformer;
-    }
-
-    public void setSourceTransformer(SourceTransformer sourceTransformer) {
-        this.sourceTransformer = sourceTransformer;
-    }
-
     public int getMaxMsgDisplaySize() {
         return maxMsgDisplaySize;
     }

Modified: servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/BeanInfo.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/BeanInfo.java?rev=778756&r1=778755&r2=778756&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/BeanInfo.java (original)
+++ servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/BeanInfo.java Tue May 26 15:38:25 2009
@@ -128,7 +128,7 @@
             }
         }
         Expression parametersExpression = createMethodParametersExpression(parameterExpressions);
-        operations.put(opName, new MethodInfo(clazz, method, parametersExpression));
+        operations.put(opName, new MethodInfo(method, parametersExpression));
     }
 
     protected Expression createMethodParametersExpression(final Expression[] parameterExpressions) {

Modified: servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/BeanSupport.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/BeanSupport.java?rev=778756&r1=778755&r2=778756&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/BeanSupport.java (original)
+++ servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/BeanSupport.java Tue May 26 15:38:25 2009
@@ -32,6 +32,7 @@
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.management.ObjectName;
 import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -174,6 +175,19 @@
         exchange.setMessage(answer, "out");
         getDeliveryChannel().send(exchange);
     }
+    
+    /**
+     * A helper method to reply to a given message exchange with a given Source 
+     * 
+     * @param exchange the message exchange
+     * @param answer the answer as an XML source
+     * @throws MessagingException
+     */
+    public void answer(MessageExchange exchange, Source answer) throws MessagingException {
+        NormalizedMessage message = exchange.createMessage();
+        message.setContent(answer);
+        answer(exchange, message);
+    }
 
     /**
      * A helper method which fails and completes the given exchange with the specified fault

Modified: servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/MethodInfo.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/MethodInfo.java?rev=778756&r1=778755&r2=778756&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/MethodInfo.java (original)
+++ servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/MethodInfo.java Tue May 26 15:38:25 2009
@@ -30,12 +30,11 @@
  * @version $Revision: $
  */
 public class MethodInfo {
-    private Class type;
-    private Method method;
-    private Expression parametersExpression;
+    
+    private final Method method;
+    private final Expression parametersExpression;
 
-    public MethodInfo(Class type, Method method, Expression parametersExpression) {
-        this.type = type;
+    public MethodInfo(Method method, Expression parametersExpression) {
         this.method = method;
         this.parametersExpression = parametersExpression;
     }
@@ -65,18 +64,6 @@
 
     }
 
-    public Class getType() {
-        return type;
-    }
-
-    public Method getMethod() {
-        return method;
-    }
-
-    public Expression getParametersExpression() {
-        return parametersExpression;
-    }
-
     protected Object invoke(Method mth, Object pojo, Object[] arguments, 
             MessageExchange exchange) throws IllegalAccessException, InvocationTargetException {
         return mth.invoke(pojo, arguments);

Modified: servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/ReflectionUtils.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/ReflectionUtils.java?rev=778756&r1=778755&r2=778756&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/ReflectionUtils.java (original)
+++ servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/ReflectionUtils.java Tue May 26 15:38:25 2009
@@ -22,7 +22,11 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
-public class ReflectionUtils extends org.springframework.util.ReflectionUtils {
+public final class ReflectionUtils extends org.springframework.util.ReflectionUtils {
+    
+    private ReflectionUtils() {
+        // hide constructor to keep CheckStyle happy
+    }
 
     public static <T extends Annotation> void callLifecycleMethod(final Object bean, final Class<T> annotation) {
         ReflectionUtils.doWithMethods(bean.getClass(), new ReflectionUtils.MethodCallback() {

Modified: servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/Request.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/Request.java?rev=778756&r1=778755&r2=778756&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/Request.java (original)
+++ servicemix/components/engines/servicemix-bean/trunk/src/main/java/org/apache/servicemix/bean/support/Request.java Tue May 26 15:38:25 2009
@@ -29,16 +29,13 @@
 import org.apache.servicemix.bean.BeanEndpoint;
 
 public class Request {
-    private Object bean;
+    private final Object bean;
     // Keep track of callbacks already called, so that the same callback
     // can not be called twice
     private Map<Method, Boolean> callbacks;
-    private Object correlationId;
+    private final Object correlationId;
     private final Set<MessageExchange> exchanges = new HashSet<MessageExchange>();
     
-    public Request() {
-    }
-    
     public Request(Object correlationId, Object bean, MessageExchange exchange) {
         this.correlationId = correlationId;
         this.bean = bean;
@@ -51,13 +48,6 @@
     public Object getBean() {
         return bean;
     }
-
-    /**
-     * @param bean the bean to set
-     */
-    public void setBean(Object bean) {
-        this.bean = bean;
-    }
     
     public Object getCorrelationId() {
         return correlationId;

Modified: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/AbstractBeanComponentTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/AbstractBeanComponentTest.java?rev=778756&r1=778755&r2=778756&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/AbstractBeanComponentTest.java (original)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/AbstractBeanComponentTest.java Tue May 26 15:38:25 2009
@@ -55,7 +55,9 @@
         container.shutDown();
     }
 
-    protected abstract void configureContainer();
+    protected void configureContainer() {
+        container.setFlowName("st");
+    }
     
     @SuppressWarnings("unchecked")
     protected void assertBeanEndpointRequestsMapEmpty(BeanEndpoint beanEndpoint) throws Exception {

Modified: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/BeanEndpointInOptionalOutTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/BeanEndpointInOptionalOutTest.java?rev=778756&r1=778755&r2=778756&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/BeanEndpointInOptionalOutTest.java (original)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/BeanEndpointInOptionalOutTest.java Tue May 26 15:38:25 2009
@@ -24,9 +24,12 @@
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessageExchange.Role;
 import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
 import javax.xml.namespace.QName;
 import javax.xml.transform.Source;
 
+import org.apache.servicemix.bean.support.BeanSupport;
+import org.apache.servicemix.common.util.MessageUtil;
 import org.apache.servicemix.jbi.jaxp.StringSource;
 import org.apache.servicemix.jbi.listener.MessageExchangeListener;
 
@@ -37,10 +40,6 @@
     
     private static final QName IN_OPTIONAL_OUT_PRODUCER = new QName("urn:test", "ioo-producer");
     private static final QName IN_OPTIONAL_OUT_CONSUMER = new QName("urn:test", "ioo-consumer");
-
-    protected void configureContainer() {
-        container.setFlowName("st");
-    }
     
     //we first have a set of tests that send an InOptionalOut exchange to the bean endpoint
     public void testInOptionalOutWithBeanType() throws Exception {
@@ -57,6 +56,75 @@
         assertBeanEndpointRequestsMapEmpty(endpoint);        
     }
     
+    public void testInOptionalOutWithSimplePojo() throws Exception {
+        MySimplePojo pojo = new MySimplePojo();
+        BeanEndpoint endpoint = createBeanEndpoint(pojo, IN_OPTIONAL_OUT_PRODUCER);
+        component.addEndpoint(endpoint);
+        
+        MessageExchange io = client.createInOptionalOutExchange();
+        io.setService(IN_OPTIONAL_OUT_PRODUCER);
+        io.getMessage("in").setContent(new StringSource("<request status='ok'/>"));
+        client.send(io);
+        
+        io = client.receive();
+        assertEquals(ExchangeStatus.DONE, io.getStatus());
+        assertBeanEndpointRequestsMapEmpty(endpoint);        
+    }
+    
+    public void testInOptionalOutWithPojoHandlingMessageExchange() throws Exception {
+        MyMessageExchangePojo pojo = new MyMessageExchangePojo();
+        BeanEndpoint endpoint = createBeanEndpoint(pojo, IN_OPTIONAL_OUT_PRODUCER);
+        component.addEndpoint(endpoint);
+        
+        MessageExchange io = client.createInOptionalOutExchange();
+        io.setService(IN_OPTIONAL_OUT_PRODUCER);
+        io.getMessage("in").setContent(new StringSource("<request status='ok'/>"));
+        io.getMessage("in").setProperty("todo", "fault");
+        client.send(io);
+        
+        io = client.receive();
+        assertEquals(ExchangeStatus.ACTIVE, io.getStatus());
+        assertNotNull(io.getFault());
+        client.done(io);
+        assertBeanEndpointRequestsMapEmpty(endpoint);        
+    }
+    
+    public void testInOptionalOutWithPojoHandlingMessageExchangeClientFault() throws Exception {
+        MyMessageExchangePojo pojo = new MyMessageExchangePojo();
+        BeanEndpoint endpoint = createBeanEndpoint(pojo, IN_OPTIONAL_OUT_PRODUCER);
+        component.addEndpoint(endpoint);
+        
+        MessageExchange io = client.createInOptionalOutExchange();
+        io.setService(IN_OPTIONAL_OUT_PRODUCER);
+        io.getMessage("in").setContent(new StringSource("<request status='ok'/>"));
+        io.getMessage("in").setProperty("todo", "reply");
+        client.send(io);
+        
+        io = client.receive();
+        assertEquals(ExchangeStatus.ACTIVE, io.getStatus());
+        io.setFault(io.createFault());
+        client.send(io);
+        assertBeanEndpointRequestsMapEmpty(endpoint);        
+    }
+    
+    public void testInOptionalOutWithPojoHandlingMessageExchangeClientError() throws Exception {
+        MyMessageExchangePojo pojo = new MyMessageExchangePojo();
+        BeanEndpoint endpoint = createBeanEndpoint(pojo, IN_OPTIONAL_OUT_PRODUCER);
+        component.addEndpoint(endpoint);
+        
+        MessageExchange io = client.createInOptionalOutExchange();
+        io.setService(IN_OPTIONAL_OUT_PRODUCER);
+        io.getMessage("in").setContent(new StringSource("<request status='ok'/>"));
+        io.getMessage("in").setProperty("todo", "fault");
+        client.send(io);
+        
+        io = client.receive();
+        assertEquals(ExchangeStatus.ACTIVE, io.getStatus());
+        assertNotNull(io.getFault());
+        client.fail(io, new RuntimeException("Abort! Abort!"));
+        assertBeanEndpointRequestsMapEmpty(endpoint);        
+    }
+    
     public void testInOptionalOutReturnsOut() throws Exception {
         MyInOptionalOutBean bean = new MyInOptionalOutBean();
         bean.response = new StringSource("<goodbye/>");
@@ -110,6 +178,7 @@
         assertBeanEndpointRequestsMapEmpty(endpoint);        
     }
 
+
     // this is a set of tests where the bean endpoint also acts as consumer and sends InOptionalOut exchanges
     public void testInOptionalOutConsumerDone() throws Exception {
         BeanEndpoint provider = createBeanEndpoint(MyInOptionalOutBean.class, IN_OPTIONAL_OUT_PRODUCER);
@@ -212,14 +281,11 @@
         return endpoint;
     }
     
-    public static final class MyInOptionalOutBean implements MessageExchangeListener {
+    public static final class MyInOptionalOutBean extends BeanSupport implements MessageExchangeListener {
         
         private Source fault;
         private Source response;
         
-        @Resource
-        private DeliveryChannel channel;
-
         public void onMessageExchange(MessageExchange exchange) throws MessagingException {
             if (exchange instanceof InOptionalOut) {
                 onInOptionalOut((InOptionalOut) exchange);
@@ -231,35 +297,64 @@
         private void onInOptionalOut(InOptionalOut exchange) throws MessagingException {
             if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
                 if (response != null) {
-                    exchange.setOutMessage(exchange.createMessage());
-                    exchange.getOutMessage().setContent(response);
+                    answer(exchange, response);
                     response = null;
                 } else if (fault != null) {
-                    exchange.setFault(exchange.createFault());
-                    exchange.getFault().setContent(fault);
+                    fail(exchange, exchange.createFault());
                     fault = null;
                 } else {
-                    exchange.setStatus(ExchangeStatus.DONE);
+                    done(exchange);
                 }
-                channel.send(exchange);
             }
         }
     }
     
-    public static final class MyConsumerBean implements MessageExchangeListener {
+    public static final class MySimplePojo {
+        
+        public void handle(@XPath(xpath = "/request/@status") String status) {
+            if (status.equalsIgnoreCase("ok")) {
+                // ok
+            } else {
+                // let's throw an Exception to see if we can blow things up
+                throw new RuntimeException("Expecting OK, but was " + status);
+            }
+        }
+    }
+    
+    public static final class MyMessageExchangePojo {
         
         @Resource
         private DeliveryChannel channel;
+        
+        public void handle(MessageExchange exchange, @Property(name = "todo") String todo) throws MessagingException {
+            if ("fault".equals(todo)) {
+                exchange.setFault(exchange.createFault());
+                exchange.getFault().setContent(new StringSource("<fault>It went astray!</fault>"));
+                channel.send(exchange);
+            } else if ("reply".equals(todo)) {
+                NormalizedMessage out = exchange.createMessage();
+                exchange.setMessage(out, "out");
+                MessageUtil.transfer(exchange.getMessage("in"), out);
+                channel.send(exchange);
+            } else {
+                // everything is OK
+            }
+        }
+    }
+    
+    public static final class MyConsumerBean extends BeanSupport implements MessageExchangeListener {
+        
+        @Resource
         private QName target;
         private MessageExchange original;
         private Source fault;
                 
         public void send() throws MessagingException {
-            InOptionalOut ioo = channel.createExchangeFactory().createInOptionalOutExchange();
+            InOptionalOut ioo = getExchangeFactory().createInOptionalOutExchange();
             ioo.setService(target);
             ioo.setInMessage(ioo.createMessage());
             ioo.getMessage("in").setContent(new StringSource("<hello/>"));
-            channel.send(ioo);
+            send(ioo);
         }
 
         public void onMessageExchange(MessageExchange exchange) throws MessagingException {
@@ -272,23 +367,16 @@
             } else {                
                 if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
                     if (fault != null) {
-                        exchange.setFault(exchange.createFault());
-                        exchange.getFault().setContent(fault);
+                        fail(exchange, exchange.createFault());
                         fault = null;
                     } else {
-                        exchange.setStatus(ExchangeStatus.DONE);
-                        done();
+                        done(exchange);
+                        done(original);
                     }
-                    channel.send(exchange);
                 } else {
-                    done();
+                    done(original);
                 }
             }
         }
-
-        private void done() throws MessagingException {
-            original.setStatus(ExchangeStatus.DONE);
-            channel.send(original);
-        }
     }
 }

Added: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/BeanEndpointTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/BeanEndpointTest.java?rev=778756&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/BeanEndpointTest.java (added)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/BeanEndpointTest.java Tue May 26 15:38:25 2009
@@ -0,0 +1,102 @@
+/*
+ * 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.servicemix.bean;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.bean.beans.AnnotatedBean;
+import org.springframework.beans.BeansException;
+import org.springframework.context.support.StaticApplicationContext;
+
+/**
+ * Test cases for {@link BeanEndpoint}
+ */
+public class BeanEndpointTest extends AbstractBeanComponentTest {
+    
+    private static final QName SERVICE = new QName("urn:test", "service");
+    private static final String BEAN_NAME = "MyBean";
+
+    public void testExceptionWithNothingSet() throws Exception {
+        BeanEndpoint endpoint = new BeanEndpoint();
+        try {
+            endpoint.createBean();
+            fail("Should have thrown an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            //this is what we expected
+        }
+    }
+    
+    public void testExceptionOnBeanNameWithoutApplicationContext() throws Exception {
+        BeanEndpoint endpoint = new BeanEndpoint();
+        try {
+            endpoint.setBeanName(BEAN_NAME);
+            endpoint.createBean();
+            fail("Should have thrown an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            //this is what we expected
+        }        
+    }
+    
+    public void testExceptionOnNonExistingBeanInApplicationContext() throws Exception {
+        BeanEndpoint endpoint = new BeanEndpoint();
+        try {
+            endpoint.setApplicationContext(new StaticApplicationContext() {
+                @Override
+                public Object getBean(String name) throws BeansException {
+                    return null;
+                }
+            });
+            endpoint.setBeanName(BEAN_NAME);
+            endpoint.createBean();
+            fail("Should have thrown a NoSuchBeanException");
+        } catch (NoSuchBeanException e) {
+            assertEquals(BEAN_NAME, e.getBeanName());
+            assertEquals(endpoint, e.getEndpoint());
+        }        
+    }
+    
+    public void testBeanClassName() throws Exception {
+        BeanEndpoint endpoint = new BeanEndpoint();
+        endpoint.setBeanClassName(AnnotatedBean.class.getName());
+        endpoint.setService(SERVICE);
+        endpoint.setEndpoint("endpoint");
+        component.addEndpoint(endpoint);
+        
+        assertEquals("Endpoint should have found the correct bean type", AnnotatedBean.class, endpoint.getBeanType());
+    }
+    
+    public void testExceptionOnInvalidOperationName() throws Exception {
+        BeanEndpoint endpoint = new BeanEndpoint();
+        endpoint.setBean(new Object());
+        endpoint.setService(SERVICE);
+        endpoint.setEndpoint("endpoint");
+        component.addEndpoint(endpoint);
+
+        InOnly exchange = client.createInOnlyExchange();
+        exchange.setService(SERVICE);
+        exchange.setOperation(new QName("urn:test", "invalid-ops"));
+        client.sendSync(exchange);
+        
+        assertEquals(ExchangeStatus.ERROR, exchange.getStatus());
+        assertTrue(exchange.getError() instanceof UnknownMessageExchangeTypeException);
+        UnknownMessageExchangeTypeException umete = (UnknownMessageExchangeTypeException) exchange.getError();
+        assertEquals(endpoint, umete.getEndpoint());
+        assertEquals(exchange.getExchangeId(), umete.getMessageExchange().getExchangeId());
+    }
+}

Propchange: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/BeanEndpointTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/ConsumerBeanTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/ConsumerBeanTest.java?rev=778756&r1=778755&r2=778756&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/ConsumerBeanTest.java (original)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/ConsumerBeanTest.java Tue May 26 15:38:25 2009
@@ -46,7 +46,6 @@
         jbi.shutDown();
     }
 
-    /*
     public void test() throws Exception {
         BeanComponent bc = new BeanComponent();
         BeanEndpoint ep = new BeanEndpoint();
@@ -74,7 +73,6 @@
         assertExchangeWorked(me);
         client.done(me);
     }
-    */
     
     protected void assertExchangeWorked(MessageExchange me) throws Exception {
         if (me.getStatus() == ExchangeStatus.ERROR) {

Added: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/EndpointFinderTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/EndpointFinderTest.java?rev=778756&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/EndpointFinderTest.java (added)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/EndpointFinderTest.java Tue May 26 15:38:25 2009
@@ -0,0 +1,67 @@
+/*
+ * 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.servicemix.bean;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Test cases for {@link EndpointFinder}
+ */
+public class EndpointFinderTest extends AbstractBeanComponentTest {
+    
+    private EndpointFinder finder;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        
+        finder = new EndpointFinder(component);
+    }
+    
+    public void testNameOnly() throws Exception {
+        BeanEndpoint endpoint = finder.createBeanEndpoint(MyNameEndpoint.class);
+        assertNotNull(endpoint);
+        assertEquals(component.getEPRServiceName(), endpoint.getService());
+        assertEquals("test", endpoint.getEndpoint());
+    }
+    
+    public void testLocalPartOnly() throws Exception {
+        BeanEndpoint endpoint = finder.createBeanEndpoint(MyLocalPartEndpoint.class);
+        assertNotNull(endpoint);
+        assertEquals(new QName("test"), endpoint.getService());        
+    }
+    
+    public void testCreateBeanEndpointWithNoAnnotation() throws Exception {
+        try {
+            finder.createBeanEndpoint(String.class);
+            fail("Should have thrown an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            //this is OK
+        }
+    }
+    
+    @Endpoint(name = "test")
+    public static final class MyNameEndpoint {
+        
+    }
+    
+    @Endpoint(serviceName = "test")
+    public static final class MyLocalPartEndpoint {
+        
+    }
+
+}

Propchange: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/EndpointFinderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/LoggingPojoTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/LoggingPojoTest.java?rev=778756&r1=778755&r2=778756&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/LoggingPojoTest.java (original)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/LoggingPojoTest.java Tue May 26 15:38:25 2009
@@ -16,21 +16,32 @@
  */
 package org.apache.servicemix.bean;
 
-import javax.xml.namespace.QName;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.InOnly;
 import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.xml.namespace.QName;
 
-import org.apache.servicemix.jbi.container.JBIContainer;
-import org.apache.servicemix.jbi.jaxp.StringSource;
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.impl.SimpleLog;
 import org.apache.servicemix.bean.pojos.LoggingPojo;
 import org.apache.servicemix.client.ServiceMixClient;
 import org.apache.servicemix.client.ServiceMixClientFacade;
-import junit.framework.TestCase;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
 
 public class LoggingPojoTest extends TestCase {
 
     protected JBIContainer container;
     protected BeanComponent component;
+    protected List<String> messages;
 
     protected void setUp() throws Exception {
         container = new JBIContainer();
@@ -38,9 +49,19 @@
         container.init();
 
         component = new BeanComponent();
+        messages = new LinkedList<String>();
         BeanEndpoint loggingEndpoint = new BeanEndpoint();
-        loggingEndpoint.setBeanClassName(LoggingPojo.class.getName());
+        LoggingPojo pojo = new LoggingPojo();
+        pojo.setMaxMsgDisplaySize(35);
+        pojo.setLog(new SimpleLog("my-logger") {
+            @Override
+            protected void log(int type, Object message, Throwable t) {
+                messages.add(message.toString());
+            }
+        });
+        loggingEndpoint.setBean(pojo);
         loggingEndpoint.setService(new QName("logging"));
+        loggingEndpoint.setInterfaceName(new QName("logservice"));
         loggingEndpoint.setEndpoint("endpoint");
         component.addEndpoint(loggingEndpoint);
         container.activateComponent(component, "servicemix-bean");
@@ -55,19 +76,56 @@
     public void testInOnly() throws Exception {
         ServiceMixClient client = new ServiceMixClientFacade(component.getComponentContext());
         InOnly exchange = client.createInOnlyExchange();
-        exchange.setService(new QName("logging"));
-        exchange.getInMessage().setContent(new StringSource("<hello/>"));
-        exchange.getInMessage().setProperty("key", "value");
+        fillExchange(exchange);
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.DONE, exchange.getStatus());
+        
+        assertLog();
+    }
+    
+    public void testInOnlyWithWrongContent() throws Exception {
+        ServiceMixClient client = new ServiceMixClientFacade(component.getComponentContext());
+        InOnly exchange = client.createInOnlyExchange();
+        fillExchange(exchange);
+        exchange.getInMessage().setContent(new StringSource("This is not XML!"));
         client.sendSync(exchange);
+        assertEquals(ExchangeStatus.DONE, exchange.getStatus());
+        
+        assertLog();
+        assertTrue(messages.get(0).contains("Unable to display:"));
     }
 
     public void testInOut() throws Exception {
         ServiceMixClient client = new ServiceMixClientFacade(component.getComponentContext());
         InOut exchange = client.createInOutExchange();
-        exchange.setService(new QName("logging"));
-        exchange.getInMessage().setContent(new StringSource("<hello/>"));
-        exchange.getInMessage().setProperty("key", "value");
+        fillExchange(exchange);
         client.sendSync(exchange);
+        assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
         client.done(exchange);
+        
+        assertLog();
+    }
+    
+    private void fillExchange(MessageExchange exchange) throws MessagingException {
+        exchange.setService(new QName("logging"));
+        exchange.setInterfaceName(new QName("logservice"));
+        exchange.setOperation(new QName("log"));
+        exchange.setProperty("xml", new StringSource("<an>XML value</an>"));
+        exchange.getMessage("in").setContent(new StringSource("<hello>world</hello>"));
+        exchange.getMessage("in").setProperty("key", "value");
+        exchange.getMessage("in").setProperty("xml", new StringSource("<an>XML value</an>"));
+        exchange.getMessage("in").addAttachment("attachment", new DataHandler(new FileDataSource("src/test/resources/attachment.png")));
+    }
+    
+    private void assertLog() {
+        assertEquals(1, messages.size());
+        String message = messages.get(0);
+        assertTrue(message.contains("service: logging"));
+        assertTrue(message.contains("endpoint: endpoint"));
+        assertTrue(message.contains("interface: logservice"));
+        assertTrue(message.contains("operation: log"));
+        assertTrue(message.contains("key = value"));
+        assertTrue(message.contains("xml = <an>XML value</an>"));
+        assertTrue(message.contains("attachments:"));
     }
 }

Added: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/MethodInvocationFailedExceptionTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/MethodInvocationFailedExceptionTest.java?rev=778756&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/MethodInvocationFailedExceptionTest.java (added)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/MethodInvocationFailedExceptionTest.java Tue May 26 15:38:25 2009
@@ -0,0 +1,57 @@
+/*
+ * 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.servicemix.bean;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.xml.namespace.QName;
+
+/**
+ * Test cases for {@link MethodInvocationFailedException}
+ */
+public class MethodInvocationFailedExceptionTest extends AbstractBeanComponentTest {
+    
+    private static final QName SERVICE = new QName("urn:test", "service");
+    
+    public void testReceiveMethodInvocationFailedException() throws Exception {
+        BeanEndpoint endpoint = new BeanEndpoint();
+        MyPojo pojo = new MyPojo();
+        endpoint.setBean(pojo);
+        endpoint.setService(SERVICE);
+        endpoint.setEndpoint("endpoint");
+        component.addEndpoint(endpoint);
+        
+        InOnly exchange = client.createInOnlyExchange();
+        exchange.setService(SERVICE);
+        client.sendSync(exchange);
+        
+        assertEquals(ExchangeStatus.ERROR, exchange.getStatus());
+        assertTrue(exchange.getError() instanceof MethodInvocationFailedException);
+        
+        MethodInvocationFailedException mife = (MethodInvocationFailedException) exchange.getError();
+        assertEquals(endpoint, mife.getEndpoint());
+        assertEquals(pojo, mife.getPojo());
+        assertTrue(mife.getCause() instanceof IllegalArgumentException);
+    }
+     
+    public static final class MyPojo {
+        
+        public void handle() {
+            throw new IllegalArgumentException("Hey, how can I have an IllegalArgumentException when there is no argument?");
+        }
+    }
+}

Propchange: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/MethodInvocationFailedExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/ParameterAnnotationsTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/ParameterAnnotationsTest.java?rev=778756&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/ParameterAnnotationsTest.java (added)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/ParameterAnnotationsTest.java Tue May 26 15:38:25 2009
@@ -0,0 +1,116 @@
+/*
+ * 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.servicemix.bean;
+
+import java.util.Currency;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+
+import org.apache.servicemix.bean.beans.ParameterAnnotationsBean;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+
+/**
+ * Test cases for handling method parameter binding on method calls in servicemix-bean
+ */
+public class ParameterAnnotationsTest extends AbstractBeanComponentTest {
+    
+    private static final QName SERVICE = new QName("urn:test", "service");
+    
+    private Pojo pojo;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        
+        pojo = new Pojo();
+        BeanEndpoint endpoint = new BeanEndpoint();
+        endpoint.setBean(pojo);
+        endpoint.setService(SERVICE);
+        endpoint.setEndpoint("endpoint");
+        
+        component.addEndpoint(endpoint);
+    }
+    
+    public void testDefaultParameterMapping() throws Exception {
+        InOnly exchange = client.createInOnlyExchange();
+        exchange.setService(SERVICE);
+        exchange.setOperation(new QName("handle"));
+        
+        NormalizedMessage message = exchange.getInMessage();
+        Source content = new StringSource("<request xmlns='urn:test'><type>important!</type></request>");
+        message.setContent(content);
+        
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.DONE, exchange.getStatus());
+        
+        assertNotNullAndType(pojo.parameters[0], MessageExchange.class);
+        assertNotNullAndType(pojo.parameters[1], NormalizedMessage.class);
+        assertSame(message, pojo.parameters[1]);
+        assertNotNullAndType(pojo.parameters[2], Source.class);
+        assertSame(content, pojo.parameters[2]);
+    }
+    
+    public void testAnnotatedParameterMapping() throws Exception {
+        InOnly exchange = client.createInOnlyExchange();
+        exchange.setService(SERVICE);
+        exchange.setOperation(new QName("annotations"));
+        
+        Currency value = Currency.getInstance("EUR");
+        NormalizedMessage message = exchange.getInMessage();
+        message.setProperty("key", value);
+        Source content = new StringSource("<ns:request xmlns:ns=\"urn:test\"><ns:type>important!</ns:type></ns:request>");
+        message.setContent(content);
+        
+        client.sendSync(exchange);
+        assertEquals(ExchangeStatus.DONE, exchange.getStatus());
+        
+        assertNotNullAndType(pojo.parameters[0], Currency.class);
+        assertSame(value, pojo.parameters[0]);
+        assertNotNullAndType(pojo.parameters[1], String.class);
+    }
+
+    private void assertNotNullAndType(Object object, Class<?> type) {
+        assertNotNull(object);
+        assertTrue(type.isAssignableFrom(object.getClass()));
+    }
+    
+    public static final class Pojo extends ParameterAnnotationsBean {
+        
+        private Object[] parameters;
+        
+        @Override
+        public void handle(MessageExchange exchange, NormalizedMessage message, Source source) throws TransformerException {
+            saveParameters(exchange, message, source);
+        }
+        
+        @Override
+        public void annotations(@Property(name = "key") Object value, 
+                                @XPath(uri = "urn:test", prefix = "ns", xpath = "/request/type") String type) {
+            saveParameters(value, type);
+        }
+        
+        private void saveParameters(Object... parms) {
+            parameters = parms;
+        }
+    }
+}

Propchange: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/ParameterAnnotationsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/TransformBeanSupportSedaFlowTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/TransformBeanSupportSedaFlowTest.java?rev=778756&r1=778755&r2=778756&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/TransformBeanSupportSedaFlowTest.java (original)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/TransformBeanSupportSedaFlowTest.java Tue May 26 15:38:25 2009
@@ -16,11 +16,127 @@
  */
 package org.apache.servicemix.bean;
 
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.transaction.xa.XAException;
+import javax.xml.namespace.QName;
+
+import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
+import org.apache.servicemix.bean.TransformBeanSupportTest.ReturnErrorComponent;
+import org.apache.servicemix.bean.TransformBeanSupportTest.ReturnFaultComponent;
+import org.apache.servicemix.bean.support.TransformBeanSupport;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.tck.ReceiverComponent;
+import org.w3c.dom.Element;
+
 
 public class TransformBeanSupportSedaFlowTest extends TransformBeanSupportTest {
 
+    private GeronimoTransactionManager txmanager;
+
+    public void testInOutWithTx() throws Exception {
+        TransformBeanSupport transformer = new MyTransformer();
+        BeanEndpoint transformEndpoint = createBeanEndpoint(transformer);
+        component.addEndpoint(transformEndpoint);
+
+        txmanager.begin();
+        MessageExchange io = client.createInOutExchange();
+        io.setService(new QName("transform"));
+        io.getMessage("in").setContent(new StringSource("<hello/>"));
+        client.sendSync(io);
+        
+        assertEquals(ExchangeStatus.ACTIVE, io.getStatus());
+        Element e = new SourceTransformer().toDOMElement(io.getMessage("out"));
+        assertEquals("hello", e.getNodeName());
+        
+        client.done(io);
+        assertEquals(ExchangeStatus.DONE, io.getStatus());
+        txmanager.commit();
+        assertBeanEndpointRequestsMapEmpty(transformEndpoint);
+    }
+    
+    public void testInOnlyWithTx() throws Exception {
+        TransformBeanSupport transformer = createTransformer("receiver");
+        BeanEndpoint transformEndpoint = createBeanEndpoint(transformer);
+        component.addEndpoint(transformEndpoint);
+
+        ReceiverComponent receiver = new ReceiverComponent();
+        activateComponent(receiver, "receiver");
+
+        txmanager.begin();
+        MessageExchange io = client.createInOnlyExchange();
+        io.setService(new QName("transform"));
+        io.getMessage("in").setContent(new StringSource("<hello/>"));
+        client.sendSync(io);
+        
+        assertEquals(ExchangeStatus.DONE, io.getStatus());
+        txmanager.commit();
+        assertBeanEndpointRequestsMapEmpty(transformEndpoint);
+        
+        receiver.getMessageList().assertMessagesReceived(1);
+    }
+    
+    public void testInOnlyWithErrorTx() throws Exception {
+        TransformBeanSupport transformer = createTransformer("error");
+        BeanEndpoint transformEndpoint = createBeanEndpoint(transformer);
+        component.addEndpoint(transformEndpoint);
+
+        activateComponent(new ReturnErrorComponent(), "error");
+
+        txmanager.begin();
+        MessageExchange io = client.createInOnlyExchange();
+        io.setService(new QName("transform"));
+        io.getMessage("in").setContent(new StringSource("<hello/>"));
+        client.sendSync(io);
+        
+        assertEquals(ExchangeStatus.ERROR, io.getStatus());
+        txmanager.commit();
+        assertBeanEndpointRequestsMapEmpty(transformEndpoint);
+    }
+    
+    public void testRobustInOnlyWithFaultTx() throws Exception {
+        TransformBeanSupport transformer = createTransformer("fault");
+        BeanEndpoint transformEndpoint = createBeanEndpoint(transformer);
+        component.addEndpoint(transformEndpoint);
+
+        activateComponent(new ReturnFaultComponent() {
+            @Override
+            public void onMessageExchange(MessageExchange exchange) throws MessagingException {
+                if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+                    Fault fault = exchange.createFault();
+                    fault.setContent(new StringSource("<fault/>"));
+                    exchange.setFault(fault);
+                    sendSync(exchange);
+                }
+            }
+        }, "fault");
+
+        txmanager.begin();
+        MessageExchange io = client.createRobustInOnlyExchange();
+        io.setService(new QName("transform"));
+        io.getMessage("in").setContent(new StringSource("<hello/>"));
+        client.sendSync(io);
+
+        assertEquals(ExchangeStatus.ACTIVE, io.getStatus());
+        assertNotNull(io.getFault());
+        client.done(io);
+        txmanager.commit();
+        
+        assertBeanEndpointRequestsMapEmpty(transformEndpoint);
+    }
+    
     protected void configureContainer() {
-        container.setFlowName("seda");
+        try {
+            txmanager = new GeronimoTransactionManager();
+            container.setTransactionManager(txmanager);
+            container.setAutoEnlistInTransaction(true);
+            container.setFlowName("seda");
+        } catch (XAException e) {
+            fail("Unable to create TransactionMaanger: " + e.getMessage());
+        }
     }
     
 }

Modified: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/TransformBeanSupportTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/TransformBeanSupportTest.java?rev=778756&r1=778755&r2=778756&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/TransformBeanSupportTest.java (original)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/TransformBeanSupportTest.java Tue May 26 15:38:25 2009
@@ -29,6 +29,8 @@
 import javax.jbi.messaging.NormalizedMessage;
 import javax.xml.namespace.QName;
 
+import org.w3c.dom.Element;
+
 import org.apache.servicemix.bean.support.ExchangeTarget;
 import org.apache.servicemix.bean.support.TransformBeanSupport;
 import org.apache.servicemix.common.util.MessageUtil;
@@ -39,14 +41,10 @@
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.jbi.jaxp.StringSource;
 import org.apache.servicemix.jbi.listener.MessageExchangeListener;
+import org.apache.servicemix.jbi.transformer.CopyTransformer;
 import org.apache.servicemix.tck.ReceiverComponent;
-import org.w3c.dom.Element;
 
 public class TransformBeanSupportTest extends AbstractBeanComponentTest {
-
-    protected void configureContainer() {
-        container.setFlowName("st");
-    }
     
     public void testInOut() throws Exception {
         TransformBeanSupport transformer = new MyTransformer();
@@ -243,8 +241,28 @@
         client.fail(io, new Exception("I do not like faults"));
         assertBeanEndpointRequestsMapEmpty(transformEndpoint);
     }
+    
+    public void testSetCopyProperties() throws Exception {
+        TransformBeanSupport transformer = createTransformer("fault");
+        transformer.setCopyProperties(true);
+        assertTrue(transformer.isCopyProperties());
+        assertTrue(((CopyTransformer) transformer.getMessageTransformer()).isCopyProperties());
+        transformer.setCopyProperties(false);
+        assertFalse(transformer.isCopyProperties());
+        assertFalse(((CopyTransformer) transformer.getMessageTransformer()).isCopyProperties());
+    }
+    
+    public void testSetCopyAttachements() throws Exception {
+        TransformBeanSupport transformer = createTransformer("fault");
+        transformer.setCopyAttachments(true);
+        assertTrue(transformer.isCopyAttachments());
+        assertTrue(((CopyTransformer) transformer.getMessageTransformer()).isCopyAttachments());
+        transformer.setCopyAttachments(false);
+        assertFalse(transformer.isCopyAttachments());
+        assertFalse(((CopyTransformer) transformer.getMessageTransformer()).isCopyAttachments());
+    }
 
-    private MyTransformer createTransformer(String targetService) {
+    protected MyTransformer createTransformer(String targetService) {
         MyTransformer transformer = new MyTransformer();
         ExchangeTarget target = new ExchangeTarget();
         target.setService(new QName(targetService));
@@ -252,7 +270,7 @@
         return transformer;
     }
 
-    private BeanEndpoint createBeanEndpoint(TransformBeanSupport transformer) {
+    protected BeanEndpoint createBeanEndpoint(TransformBeanSupport transformer) {
         BeanEndpoint transformEndpoint = new BeanEndpoint();
         transformEndpoint.setBean(transformer);
         transformEndpoint.setService(new QName("transform"));

Added: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/beans/ParameterAnnotationsBean.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/beans/ParameterAnnotationsBean.java?rev=778756&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/beans/ParameterAnnotationsBean.java (added)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/beans/ParameterAnnotationsBean.java Tue May 26 15:38:25 2009
@@ -0,0 +1,57 @@
+/*
+ * 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.servicemix.bean.beans;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+
+import org.apache.servicemix.bean.Property;
+import org.apache.servicemix.bean.XPath;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+
+/**
+ * Example bean to show method parameter mapping with and without annotations
+ */
+public class ParameterAnnotationsBean {
+    
+    private final SourceTransformer transformer = new SourceTransformer();
+    
+    /**
+     * The handle method shows the types that will be automatically recognized
+     * without having to annotate the parameters 
+     * 
+     * @throws TransformerException 
+     */
+    public void handle(MessageExchange exchange,
+                       NormalizedMessage message, 
+                       Source source) throws TransformerException {
+        System.out.println(String.format("Received exchange %s with content %s", exchange.toString(), transformer.toString(source)));
+    }
+    
+    /**
+     * The annotations methods shows some of the options for annotating parameters
+     * 
+     * @param value uses the {@link Property} annotation to extract a message property
+     * @param type use the {@link XPath} annotation to extract data from the message content using XPath
+     */
+    public void annotations(@Property(name = "key") Object value,
+                            @XPath(prefix = "my", uri = "urn:test", xpath = "/my:message/@type") String type) {
+        System.out.println(String.format("Type %s has key value %s", type, value));
+    }
+}

Propchange: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/beans/ParameterAnnotationsBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/BeanInfoTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/BeanInfoTest.java?rev=778756&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/BeanInfoTest.java (added)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/BeanInfoTest.java Tue May 26 15:38:25 2009
@@ -0,0 +1,65 @@
+/*
+ * 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.servicemix.bean.support;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.aopalliance.intercept.MethodInvocation;
+import org.apache.servicemix.bean.Operation;
+import org.apache.servicemix.tck.mock.MockMessageExchange;
+
+/**
+ * Test cases for {@link BeanInfo}
+ */
+public class BeanInfoTest extends TestCase {
+    
+    public void testIntrospect() throws Exception {
+        BeanInfo info = new BeanInfo(Pojo.class, new DefaultMethodInvocationStrategy());
+        info.introspect();
+        
+        assertNotNull("Should find methods in superclass", 
+                      createInvocation(info, "doSomethingElse"));
+        assertNotNull("Should find methods based on the name in @Operation annotation", 
+                      createInvocation(info, "doSomethingMoreSophisticated"));
+        assertNull("Should not find method names that have @Operation information", 
+                   createInvocation(info, "doSomething"));
+    }
+
+    private MethodInvocation createInvocation(BeanInfo info, String name) throws MessagingException {
+        MessageExchange exchange = new MockMessageExchange();
+        exchange.setOperation(new QName(name));
+        return info.createInvocation(new Pojo(), exchange);
+    }
+
+    public static final class Pojo extends AbstractPojo {
+        @Operation(name = "doSomethingMoreSophisticated")
+        public void doSomething() {
+            //just an operation
+        }
+    }
+    
+    public abstract static class AbstractPojo {
+
+        public void doSomethingElse() {
+            //just another operation
+        }
+    }
+}

Propchange: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/BeanInfoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/BeanSupportTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/BeanSupportTest.java?rev=778756&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/BeanSupportTest.java (added)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/BeanSupportTest.java Tue May 26 15:38:25 2009
@@ -0,0 +1,119 @@
+/*
+ * 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.servicemix.bean.support;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.bean.AbstractBeanComponentTest;
+import org.apache.servicemix.bean.BeanEndpoint;
+import org.apache.servicemix.common.JbiConstants;
+import org.apache.servicemix.tck.mock.MockMessageExchange;
+
+/**
+ * Test cases for {@link BeanSupport}
+ */
+public class BeanSupportTest extends AbstractBeanComponentTest {
+    
+    private static final String CORRELATION_ID = "my-correlation-id"; 
+    private static final QName TARGET_SERVICE = new QName("urn:test", "new-service");
+    private static final QName TARGET_INTERFACE = new QName("urn:test", "new-interface");
+    private static final QName TARGET_OPERATION = new QName("urn:test", "new-operation");
+    
+    private BeanSupport support;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        
+        support = new Pojo();
+        BeanEndpoint endpoint = new BeanEndpoint();
+        endpoint.setService(new QName("urn:test", "service"));
+        endpoint.setEndpoint("endpoint");
+        endpoint.setBean(support);
+        
+        component.addEndpoint(endpoint);
+    }
+
+    public void testCreateInOnlyExchange() throws Exception {
+        MessageExchange answer = support.createInOnlyExchange(TARGET_SERVICE, null, null, null);
+        assertNotNull(answer);
+        assertEquals(TARGET_SERVICE, answer.getService());
+        
+        answer = support.createInOnlyExchange(null, TARGET_INTERFACE, TARGET_OPERATION, null);
+        assertNotNull(answer);
+        assertEquals(TARGET_INTERFACE, answer.getInterfaceName());
+        assertEquals(TARGET_OPERATION, answer.getOperation());
+    }
+    
+    public void testCreateInOutExchange() throws Exception {
+        MessageExchange answer = support.createInOutExchange(TARGET_SERVICE, null, null, null);
+        assertNotNull(answer);
+        assertEquals(TARGET_SERVICE, answer.getService());
+        
+        answer = support.createInOutExchange(null, TARGET_INTERFACE, TARGET_OPERATION, null);
+        assertNotNull(answer);
+        assertEquals(TARGET_INTERFACE, answer.getInterfaceName());
+        assertEquals(TARGET_OPERATION, answer.getOperation());
+    }
+    
+    public void testCreateInOnlyExchangeFromOriginalExchange() throws Exception {
+        MessageExchange answer = support.createInOnlyExchange(createMockExchange());
+        assertNotNull(answer);
+        assertEquals(CORRELATION_ID, answer.getProperty(JbiConstants.CORRELATION_ID));
+    }
+    
+    public void testCreateInOnlyExchangeFromOriginalExchangeWithCorrelationId() throws Exception {
+        MessageExchange exchange = createMockExchange();
+        exchange.setProperty(JbiConstants.CORRELATION_ID, "my-other-correlation-id");
+        MessageExchange answer = support.createInOnlyExchange(exchange);
+        assertNotNull(answer);
+        assertEquals("my-other-correlation-id", answer.getProperty(JbiConstants.CORRELATION_ID));
+    }
+    
+    public void testCreateInOutExchangeFromOriginalExchange() throws Exception {
+        MessageExchange answer = support.createInOutExchange(createMockExchange());
+        assertNotNull(answer);
+        assertEquals(CORRELATION_ID, answer.getProperty(JbiConstants.CORRELATION_ID));
+    }
+    
+    public void testCreateRobustInOnlyExchangeFromOriginalExchange() throws Exception {
+        MessageExchange answer = support.createRobustInOnlyExchange(createMockExchange());
+        assertNotNull(answer);
+        assertEquals(CORRELATION_ID, answer.getProperty(JbiConstants.CORRELATION_ID));
+    }
+    
+    public void testCreateInOptionalOutExchangeFromOriginalExchange() throws Exception {
+        MessageExchange answer = support.createInOptionalOutExchange(createMockExchange());
+        assertNotNull(answer);
+        assertEquals(CORRELATION_ID, answer.getProperty(JbiConstants.CORRELATION_ID));
+    }
+    
+    private MessageExchange createMockExchange() {
+        return new MockMessageExchange() {
+            @Override
+            public String getExchangeId() {
+                return CORRELATION_ID;
+            }
+        };
+    }
+
+    private static final class Pojo extends BeanSupport {
+        
+    }
+
+}

Propchange: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/BeanSupportTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/DefaultMethodInvocationStrategyTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/DefaultMethodInvocationStrategyTest.java?rev=778756&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/DefaultMethodInvocationStrategyTest.java (added)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/DefaultMethodInvocationStrategyTest.java Tue May 26 15:38:25 2009
@@ -0,0 +1,54 @@
+/*
+ * 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.servicemix.bean.support;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.Source;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.tck.mock.MockMessageExchange;
+
+/**
+ * Test cases for {@link DefaultMethodInvocationStrategy}
+ */
+public class DefaultMethodInvocationStrategyTest extends TestCase {
+    
+    private DefaultMethodInvocationStrategy strategy;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        strategy = new DefaultMethodInvocationStrategy();
+        strategy.loadDefaultRegistry();
+    }
+    
+    public void testMessageExchangeExpression() throws Exception {
+        MessageExchange exchange = new MockMessageExchange();
+        NormalizedMessage message = exchange.createMessage();
+        Source source = new StringSource("<my><content type='test'/></my>");
+        message.setContent(source);
+        exchange.setMessage(message, "in");
+        
+        assertSame(exchange, strategy.getDefaultParameterTypeExpression(MessageExchange.class).evaluate(exchange, message));
+        assertSame(message, strategy.getDefaultParameterTypeExpression(NormalizedMessage.class).evaluate(exchange, message));
+        assertSame(source, strategy.getDefaultParameterTypeExpression(Source.class).evaluate(exchange, message));
+    }
+
+}

Propchange: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/DefaultMethodInvocationStrategyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ExchangeTargetTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ExchangeTargetTest.java?rev=778756&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ExchangeTargetTest.java (added)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ExchangeTargetTest.java Tue May 26 15:38:25 2009
@@ -0,0 +1,99 @@
+/*
+ * 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.servicemix.bean.support;
+
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.tck.mock.MockMessageExchange;
+import org.easymock.EasyMock;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+/**
+ * Test cases for {@link ExchangeTarget}
+ */
+public class ExchangeTargetTest extends TestCase {
+    
+    private static final String ENDPOINT = "endpoint";
+    private static final QName INTERFACE = new QName("urn:test", "interface");
+    private static final QName OPERATION = new QName("urn:test", "operation");
+    private static final QName SERVICE = new QName("urn:test", "service");
+    
+    private ExchangeTarget target;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        target = new ExchangeTarget();
+    }
+    
+    public void testMessagingExceptionWhenNoTargetSet() throws Exception {
+        try {
+            target.afterPropertiesSet();
+            fail("Should have thrown a MessagingException");
+        } catch (MessagingException e) {
+            //this is OK
+        }
+        try {
+            target.configureTarget(null, null);
+            fail("Should have thrown a MessagingException");
+        } catch (MessagingException e) {
+            //this is OK
+        }
+    }
+    
+    public void testInterfaceAndOperation() throws Exception {
+        target.setInterface(INTERFACE);
+        target.setOperation(OPERATION);
+        
+        MessageExchange exchange = new MockMessageExchange();
+        target.configureTarget(exchange, null);
+        assertEquals(INTERFACE, exchange.getInterfaceName());
+        assertEquals(OPERATION, exchange.getOperation());
+    }
+    
+    public void testServiceAndEndpoint() throws Exception {
+        target.setService(SERVICE);
+        target.setEndpoint(ENDPOINT);
+        
+        ComponentContext context = EasyMock.createMock(ComponentContext.class);
+        ServiceEndpoint endpoint = EasyMock.createMock(ServiceEndpoint.class);
+        expect(context.getEndpoint(SERVICE, ENDPOINT)).andReturn(endpoint);
+        replay(context);
+                
+        MessageExchange exchange = new MockMessageExchange();
+        target.configureTarget(exchange, context);
+        assertEquals(SERVICE, exchange.getService());
+        assertEquals(endpoint, exchange.getEndpoint());
+    }
+    
+    public void testUri() throws Exception {
+        target.setUri("interface:urn:test:interface");
+        target.afterPropertiesSet();
+
+        MessageExchange exchange = new MockMessageExchange();
+        target.configureTarget(exchange, EasyMock.createMock(ComponentContext.class));
+        assertEquals(INTERFACE, exchange.getInterfaceName());
+    }
+}

Propchange: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ExchangeTargetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message