servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r777432 - in /servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel: ./ src/main/java/org/apache/servicemix/camel/ src/test/java/org/apache/servicemix/camel/
Date Fri, 22 May 2009 08:45:21 GMT
Author: gertv
Date: Fri May 22 08:45:21 2009
New Revision: 777432

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

Modified:
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/pom.xml
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiMessage.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiCamelAttachmentTest.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiExchangeTest.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/pom.xml?rev=777432&r1=777431&r2=777432&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/pom.xml
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/pom.xml
Fri May 22 08:45:21 2009
@@ -82,6 +82,11 @@
       <scope>provided</scope>
     </dependency>
     <dependency>
+      <groupId>org.easymock</groupId>
+      <artifactId>easymock</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>org.apache.servicemix</groupId>
       <artifactId>servicemix-core</artifactId>
       <scope>provided</scope>

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java?rev=777432&r1=777431&r2=777432&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelJbiComponent.java
Fri May 22 08:45:21 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,8 +41,6 @@
 
     protected CamelSpringDeployer deployer;
 
-    private ScheduledExecutorService executorService;
-
     private List<JbiComponent> jbiComponents = new ArrayList<JbiComponent>();
 
     /*
@@ -153,13 +149,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/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java?rev=777432&r1=777431&r2=777432&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiBinding.java
Fri May 22 08:45:21 2009
@@ -17,7 +17,6 @@
 package org.apache.servicemix.camel;
 
 import java.io.Serializable;
-import java.io.StringReader;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Collection;
@@ -31,7 +30,6 @@
 import javax.jbi.messaging.NormalizedMessage;
 import javax.xml.namespace.QName;
 import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
@@ -160,11 +158,16 @@
 
     protected Source getJbiInContent(Exchange camelExchange) {
         // TODO this should be more smart
-        Object value = camelExchange.getIn().getBody();
-        if (value instanceof String) {
-            return new StreamSource(new StringReader(value.toString()));
+        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 camelExchange.getIn().getBody(Source.class);
+        return content;
     }
 
     protected void addJbiHeaders(MessageExchange jbiExchange, NormalizedMessage normalizedMessage,
Exchange camelExchange) {

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java?rev=777432&r1=777431&r2=777432&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiComponent.java
Fri May 22 08:45:21 2009
@@ -28,7 +28,7 @@
 import org.apache.servicemix.jbi.resolver.URIResolver;
 
 public class JbiComponent implements Component<Exchange> {
-    private final CamelJbiComponent camelJbiComponent;
+    private CamelJbiComponent camelJbiComponent;
     private JbiBinding binding;
     private CamelContext camelContext;
     private IdGenerator idGenerator;
@@ -81,8 +81,7 @@
     // -------------------------------------------------------------------------
     public Endpoint<Exchange> createEndpoint(String uri) {
         if (uri.startsWith("jbi:")) {
-            uri = uri.substring("jbi:".length());
-            return new JbiEndpoint(this, uri);
+            return new JbiEndpoint(this, uri.substring("jbi:".length()));
         }
         return null;
     }

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java?rev=777432&r1=777431&r2=777432&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
Fri May 22 08:45:21 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/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiMessage.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiMessage.java?rev=777432&r1=777431&r2=777432&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiMessage.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/JbiMessage.java
Fri May 22 08:45:21 2009
@@ -109,9 +109,8 @@
             } catch (MessagingException e) {
                 throw new JbiException(e);
             }
-        } else {
-            super.addAttachment(id, content);
         }
+        super.addAttachment(id, content);
     }
 
     @Override

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiCamelAttachmentTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiCamelAttachmentTest.java?rev=777432&r1=777431&r2=777432&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiCamelAttachmentTest.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiCamelAttachmentTest.java
Fri May 22 08:45:21 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)));
+                    }
+                    
+                });
             }
         };
     }

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiExchangeTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiExchangeTest.java?rev=777432&r1=777431&r2=777432&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiExchangeTest.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiExchangeTest.java
Fri May 22 08:45:21 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.FaultImpl;
 import org.apache.servicemix.jbi.messaging.MessageExchangeSupport;
 import org.apache.servicemix.tck.mock.MockMessageExchange;
+import org.apache.servicemix.tck.mock.MockNormalizedMessage;
 
 /**
  * Test case for {@link JbiExchange}
@@ -66,12 +70,35 @@
         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;
             }
+            public NormalizedMessage getMessage(String name) {
+                if ("fault".equalsIgnoreCase(name)) {
+                    return getFault();
+                }
+                return super.getMessage(name);
+            }
         };
     }
 

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java?rev=777432&r1=777431&r2=777432&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-camel/src/test/java/org/apache/servicemix/camel/JbiTestSupport.java
Fri May 22 08:45:21 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
endpointName) {
-        ActivationSpec spec = new ActivationSpec(component);
+    protected ActivationSpec createActivationSpec(Object comp, QName service, String endpointName)
{
+        ActivationSpec spec = new ActivationSpec(comp);
         spec.setService(service);
         spec.setEndpoint(endpointName);
         return spec;
@@ -182,6 +185,7 @@
 
     @Override
     protected void tearDown() throws Exception {
+        exchangeCompletedListener.assertExchangeCompleted();
         getServicemixClient().close();
         client.stop();
         camelContext.stop();



Mime
View raw message