You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2009/05/22 10:42:05 UTC

svn commit: r777431 - in /servicemix/components/engines/servicemix-camel/trunk: ./ src/main/java/org/apache/servicemix/camel/ src/main/java/org/apache/servicemix/camel/osgi/ src/test/java/org/apache/servicemix/camel/ src/test/java/org/apache/servicemix...

Author: gertv
Date: Fri May 22 08:42:04 2009
New Revision: 777431

URL: http://svn.apache.org/viewvc?rev=777431&view=rev
Log:
SMXCOMP-532: Improve test coverage for servicemix-camel

Added:
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/CamelConsumerEndpointTest.java   (with props)
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiComponentTest.java   (with props)
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOptionalOutCamelTest.java   (with props)
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiMessageTest.java   (with props)
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiOperationCamelTest.java   (with props)
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/osgi/
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/osgi/OsgiJbiComponentTest.java   (with props)
Modified:
    servicemix/components/engines/servicemix-camel/trunk/pom.xml
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiBinding.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiMessage.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponent.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiJbiComponent.java
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiCamelAttachmentTest.java
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiExchangeTest.java
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyAsyncCamelTest.java
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelErrorHandlingTest.java
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java

Modified: servicemix/components/engines/servicemix-camel/trunk/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/pom.xml?rev=777431&r1=777430&r2=777431&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/pom.xml (original)
+++ servicemix/components/engines/servicemix-camel/trunk/pom.xml Fri May 22 08:42:04 2009
@@ -156,6 +156,11 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.easymock</groupId>
+      <artifactId>easymock</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>org.apache.servicemix</groupId>
       <artifactId>servicemix-core</artifactId>
       <version>${servicemix-version}</version>

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java?rev=777431&r1=777430&r2=777431&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java Fri May 22 08:42:04 2009
@@ -21,8 +21,6 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
 
 import javax.jbi.servicedesc.ServiceEndpoint;
 
@@ -43,11 +41,8 @@
 
     protected CamelSpringDeployer deployer;
 
-    private ScheduledExecutorService executorService;
-
     private List<JbiComponent> jbiComponents = new ArrayList<JbiComponent>();
 
-
     /*
      * (non-Javadoc)
      *
@@ -153,13 +148,6 @@
         return result;
     }
 
-    public ScheduledExecutorService getExecutorService() {
-        if (executorService == null) {
-            executorService = new ScheduledThreadPoolExecutor(5);
-        }
-        return executorService;
-    }
-
     /**
      * Activating a JBI endpoint created by a camel consumer.
      *

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiBinding.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiBinding.java?rev=777431&r1=777430&r2=777431&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiBinding.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiBinding.java Fri May 22 08:42:04 2009
@@ -156,10 +156,14 @@
 
     protected Source getJbiInContent(Exchange camelExchange) {
         // TODO this should be more smart
-        Source content = camelExchange.getIn().getBody(Source.class);
-        if (content == null && camelExchange.getIn().getBody() != null) {
-            LOG.warn("'in' message content of type " + camelExchange.getIn().getBody().getClass()
-                     + " could not be converted to Source and will be dropped");
+        Source content = null;
+        try {
+            content = camelExchange.getIn().getBody(Source.class);
+        } catch (NoTypeConversionAvailableException e) {
+            if (camelExchange.getIn().getBody() != null) {
+                LOG.warn("'in' message content of type " + camelExchange.getIn().getBody().getClass()
+                         + " could not be converted to Source and will be dropped");
+            }
         }
         return content;
     }

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java?rev=777431&r1=777430&r2=777431&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java Fri May 22 08:42:04 2009
@@ -38,11 +38,11 @@
     public JbiComponent(CamelComponent component) {
         setCamelJbiComponent(component);
     }
-
+    
     protected JbiComponent() {
+        super();
     }
 
-
     public CamelContext getCamelContext() {
         return camelContext;
     }

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java?rev=777431&r1=777430&r2=777431&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java Fri May 22 08:42:04 2009
@@ -79,6 +79,7 @@
             jbiComponent.getCamelJbiComponent().addEndpoint(consumer);
             super.start();
         }
+        
         @Override
         public void stop() throws Exception {
             if (isStopped()) {
@@ -97,6 +98,13 @@
         public boolean process(Exchange exchange, AsyncCallback asyncCallback) {
             return consumer.process(exchange, asyncCallback);
         }
+        
+        /*
+         * Access the underlying JBI Consumer endpoint
+         */
+        protected CamelConsumerEndpoint getCamelConsumerEndpoint() {
+            return consumer;
+        }
     }
 
     private void parseUri(String uri) {

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiMessage.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiMessage.java?rev=777431&r1=777430&r2=777431&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiMessage.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiMessage.java Fri May 22 08:42:04 2009
@@ -110,9 +110,8 @@
             } catch (MessagingException e) {
                 throw new JbiException(e);
             }
-        } else {
-            super.addAttachment(id, content);
         }
+        super.addAttachment(id, content);
     }
 
     @Override

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponent.java?rev=777431&r1=777430&r2=777431&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponent.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiCamelJbiComponent.java Fri May 22 08:42:04 2009
@@ -19,7 +19,6 @@
 import java.util.List;
 import java.util.Collections;
 import java.util.ArrayList;
-import java.util.Map;
 import java.io.File;
 import java.net.URL;
 
@@ -27,20 +26,16 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.camel.CamelJbiComponent;
 import org.apache.servicemix.camel.CamelSpringDeployer;
-import org.apache.servicemix.camel.JbiBinding;
 import org.apache.servicemix.common.BaseServiceUnitManager;
 import org.apache.servicemix.common.Deployer;
 import org.apache.servicemix.common.ServiceMixComponent;
 import org.apache.servicemix.common.xbean.ClassLoaderXmlPreprocessor;
-import org.apache.servicemix.common.xbean.ParentBeanFactoryPostProcessor;
 import org.apache.xbean.spring.context.SpringApplicationContext;
 import org.apache.xbean.classloader.JarFileClassLoader;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
 import org.springframework.beans.factory.config.BeanPostProcessor;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
-import org.springframework.core.io.FileSystemResource;
 import org.springframework.osgi.context.BundleContextAware;
 import org.springframework.osgi.util.BundleDelegatingClassLoader;
 import org.osgi.framework.BundleContext;
@@ -49,7 +44,7 @@
 /**
  * When deploying a JBI packaged SU to camel component, camel-spring and camel-osgi 
  * can not be found by Spring/XBean, thus leading to an exception about the spring 
- * and osgi namespaces not being found.  We need to hack the clasloader for SUs to 
+ * and osgi namespaces not being found.  We need to hack the classloader for SUs to 
  * force a reference to camel-spring and camel-osgi in the SU classloader parents.
  *
  * We also need to inject the bundleContext into the CamelContextFactoryBean to 
@@ -57,7 +52,8 @@
  * with OSGi ResolverUtils
  */
 public class OsgiCamelJbiComponent extends CamelJbiComponent implements BundleContextAware {
-	private static final Log LOG = LogFactory.getLog(OsgiCamelJbiComponent.class);
+    
+    private static final Log LOG = LogFactory.getLog(OsgiCamelJbiComponent.class);
     private BundleContext bundleContext;
 
     public void setBundleContext(BundleContext bundleContext) {
@@ -65,7 +61,7 @@
     }
     
     public BundleContext getBundleContext() {
-    	return bundleContext;
+        return bundleContext;
     }
 
     public BaseServiceUnitManager createServiceUnitManager() {
@@ -74,10 +70,9 @@
     }
 
     public class OsgiCamelSpringDeployer extends CamelSpringDeployer {
-        private OsgiCamelJbiComponent osgiCamelJbiComponent;
-    	public OsgiCamelSpringDeployer(OsgiCamelJbiComponent component) {
+        
+        public OsgiCamelSpringDeployer(OsgiCamelJbiComponent component) {
             super(component);
-            osgiCamelJbiComponent = component;
         }
         
         protected List getXmlPreProcessors(String serviceUnitRootPath) {
@@ -98,33 +93,30 @@
         }
     }
     
-    private class OsgiBundleContextPostprocessor implements BeanFactoryPostProcessor {    	
-    		
-		public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
-				throws BeansException {
-			beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
-				
-				public Object postProcessAfterInitialization(Object bean,
-						String beanName) throws BeansException {
-					// do nothing here
-					return bean;
-				}
-				
-				public Object postProcessBeforeInitialization(Object bean,
-						String beanName) throws BeansException {
-					 if (bean instanceof BundleContextAware) {
-						 BundleContextAware bundleContextAware = (BundleContextAware)bean;
-				         if (bundleContext == null) {
-				             LOG.warn("No bundle defined yet so cannot inject into: " + bean);
-				         } else {
-				             bundleContextAware.setBundleContext(bundleContext);
-				         }
-				     }			         
-				     return bean;
-				}
-			});			
-		}
-    	
+    private class OsgiBundleContextPostprocessor implements BeanFactoryPostProcessor {
+
+        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
+            beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
+
+                public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
+                    // do nothing here
+                    return bean;
+                }
+
+                public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
+                    if (bean instanceof BundleContextAware) {
+                        BundleContextAware bundleContextAware = (BundleContextAware)bean;
+                        if (bundleContext == null) {
+                            LOG.warn("No bundle defined yet so cannot inject into: " + bean);
+                        } else {
+                            bundleContextAware.setBundleContext(bundleContext);
+                        }
+                    }
+                    return bean;
+                }
+            });
+        }
+
     }
 
     public class OsgiClassLoaderXmlPreprocessor extends ClassLoaderXmlPreprocessor {
@@ -137,7 +129,7 @@
             parents.add(super.getParentClassLoader(applicationContext));
             for (Bundle bundle : bundleContext.getBundles()) {
                 try {
-                	String symbolicName = bundle.getSymbolicName();
+                    String symbolicName = bundle.getSymbolicName();
                     if (symbolicName.contains("camel-spring") || symbolicName.contains("camel-osgi")) {
                         parents.add(BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle));
                     }
@@ -150,5 +142,4 @@
                                           parents.toArray(new ClassLoader[parents.size()]));
         }
     }
-
 }

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiJbiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiJbiComponent.java?rev=777431&r1=777430&r2=777431&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiJbiComponent.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/osgi/OsgiJbiComponent.java Fri May 22 08:42:04 2009
@@ -25,16 +25,13 @@
 import org.osgi.framework.ServiceReference;
 
 /**
+ * OSGi-specific servicemix-camel {@link JbiComponent} implementation that looks up the {@link CamelComponent} in the OSGi Service Registry
  */
 public class OsgiJbiComponent extends JbiComponent implements BundleContextAware, InitializingBean, DisposableBean {
 
     private BundleContext bundleContext;
     private ServiceReference reference;
 
-    public BundleContext getBundleContext() {
-        return bundleContext;
-    }
-
     public void setBundleContext(BundleContext bundleContext) {
         this.bundleContext = bundleContext;
     }

Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/CamelConsumerEndpointTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/CamelConsumerEndpointTest.java?rev=777431&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/CamelConsumerEndpointTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/CamelConsumerEndpointTest.java Fri May 22 08:42:04 2009
@@ -0,0 +1,71 @@
+/*
+ * 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.camel;
+
+import java.util.List;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.tck.mock.MockMessageExchange;
+
+/**
+ * Test cases for {@link CamelConsumerEndpoint} 
+ */
+public class CamelConsumerEndpointTest extends JbiTestSupport {
+    
+    public void testInvalidMessageExchangeDoesNotThrowException() throws Exception {
+        String endpointName = 
+            jbiContainer.getRegistry().getExternalEndpointsForService(CamelConsumerEndpoint.SERVICE_NAME)[0].getEndpointName();
+        CamelConsumerEndpoint endpoint = 
+            (CamelConsumerEndpoint) component.getRegistry().getEndpoint(CamelConsumerEndpoint.SERVICE_NAME + ":" + endpointName);
+        
+        try {
+            // now, let's shamelessly process a completely fake MessageExchange...
+            endpoint.process(new MockMessageExchange() {
+                @Override
+                public String getExchangeId() {
+                    return "a-fake-exchange-id";
+                }
+            });
+        } catch (Exception e) {
+            // ... and still expect the endpoint to behave properly
+            fail("Should not throw " + e);
+        }
+    }
+
+    @Override
+    protected void appendJbiActivationSpecs(List<ActivationSpec> activationSpecList) {
+        // no additional JBI activation specs required
+    }
+    
+    @Override
+    protected void configureContainer(JBIContainer container) throws Exception {
+        super.configureContainer(container);
+    }
+
+    @Override
+    protected RouteBuilder createRoutes() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:a").to("jbi:endpoint:urn:test:service:endpoint");
+                from("jbi:endpoint:urn:test:service:endpoint").to("log:info");
+            }            
+        };
+    }
+}

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

Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiCamelAttachmentTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiCamelAttachmentTest.java?rev=777431&r1=777430&r2=777431&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiCamelAttachmentTest.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiCamelAttachmentTest.java Fri May 22 08:42:04 2009
@@ -21,12 +21,17 @@
 
 import javax.activation.DataHandler;
 import javax.activation.FileDataSource;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOut;
+import javax.xml.namespace.QName;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.DefaultExchange;
 import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.jbi.jaxp.StringSource;
 
 /**
  * Tests for attachment handling by servicemix-camel JBI component 
@@ -56,6 +61,18 @@
             fail("Expected a FileDataSource, but received a " + received.getIn().getAttachment(ATTACHMENT_ID).getDataSource().getClass());
         }
     }
+    
+    public void testGetAttachmentsFromCamelProcessor() throws Exception {
+        InOut inout = getServicemixClient().createInOutExchange();
+        inout.setService(new QName("urn:test", "inout-service"));
+        inout.getInMessage().setContent(new StringSource("<request>Could I get an attachment, Mr. Camel?</request>"));
+        getServicemixClient().sendSync(inout);
+        assertEquals(ExchangeStatus.ACTIVE, inout.getStatus());
+        inout.setStatus(ExchangeStatus.DONE);
+        getServicemixClient().done(inout);
+        assertNotNull(inout.getOutMessage().getAttachment(ATTACHMENT_ID));
+        Thread.sleep(500);
+    }
 
     @Override
     protected void appendJbiActivationSpecs(List<ActivationSpec> activationSpecList) {
@@ -67,10 +84,21 @@
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                //from Camel to JBI...
+                // from Camel to JBI...
                 from("direct:a").to("jbi:service:urn:test:service");
-                //...and the other way around
+                // ...and the other way around
                 from("jbi:service:urn:test:service").to("mock:a");
+                
+                // and now with a Camel processor to add the attachment
+                from("jbi:service:urn:test:inout-service").process(new Processor() {
+
+                    @Override
+                    public void process(Exchange exchange) throws Exception {
+                        exchange.getOut().setBody(exchange.getIn().getBody());
+                        exchange.getOut().addAttachment(ATTACHMENT_ID, new DataHandler(new FileDataSource(TEST_FILE)));
+                    }
+                    
+                });
             }
         };
     }

Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiComponentTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiComponentTest.java?rev=777431&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiComponentTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiComponentTest.java Fri May 22 08:42:04 2009
@@ -0,0 +1,59 @@
+/*
+ * 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.camel;
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for {@link JbiComponent}
+ */
+public class JbiComponentTest extends TestCase {
+    
+    private final static String IN_OUT = "http://www.w3.org/ns/wsdl/in-out";
+    
+    public void testGetUriWithMep() throws Exception {
+        JbiComponent component = createJbiComponent();
+        JbiEndpoint endpoint = (JbiEndpoint) component.createEndpoint("jbi:endpoint:urn:test:service?mep=in-out");
+        assertEquals(IN_OUT, endpoint.getMep());        
+    }
+    
+    public void testNullWhenNoJbiUri() throws Exception {
+        assertNull(createJbiComponent().createEndpoint("somethingelse:service:urn:test"));
+    }
+    
+    public void testExceptionWhenIllegalUri() {
+        // expecting an exception when uri doesn't have name, endpoint or service after the jbi:
+        assertIllegalArgumentExceptionOnInvalidUri("jbi:illegal:urn:test:service");
+        // expecting an exception when using the wrong separators
+        assertIllegalArgumentExceptionOnInvalidUri("jbi:endpoint:urn:test/service");
+    }
+
+    private void assertIllegalArgumentExceptionOnInvalidUri(String uri) {
+        JbiComponent component = createJbiComponent();
+        JbiEndpoint endpoint = (JbiEndpoint) component.createEndpoint(uri);
+        try {
+            component.createJbiEndpointFromCamel(endpoint);
+            fail("Should have thrown an IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // ok, at least we got the exception we expected
+        }
+    }
+
+    private JbiComponent createJbiComponent() {
+        return new JbiComponent(new CamelJbiComponent());
+    }
+}

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

Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiExchangeTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiExchangeTest.java?rev=777431&r1=777430&r2=777431&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiExchangeTest.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiExchangeTest.java Fri May 22 08:42:04 2009
@@ -18,14 +18,18 @@
 
 import java.net.URI;
 
+import javax.jbi.messaging.Fault;
 import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
 
 import junit.framework.TestCase;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.servicemix.jbi.messaging.MessageExchangeSupport;
+import org.apache.servicemix.jbi.helper.MessageExchangePattern;
+import org.apache.servicemix.jbi.messaging.FaultImpl;
 import org.apache.servicemix.tck.mock.MockMessageExchange;
+import org.apache.servicemix.tck.mock.MockNormalizedMessage;
 
 /**
  * Test case for {@link JbiExchange}
@@ -66,11 +70,34 @@
         assertEquals(VALUE, camelExchange.getProperty(KEY));
     }
     
+    /*
+     * Test access to the underlying NormalizedMessages
+     */
+    public void testAccessTheNormalizedMessages() throws Exception {
+        NormalizedMessage in = new MockNormalizedMessage();
+        NormalizedMessage out = new MockNormalizedMessage();
+        Fault fault = new FaultImpl();
+        MessageExchange mock = createMockExchange();
+        mock.setMessage(in, "in");
+        mock.setMessage(out, "out");
+        mock.setFault(fault);
+        JbiExchange exchange = new JbiExchange(new DefaultCamelContext(), new JbiBinding(), mock);
+        assertSame(in, exchange.getInMessage());
+        assertSame(out, exchange.getOutMessage());
+        assertSame(fault, exchange.getFaultMessage());
+    }
+    
     private MessageExchange createMockExchange() {
         return new MockMessageExchange() {
             @Override
             public URI getPattern() {
-                return MessageExchangeSupport.IN_OUT;
+                return MessageExchangePattern.IN_OUT;
+            }
+            public NormalizedMessage getMessage(String name) {
+                if ("fault".equalsIgnoreCase(name)) {
+                    return getFault();
+                }
+                return super.getMessage(name);
             }
         };
     }

Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyAsyncCamelTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyAsyncCamelTest.java?rev=777431&r1=777430&r2=777431&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyAsyncCamelTest.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyAsyncCamelTest.java Fri May 22 08:42:04 2009
@@ -22,6 +22,8 @@
 import javax.jbi.messaging.InOnly;
 import javax.xml.namespace.QName;
 
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.converter.jaxp.StringSource;
@@ -37,6 +39,9 @@
     private static final String MESSAGE = "<just><a>test</a></just>";
 
     public void testInOnlyExchangeThroughAsyncRoute() throws Exception {
+        // first remove the ExchangeListener -- it will not be notified of the undeliverable MessageExchange
+        jbiContainer.removeListener(exchangeCompletedListener);
+        
         MockEndpoint done = getMockEndpoint("mock:done");
         done.expectedBodiesReceived(MESSAGE);
         
@@ -72,3 +77,4 @@
         };
     }
 }
+

Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOptionalOutCamelTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOptionalOutCamelTest.java?rev=777431&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOptionalOutCamelTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOptionalOutCamelTest.java Fri May 22 08:42:04 2009
@@ -0,0 +1,111 @@
+/*
+ * 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.camel;
+
+import java.util.List;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOptionalOut;
+import javax.xml.namespace.QName;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.jaxp.StringSource;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+
+/**
+ * Tests on handling JBI InOnly exchanges by Camel
+ */
+public class JbiInOptionalOutCamelTest extends JbiTestSupport {
+    
+    public void testInOptionalOutFromCamelEndpoint() throws Exception {
+        MockEndpoint inonly = getMockEndpoint("mock:in-optional-out");
+        inonly.expectedMessageCount(1);
+        
+        client.sendBody("direct:in-optional-out", new StringSource("<request>Does this MEP confuse you?</request>"));
+        
+        inonly.assertIsSatisfied();
+    }
+    
+    public void testInOptionalOutFromJbiWithDone() throws Exception {
+        MockEndpoint inonly = getMockEndpoint("mock:in-optional-out");
+        inonly.expectedMessageCount(1);
+        
+        InOptionalOut exchange = getServicemixClient().createInOptionalOutExchange();
+        exchange.setService(new QName("urn:test", "in-optional-out"));
+        exchange.getInMessage().setContent(new StringSource("<request>Does this MEP confuse you?</request>"));
+        getServicemixClient().sendSync(exchange);
+        assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
+        inonly.assertIsSatisfied();
+        
+        // let's send the done and wait for a moment until it's handled
+        getServicemixClient().done(exchange);
+        Thread.sleep(500);
+    }
+    
+    public void testInOptionalOutFromJbiWithFault() throws Exception {
+        MockEndpoint inonly = getMockEndpoint("mock:in-optional-out");
+        inonly.expectedMessageCount(1);
+        
+        InOptionalOut exchange = getServicemixClient().createInOptionalOutExchange();
+        exchange.setService(new QName("urn:test", "in-optional-out"));
+        exchange.getInMessage().setContent(new StringSource("<request>Does this MEP confuse you?</request>"));
+        getServicemixClient().sendSync(exchange);
+        assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
+        inonly.assertIsSatisfied();
+        
+        // let's send back a fault to the Camel provider endpoint
+        exchange.setFault(exchange.createFault());
+        exchange.getFault().setContent(new StringSource("<response>Oh no, things are going astray!</response>"));
+        getServicemixClient().sendSync(exchange);
+        assertEquals(ExchangeStatus.DONE, exchange.getStatus());
+    }
+    
+    public void testInOptionalOutFromJbiWithError() throws Exception {
+        MockEndpoint inonly = getMockEndpoint("mock:in-optional-out");
+        inonly.expectedMessageCount(1);
+        
+        InOptionalOut exchange = getServicemixClient().createInOptionalOutExchange();
+        exchange.setService(new QName("urn:test", "in-optional-out"));
+        exchange.getInMessage().setContent(new StringSource("<request>Does this MEP confuse you?</request>"));
+        getServicemixClient().sendSync(exchange);
+        assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
+        inonly.assertIsSatisfied();
+        
+        // let's back an error to the Camel provider endpoint and wait for a moment until it's handled
+        exchange.setError(new JbiException("Oh no, things are going astray!"));
+        getServicemixClient().send(exchange);
+        Thread.sleep(500);
+    }
+
+    
+    @Override
+    protected void appendJbiActivationSpecs(List<ActivationSpec> activationSpecList) {
+        // no additional activation specs required
+    }
+
+    @Override
+    protected RouteBuilder createRoutes() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:in-optional-out").to("jbi:service:urn:test:in-optional-out?mep=in-optional-out");
+                from("jbi:service:urn:test:in-optional-out").to("mock:in-optional-out");
+            }
+        };
+    }
+}

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

Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelErrorHandlingTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelErrorHandlingTest.java?rev=777431&r1=777430&r2=777431&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelErrorHandlingTest.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelErrorHandlingTest.java Fri May 22 08:42:04 2009
@@ -50,6 +50,9 @@
         client.done(exchange);
 
         errors.assertIsSatisfied();
+        
+        // let's wait a moment to make sure that the last DONE MessageExchange is handled
+        Thread.sleep(500);
     }
 
     public void testInOutWithHandleFault() throws Exception {
@@ -66,6 +69,9 @@
         client.done(exchange);
 
         errors.assertIsSatisfied();
+
+        // let's wait a moment to make sure that the last DONE MessageExchange is handled
+        Thread.sleep(500);
     }
 
     public void testInOutWithErrorNotHandled() throws Exception {
@@ -115,6 +121,9 @@
         receiverComponent.getMessageList().assertMessagesReceived(1);
 
         errors.assertIsSatisfied();
+        
+        // let's wait a moment to make sure that the last DONE MessageExchange is handled
+        Thread.sleep(500);
     }
 
     @Override

Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiMessageTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiMessageTest.java?rev=777431&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiMessageTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiMessageTest.java Fri May 22 08:42:04 2009
@@ -0,0 +1,61 @@
+/*
+ * 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.camel;
+
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+import javax.jbi.messaging.NormalizedMessage;
+
+import junit.framework.TestCase;
+
+import org.apache.camel.Message;
+import org.apache.servicemix.tck.mock.MockNormalizedMessage;
+
+/**
+ * Test cases for {@link JbiMessage}
+ */
+public class JbiMessageTest extends TestCase {
+    
+    private static final String ATTACHMENT_ID = "attachment.png";
+    private static final String ANOTHER_ATTACHMENT_ID = "another_attachment.png"; 
+    private static final DataHandler ATTACHMENT = new DataHandler(new FileDataSource("attachment.png"));
+    private static final DataHandler ANOTHER_ATTACHMENT = new DataHandler(new FileDataSource("attachment.png"));
+    
+    public void testAttachmentsWithNormalizedMessage() throws Exception {
+        NormalizedMessage jbiMessage = new MockNormalizedMessage();
+        jbiMessage.addAttachment(ATTACHMENT_ID, ATTACHMENT);
+        
+        // make sure the Camel Message also has the attachment
+        JbiMessage camelMessage = new JbiMessage(jbiMessage);
+        assertSame(ATTACHMENT, camelMessage.getAttachment(ATTACHMENT_ID));
+        
+        // and ensure that attachments are propagated back to the underlying NormalizedMessage
+        camelMessage.addAttachment(ANOTHER_ATTACHMENT_ID, ANOTHER_ATTACHMENT);
+        assertSame(ANOTHER_ATTACHMENT, jbiMessage.getAttachment(ANOTHER_ATTACHMENT_ID));
+        
+        // and they should also be on the Camel Message itself
+        camelMessage.setNormalizedMessage(null);
+        assertSame(ANOTHER_ATTACHMENT, camelMessage.getAttachment(ANOTHER_ATTACHMENT_ID));
+    }
+    
+    public void testCopyMessage() throws Exception {
+        JbiMessage message = new JbiMessage();
+        Message copy = message.copy();
+        assertTrue(copy instanceof JbiMessage);
+    }
+
+}

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

Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiOperationCamelTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiOperationCamelTest.java?rev=777431&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiOperationCamelTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiOperationCamelTest.java Fri May 22 08:42:04 2009
@@ -0,0 +1,90 @@
+/*
+ * 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.camel;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.jaxp.StringSource;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+
+/**
+ * Tests on handling JBI InOnly exchanges by Camel
+ */
+public class JbiOperationCamelTest extends JbiTestSupport {
+    
+    private static final String OPERATION = "doit";
+    
+    public void testInOnlySetOperationOnCamelEndpoint() throws Exception {
+        MockEndpoint inonly = getMockEndpoint("mock:in-only");
+        inonly.expectedMessageCount(1);
+        
+        // either set the operation on the Camel JBI Endpoint
+        client.sendBody("direct:in-only", new StringSource("<request>How about adding an operation?</request>"));
+        
+        inonly.assertIsSatisfied();
+        Exchange exchange = inonly.getExchanges().get(0);
+        assertEquals(OPERATION, exchange.getProperty("jbi.operation"));
+    }
+    
+    public void testInOnlySetOperationOnCamelExchange() throws Exception {
+        MockEndpoint inonly = getMockEndpoint("mock:in-only");
+        inonly.expectedMessageCount(1);
+        
+        // this time, we set the target operation on the Camel Exchange
+        client.send("direct:in-only-noop", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.setProperty("jbi.operation", OPERATION);
+                exchange.getIn().setBody(new StringSource("<request>Sending you the operation, could you please perform it?</request>"));
+            }    
+        });
+        
+        inonly.assertIsSatisfied();
+        Exchange exchange = inonly.getExchanges().get(0);
+        assertEquals(OPERATION, exchange.getProperty("jbi.operation"));
+    }
+
+    @Override
+    protected void appendJbiActivationSpecs(List<ActivationSpec> activationSpecList) {
+        // no additional activation specs required
+    }
+
+    @Override
+    protected RouteBuilder createRoutes() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:in-only").to("jbi:service:urn:test:in-only?operation=" + OPERATION);
+                from("direct:in-only-noop").to("log:info").to("jbi:service:urn:test:in-only");
+                
+                from("jbi:service:urn:test:in-only").process(new Processor() {
+                    @Override
+                    public void process(Exchange exchange) throws Exception {
+                        JbiExchange jbi = (JbiExchange) exchange;
+                        assertEquals(new QName(OPERATION), jbi.getMessageExchange().getOperation());
+                    }                    
+                }).to("mock:in-only");
+            }
+        };
+    }
+}

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

Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java?rev=777431&r1=777430&r2=777431&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java Fri May 22 08:42:04 2009
@@ -53,6 +53,8 @@
     protected CamelContext camelContext;
 
     protected SpringJBIContainer jbiContainer = new SpringJBIContainer();
+    
+    protected CamelJbiComponent component;
 
     protected ExchangeCompletedListener exchangeCompletedListener;
 
@@ -124,7 +126,7 @@
         List<ActivationSpec> activationSpecList = new ArrayList<ActivationSpec>();
 
         // lets add the Camel endpoint
-        CamelJbiComponent component = new CamelJbiComponent();
+        component = new CamelJbiComponent();
         activationSpecList.add(createActivationSpec(component, new QName("camel", "camel"), "camelEndpoint"));
 
         // and provide a callback method for adding more services
@@ -133,7 +135,7 @@
 
         jbiContainer.afterPropertiesSet();
 
-        exchangeCompletedListener = new ExchangeCompletedListener();
+        exchangeCompletedListener = new ExchangeCompletedListener(2000);
         jbiContainer.addListener(exchangeCompletedListener);
 
         // allow for additional configuration of the compenent (e.g. deploying SU)
@@ -153,13 +155,14 @@
         return new DefaultCamelContext();
     }
 
-    protected void configureComponent(CamelJbiComponent component) throws Exception {
+    protected void configureComponent(CamelJbiComponent camelComponent) throws Exception {
         // add the ServiceMix Camel component to the CamelContext
-        camelContext.addComponent("jbi", new JbiComponent(component));
+        camelContext.addComponent("jbi", new JbiComponent(camelComponent));
     }
 
     protected void configureContainer(final JBIContainer container) throws Exception {
         container.setEmbedded(true);
+        container.setForceShutdown(1000);
     }
 
     public ServiceMixClient getServicemixClient() throws JBIException {
@@ -169,12 +172,12 @@
         return servicemixClient;
     }
 
-    protected ActivationSpec createActivationSpec(Object component, QName service) {
-        return createActivationSpec(component, service, "endpoint");
+    protected ActivationSpec createActivationSpec(Object comp, QName service) {
+        return createActivationSpec(comp, service, "endpoint");
     }
 
-    protected ActivationSpec createActivationSpec(Object component, QName service, String endpoint) {
-        ActivationSpec spec = new ActivationSpec(component);
+    protected ActivationSpec createActivationSpec(Object comp, QName service, String endpoint) {
+        ActivationSpec spec = new ActivationSpec(comp);
         spec.setService(service);
         spec.setEndpoint(endpoint);
         return spec;
@@ -182,6 +185,7 @@
 
     @Override
     protected void tearDown() throws Exception {
+        exchangeCompletedListener.assertExchangeCompleted();
         getServicemixClient().close();
         client.stop();
         camelContext.stop();

Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/osgi/OsgiJbiComponentTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/osgi/OsgiJbiComponentTest.java?rev=777431&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/osgi/OsgiJbiComponentTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/osgi/OsgiJbiComponentTest.java Fri May 22 08:42:04 2009
@@ -0,0 +1,75 @@
+/*
+ * 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.camel.osgi;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.camel.CamelComponent;
+import org.apache.servicemix.camel.CamelJbiComponent;
+import org.easymock.EasyMock;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Test cases for {@link OsgiJbiComponent}
+ */
+public class OsgiJbiComponentTest extends TestCase {
+    
+    /*
+     * The OsgiJbiComponent should get the CamelComponent from the OSGi Service Registry
+     */
+    public void testGetCamelComponentFromOsgiServiceRegistry() throws Exception {
+        CamelComponent component = new CamelJbiComponent();
+        
+        BundleContext context = EasyMock.createMock(BundleContext.class);
+        ServiceReference reference = EasyMock.createMock(ServiceReference.class);
+        expect(context.getServiceReference(CamelComponent.class.getName())).andReturn(reference);
+        expect(context.getService(reference)).andReturn(component);
+        expect(context.ungetService(reference)).andReturn(true);
+        replay(context);
+
+        // check that the CamelComponent is being fetched from the OSGi Service Registry
+        OsgiJbiComponent osgiComponent = new OsgiJbiComponent();
+        osgiComponent.setBundleContext(context);
+        osgiComponent.afterPropertiesSet();
+        assertSame(component, osgiComponent.getCamelJbiComponent());
+        
+        // and that that is being unget in the destroy method
+        osgiComponent.destroy();        
+        verify(context);
+    }
+    
+    public void testIllegalStateExceptionWithoutServiceRegistryEntry() throws Exception {
+        BundleContext context = EasyMock.createMock(BundleContext.class);
+        expect(context.getServiceReference(CamelComponent.class.getName())).andReturn(null);
+        replay(context);
+        
+        OsgiJbiComponent osgiComponent = new OsgiJbiComponent();
+        osgiComponent.setBundleContext(context);
+
+        try {
+            osgiComponent.afterPropertiesSet();
+            fail("Should have thrown an IllegalStateException");
+        } catch (IllegalStateException e) {
+            // this is exactly what we expected
+        }
+    }
+}

Propchange: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/osgi/OsgiJbiComponentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native