camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r645216 - in /activemq/camel/trunk/components/camel-ftp/src: main/java/org/apache/camel/component/file/remote/ main/resources/META-INF/services/org/apache/camel/ test/data/ test/data/ftpbinarytest/ test/java/org/apache/camel/component/file/...
Date Sun, 06 Apr 2008 09:04:18 GMT
Author: davsclaus
Date: Sun Apr  6 02:04:17 2008
New Revision: 645216

URL: http://svn.apache.org/viewvc?rev=645216&view=rev
Log:
CAMEL-420
- Added missing type converters to support consuming binary files
- Refactored and added unit tests

Added:
    activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConverter.java
    activemq/camel/trunk/components/camel-ftp/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
    activemq/camel/trunk/components/camel-ftp/src/test/data/
    activemq/camel/trunk/components/camel-ftp/src/test/data/ftpbinarytest/
    activemq/camel/trunk/components/camel-ftp/src/test/data/ftpbinarytest/logo.jpeg   (with
props)
    activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToBinaryFileTest.java
    activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToMockTest.java
  (contents, props changed)
      - copied, changed from r645079, activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRouteTest.java
    activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java
Removed:
    activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRouteTest.java
Modified:
    activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpTest.java
    activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToAsciiFileTest.java

Added: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConverter.java?rev=645216&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConverter.java
(added)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConverter.java
Sun Apr  6 02:04:17 2008
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file.remote;
+
+import org.apache.camel.Converter;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.ByteArrayInputStream;
+
+/**
+ * A set of converter methods for working with remote file types
+ *
+ * @version $Revision$
+ */
+@Converter
+public class RemoteFileConverter {
+
+    @Converter
+    public static byte[] toByteArray(ByteArrayOutputStream os) {
+        return os.toByteArray();
+    }
+
+    @Converter
+    public static InputStream toInputStream(ByteArrayOutputStream os) {
+        return new ByteArrayInputStream(os.toByteArray());
+    }
+    
+}

Added: activemq/camel/trunk/components/camel-ftp/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/resources/META-INF/services/org/apache/camel/TypeConverter?rev=645216&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
(added)
+++ activemq/camel/trunk/components/camel-ftp/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
Sun Apr  6 02:04:17 2008
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.camel.component.file.remote
\ No newline at end of file

Added: activemq/camel/trunk/components/camel-ftp/src/test/data/ftpbinarytest/logo.jpeg
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/data/ftpbinarytest/logo.jpeg?rev=645216&view=auto
==============================================================================
Binary file - no diff available.

Propchange: activemq/camel/trunk/components/camel-ftp/src/test/data/ftpbinarytest/logo.jpeg
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpTest.java?rev=645216&r1=645215&r2=645216&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpTest.java
(original)
+++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpTest.java
Sun Apr  6 02:04:17 2008
@@ -17,20 +17,24 @@
 package org.apache.camel.component.file.remote;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * @version $Revision$
  */
-public class FromFileToFtpTest extends FtpRouteTest {
+public class FromFileToFtpTest extends FtpServerTestSupport {
+
+    private String port = "20011";
+    private String ftpUrl = "ftp://admin@localhost:" + port + "/tmp2/camel?password=admin";
+
     public void testFtpRoute() throws Exception {
+        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
         resultEndpoint.expectedMinimumMessageCount(1);
-
         resultEndpoint.assertIsSatisfied();
     }
 
-    protected String createFtpUrl() {
-        port = "20011";
-        return "ftp://admin@localhost:" + port + "/tmp2/camel?password=admin";
+    public String getPort() {
+        return port;
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -42,4 +46,5 @@
             }
         };
     }
+
 }

Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToAsciiFileTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToAsciiFileTest.java?rev=645216&r1=645215&r2=645216&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToAsciiFileTest.java
(original)
+++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToAsciiFileTest.java
Sun Apr  6 02:04:17 2008
@@ -21,21 +21,25 @@
 import org.apache.camel.Producer;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.file.FileComponent;
+import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * Unit test to verify that we can pool an ASCII file from the FTP Server and store it on
a local file path
  */
-public class FromFtpToAsciiFileTest extends FtpRouteTest {
+public class FromFtpToAsciiFileTest extends FtpServerTestSupport {
+
+    private String port = "20013";
+    private String ftpUrl = "ftp://admin@localhost:" + port + "/tmp3/camel?password=admin&binary=false";
 
     public void testFtpRoute() throws Exception {
+        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
         resultEndpoint.expectedMinimumMessageCount(1);
         resultEndpoint.expectedBodiesReceived("Hello World from FTPServer");
         resultEndpoint.assertIsSatisfied();
     }
 
-    protected String createFtpUrl() {
-        port = "20013";
-        return "ftp://admin@localhost:" + port + "/tmp3/camel?password=admin&binary=false";
+    public String getPort() {
+        return port;
     }
 
     @Override

Added: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToBinaryFileTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToBinaryFileTest.java?rev=645216&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToBinaryFileTest.java
(added)
+++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToBinaryFileTest.java
Sun Apr  6 02:04:17 2008
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file.remote;
+
+import java.io.File;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Producer;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.file.FileComponent;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.IOConverter;
+
+/**
+ * Unit test to verify that we can pool a BINARY file from the FTP Server and store it on
a local file path
+ */
+public class FromFtpToBinaryFileTest extends FtpServerTestSupport {
+
+    private String port = "20014";
+    // must user "consumer." prefix on the parameters to the file component
+    private String ftpUrl = "ftp://admin@localhost:" + port + "/tmp4/camel?password=admin&binary=true"
+        + "&consumer.delay=2000&consumer.recursive=false&consumer.append=false";
+
+    public void testFtpRoute() throws Exception {
+        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
+        resultEndpoint.expectedMessageCount(1);
+        resultEndpoint.assertIsSatisfied();
+        Exchange ex = resultEndpoint.getExchanges().get(0);
+        byte[] bytes = ex.getIn().getBody(byte[].class);
+        assertTrue("Logo size wrong", bytes.length > 10000);
+
+        // assert the file
+        File file = new File("target/ftptest/deleteme.jpg");
+        assertTrue("The binary file should exists", file.exists());
+        assertTrue("Logo size wrong", file.length() > 10000);
+    }
+
+    public String getPort() {
+        return port;
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        prepareFtpServer();
+    }
+
+    private void prepareFtpServer() throws Exception {
+        // prepares the FTP Server by creating a file on the server that we want to unit
+        // test that we can pool and store as a local file
+        Endpoint endpoint = context.getEndpoint(ftpUrl);
+        Exchange exchange = endpoint.createExchange();
+        exchange.getIn().setBody(IOConverter.toFile("src/test/data/ftpbinarytest/logo.jpeg"));
+        exchange.getIn().setHeader(FileComponent.HEADER_FILE_NAME, "logo.jpeg");
+        Producer producer = endpoint.createProducer();
+        producer.start();
+        producer.process(exchange);
+        producer.stop();
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                String fileUrl = "file:target/ftptest/?noop=true";
+                from(ftpUrl).setHeader(FileComponent.HEADER_FILE_NAME, constant("deleteme.jpg"))
+                    .to(fileUrl, "mock:result");
+            }
+        };
+    }
+
+}
\ No newline at end of file

Copied: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToMockTest.java
(from r645079, activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRouteTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToMockTest.java?p2=activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToMockTest.java&p1=activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRouteTest.java&r1=645079&r2=645216&rev=645216&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRouteTest.java
(original)
+++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToMockTest.java
Sun Apr  6 02:04:17 2008
@@ -16,60 +16,28 @@
  */
 package org.apache.camel.component.file.remote;
 
-import java.util.Properties;
-
-import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.ftpserver.ConfigurableFtpServerContext;
-import org.apache.ftpserver.FtpServer;
-import org.apache.ftpserver.config.PropertiesConfiguration;
-import org.apache.ftpserver.ftplet.Configuration;
-import org.apache.ftpserver.interfaces.FtpServerContext;
 
 /**
  * @version $Revision$
  */
-public class FtpRouteTest extends ContextTestSupport {
+public class FromFtpToMockTest extends FtpServerTestSupport {
     protected MockEndpoint resultEndpoint;
-    protected String ftpUrl;
-    protected FtpServer ftpServer;
     protected String expectedBody = "Hello there!";
     protected String port = "20010";
+    protected String ftpUrl = "ftp://admin@localhost:" + port + "/tmp/camel?password=admin";
 
     public void testFtpRoute() throws Exception {
-
+        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
         resultEndpoint.expectedBodiesReceived(expectedBody);
 
         // TODO when we support multiple marshallers for messages
         // we can support passing headers over files using serialized/XML files
         //resultEndpoint.message(0).header("cheese").isEqualTo(123);
 
-        sendExchange(expectedBody);
-        resultEndpoint.assertIsSatisfied();
-    }
-
-    protected void sendExchange(final Object expectedBody) {
         template.sendBodyAndHeader(ftpUrl, expectedBody, "cheese", 123);
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        ftpUrl = createFtpUrl();
-        ftpServer = createFtpServer();
-        ftpServer.start();
-
-        super.setUp();
-
-        resultEndpoint = getMockEndpoint("mock:result");
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        if (ftpServer != null) {
-            ftpServer.stop();
-        }
+        resultEndpoint.assertIsSatisfied();
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -80,26 +48,8 @@
         };
     }
 
-    protected String createFtpUrl() {
-        return "ftp://admin@localhost:" + port + "/tmp/camel?password=admin";
-    }
-
-    protected FtpServer createFtpServer() throws Exception {
-        // get the configuration object
-        Properties properties = createFtpServerProperties();
-        Configuration config = new PropertiesConfiguration(properties);
-
-        // create service context
-        FtpServerContext ftpConfig = new ConfigurableFtpServerContext(config);
-
-        // create the server object and start it
-        return new FtpServer(ftpConfig);
+    public String getPort() {
+        return port;
     }
 
-    protected Properties createFtpServerProperties() {
-        Properties properties = new Properties();
-        properties.setProperty("config.listeners.default.port", port);
-        properties.setProperty("config.create-default-user", "true");
-        return properties;
-    }
 }

Propchange: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToMockTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToMockTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java?rev=645216&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java
(added)
+++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java
Sun Apr  6 02:04:17 2008
@@ -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.camel.component.file.remote;
+
+import java.util.Properties;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.ftpserver.FtpServer;
+import org.apache.ftpserver.ConfigurableFtpServerContext;
+import org.apache.ftpserver.interfaces.FtpServerContext;
+import org.apache.ftpserver.config.PropertiesConfiguration;
+import org.apache.ftpserver.ftplet.Configuration;
+
+/**
+ * Base class for unit testing using a FTPServer
+ */
+public abstract class FtpServerTestSupport extends ContextTestSupport {
+    protected FtpServer ftpServer;
+
+    public abstract String getPort();
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        initFtpServer();
+        ftpServer.start();
+    }
+
+    protected void tearDown() throws Exception {
+        ftpServer.stop();
+        super.tearDown();
+    }
+
+    protected void initFtpServer() throws Exception {
+        // get the configuration object
+        Properties properties = createFtpServerProperties();
+        Configuration config = new PropertiesConfiguration(properties);
+
+        // create service context
+        FtpServerContext ftpConfig = new ConfigurableFtpServerContext(config);
+
+        // create the server object and start it
+        ftpServer = new FtpServer(ftpConfig);
+    }
+
+    protected Properties createFtpServerProperties() {
+        Properties properties = new Properties();
+        properties.setProperty("config.listeners.default.port", getPort());
+        properties.setProperty("config.create-default-user", "true");
+        return properties;
+    }
+}



Mime
View raw message