svn commit: r1030880 - in /camel/trunk/tests/camel-itest-osgi: ./ src/test/java/org/apache/camel/itest/osgi/ftp/ src/test/resources/ src/test/resources/org/apache/camel/itest/osgi/ftp/

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1030880 - in /camel/trunk/tests/camel-itest-osgi: ./ src/test/java/org/apache/camel/itest/osgi/ftp/ src/test/resources/ src/test/resources/org/apache/camel/itest/osgi/ftp/

davsclaus-2
Author: davsclaus
Date: Thu Nov  4 11:00:04 2010
New Revision: 1030880

URL: http://svn.apache.org/viewvc?rev=1030880&view=rev
Log:
Added ftp test (work in progress)

Added:
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/ftp/
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/ftp/FtpServerBean.java
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/ftp/FtpTest.java
      - copied, changed from r1030862, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/netty/NettyTest.java
    camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/ftp/
    camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/ftp/CamelContext.xml
      - copied, changed from r1030862, camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/spring/bean/CamelContext.xml
    camel/trunk/tests/camel-itest-osgi/src/test/resources/users.properties
Modified:
    camel/trunk/tests/camel-itest-osgi/pom.xml

Modified: camel/trunk/tests/camel-itest-osgi/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/pom.xml?rev=1030880&r1=1030879&r2=1030880&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/pom.xml (original)
+++ camel/trunk/tests/camel-itest-osgi/pom.xml Thu Nov  4 11:00:04 2010
@@ -233,6 +233,17 @@
           <version>${cxf-version}</version>
       </dependency>
 
+      <dependency>
+        <groupId>org.apache.ftpserver</groupId>
+        <artifactId>ftpserver-core</artifactId>
+        <scope>test</scope>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.ftpserver</groupId>
+        <artifactId>ftplet-api</artifactId>
+        <scope>test</scope>
+      </dependency>
+
   </dependencies>
 
   <build>

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/ftp/FtpServerBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/ftp/FtpServerBean.java?rev=1030880&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/ftp/FtpServerBean.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/ftp/FtpServerBean.java Thu Nov  4 11:00:04 2010
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.itest.osgi.ftp;
+
+import java.net.URL;
+
+import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ftpserver.FtpServer;
+import org.apache.ftpserver.FtpServerFactory;
+import org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory;
+import org.apache.ftpserver.ftplet.UserManager;
+import org.apache.ftpserver.listener.ListenerFactory;
+import org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor;
+import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory;
+
+public class FtpServerBean {
+
+    private static final transient Log LOG = LogFactory.getLog(FtpServerBean.class);
+
+    public static final String FTP_ROOT_DIR = "./res/home/";
+
+    protected static FtpServer ftpServer;
+
+    private static int port;
+
+    public static int getPort() {
+        return port;
+    }
+
+    public static void startServer() throws Exception {
+        initPort();
+        System.out.println("Starting FTP server on port " + port);
+        LOG.info("Starting FTP server on port " + port);
+        initFtpServer();
+        ftpServer.start();
+    }
+
+    private static void initPort() {
+        port = 21002;
+    }
+
+    public static void shutdownServer() throws Exception {
+        System.out.println("Shutting down FTP server");
+        LOG.info("Shutting down FTP server with port " + port);
+        try {
+            ftpServer.stop();
+            ftpServer = null;
+            port = 0;
+        } catch (Exception e) {
+            // ignore while shutting down as we could be polling during shutdown
+            // and get errors when the ftp server is stopping. This is only an issue
+            // since we host the ftp server embedded in the same jvm for unit testing
+        }
+    }
+
+    public static void initFtpServer() throws Exception {
+        if (port < 21000) {
+            throw new IllegalArgumentException("Port number is not initialized in an expected range: " + getPort());
+        }
+
+        FtpServerFactory serverFactory = new FtpServerFactory();
+
+        // setup user management to read our users.properties and use clear text passwords
+        URL url = ObjectHelper.loadResourceAsURL("users.properties");
+
+        // use factory to create user manager
+        PropertiesUserManagerFactory pumf = new PropertiesUserManagerFactory();
+        pumf.setUrl(url);
+        pumf.setPasswordEncryptor(new ClearTextPasswordEncryptor());
+        pumf.setAdminName("admin");
+        UserManager uman = pumf.createUserManager();
+
+        serverFactory.setUserManager(uman);
+
+        NativeFileSystemFactory fsf = new NativeFileSystemFactory();
+        fsf.setCreateHome(true);
+        serverFactory.setFileSystem(fsf);
+
+        ListenerFactory factory = new ListenerFactory();
+        factory.setPort(port);
+        serverFactory.addListener("default", factory.createListener());
+
+        ftpServer = serverFactory.createServer();
+    }
+
+}

Copied: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/ftp/FtpTest.java (from r1030862, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/netty/NettyTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/ftp/FtpTest.java?p2=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/ftp/FtpTest.java&p1=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/netty/NettyTest.java&r1=1030862&r2=1030880&rev=1030880&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/netty/NettyTest.java (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/ftp/FtpTest.java Thu Nov  4 11:00:04 2010
@@ -14,62 +14,66 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.itest.osgi.netty;
+package org.apache.camel.itest.osgi.ftp;
 
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.itest.osgi.OSGiIntegrationSpringTestSupport;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
 
 import static org.ops4j.pax.exam.CoreOptions.equinox;
-import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.CoreOptions.options;
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
 
 @RunWith(JUnit4TestRunner.class)
-public class NettyTest extends OSGiIntegrationTestSupport {
-    
+@Ignore("Not fully implemented, see TODO")
+public class FtpTest extends OSGiIntegrationSpringTestSupport {
+
+    @Override
+    protected OsgiBundleXmlApplicationContext createApplicationContext() {
+        return new OsgiBundleXmlApplicationContext(new String[]{"org/apache/camel/itest/osgi/ftp/CamelContext.xml"});
+    }
+
     @Test
-    public void testNetty() throws Exception {
-        getMockEndpoint("mock:result").expectedBodiesReceived("World");
+    public void testFtp() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(1);
 
-        String reply = template.requestBody("netty:tcp://localhost:8876?textline=true", "World", String.class);
-        assertEquals("Bye World", reply);
+        template.sendBodyAndHeader("ftp://localhost:21002?username=admin&password=admin", "Hello World", Exchange.FILE_NAME, "hello.txt");
 
         assertMockEndpointsSatisfied();
     }
 
-    protected RouteBuilder createRouteBuilder() {
-        return new RouteBuilder() {
-            public void configure() {
-                from("netty:tcp://localhost:8876?textline=true")
-                    .to("mock:result")
-                    .transform(body().prepend("Bye "));
-            }
-        };
-    }
-    
     @Configuration
     public static Option[] configure() {
         Option[] options = options(
             // install the spring dm profile            
             profile("spring.dm").version("1.2.0"),    
             // this is how you set the default log level when using pax logging (logProfile)
-            org.ops4j.pax.exam.CoreOptions.systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+            org.ops4j.pax.exam.CoreOptions.systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
             
-            // using the features to install the camel components            
+            mavenBundle().groupId("org.apache.mina").artifactId("mina-core").version("2.0.0"),
+            mavenBundle().groupId("org.apache.ftpserver").artifactId("ftpserver-core").version("1.0.5"),
+            mavenBundle().groupId("org.apache.ftpserver").artifactId("ftplet-api").version("1.0.5"),
+
+            // using the features to install the camel components
             scanFeatures(getCamelKarafFeatureUrl(),                        
-                          "camel-core", "camel-test", "camel-netty"),
-            
+                          "camel-core", "camel-spring", "camel-test", "camel-ftp"),
+
+            // TODO: our app need to import the FTP server stuff
+
             workingDirectory("target/paxrunner/"),
 
-            felix(), equinox());
+            /*felix(),*/ equinox());
         
         return options;
     }
+
 }
\ No newline at end of file

Copied: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/ftp/CamelContext.xml (from r1030862, camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/spring/bean/CamelContext.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/ftp/CamelContext.xml?p2=camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/ftp/CamelContext.xml&p1=camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/spring/bean/CamelContext.xml&r1=1030862&r2=1030880&rev=1030880&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/spring/bean/CamelContext.xml (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/ftp/CamelContext.xml Thu Nov  4 11:00:04 2010
@@ -23,14 +23,14 @@
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
 
-    <bean id="foo" class="org.apache.camel.itest.osgi.core.bean.MyFooBean"/>
-
-    <camelContext xmlns="http://camel.apache.org/schema/spring">
-        <camel:route>
-            <camel:from uri="direct:start"/>
-            <camel:to uri="bean:foo"/>
-            <camel:to uri="mock:result"/>
-        </camel:route>
+    <camelContext xmlns="http://camel.apache.org/schema/spring" depends-on="ftpServer">
+        <route>
+            <from uri="ftp://localhost:21002?user=admin&amp;password=admin"/>
+            <to uri="mock:result"/>
+        </route>
     </camelContext>
 
+    <bean id="ftpServer" class="org.apache.camel.itest.osgi.ftp.FtpServerBean"
+          init-method="startServer" destroy-method="shutdownServer"/>
+
 </beans>

Added: camel/trunk/tests/camel-itest-osgi/src/test/resources/users.properties
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/users.properties?rev=1030880&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/resources/users.properties (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/resources/users.properties Thu Nov  4 11:00:04 2010
@@ -0,0 +1,12 @@
+ftpserver.user.admin
+ftpserver.user.admin.userpassword=admin
+ftpserver.user.admin.homedirectory=./res/home
+ftpserver.user.admin.writepermission=true
+ftpserver.user.scott
+ftpserver.user.scott.userpassword=tiger
+ftpserver.user.scott.homedirectory=./res/home
+ftpserver.user.scott.writepermission=true
+ftpserver.user.dummy
+ftpserver.user.dummy.userpassword=foo
+ftpserver.user.dummy.homedirectory=./res/home
+ftpserver.user.dummy.writepermission=false