activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r801312 - in /activemq/trunk: activemq-core/pom.xml activemq-core/src/test/java/org/apache/activemq/blob/FTPBlobTest.java pom.xml
Date Wed, 05 Aug 2009 17:14:18 GMT
Author: gtully
Date: Wed Aug  5 17:14:17 2009
New Revision: 801312

URL: http://svn.apache.org/viewvc?rev=801312&view=rev
Log:
enable ftpblob test - pull in test dependency on apache ftpserver

Modified:
    activemq/trunk/activemq-core/pom.xml
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPBlobTest.java
    activemq/trunk/pom.xml

Modified: activemq/trunk/activemq-core/pom.xml
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/pom.xml?rev=801312&r1=801311&r2=801312&view=diff
==============================================================================
--- activemq/trunk/activemq-core/pom.xml (original)
+++ activemq/trunk/activemq-core/pom.xml Wed Aug  5 17:14:17 2009
@@ -237,13 +237,11 @@
       <groupId>org.apache.directory.server</groupId>
       <artifactId>apacheds-core</artifactId>
       <version>1.0.0</version>
-      <!--<version>1.0-RC3</version>-->
       <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>
-      <artifactId>nlog4j</artifactId>
-      <version>1.2.24</version>
+      <artifactId>slf4j-log4j12</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>
@@ -252,6 +250,12 @@
       <version>${jmock-version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.ftpserver</groupId>
+      <artifactId>ftpserver-core</artifactId>
+      <version>${ftpserver-version}</version>
+    </dependency>
+
 
   </dependencies>
 
@@ -465,10 +469,6 @@
             <!-- https://issues.apache.org/activemq/browse/AMQ-2050 -->
             <exclude>**/ProxyConnectorTest.*</exclude>
             
-            <!-- FTPBlob tests need FTP server running -->
-            
-            <exclude>**/FTPBlob*/</exclude>
-            
           </excludes>
         </configuration>
       </plugin>

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPBlobTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPBlobTest.java?rev=801312&r1=801311&r2=801312&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPBlobTest.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPBlobTest.java Wed
Aug  5 17:14:17 2009
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 package org.apache.activemq.blob;
+
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileWriter;
@@ -32,37 +33,104 @@
 import org.apache.activemq.BlobMessage;
 import org.apache.activemq.EmbeddedBrokerTestSupport;
 import org.apache.activemq.command.ActiveMQBlobMessage;
+import org.apache.ftpserver.FtpServer;
+import org.apache.ftpserver.FtpServerFactory;
+import org.apache.ftpserver.ftplet.AuthorizationRequest;
+import org.apache.ftpserver.ftplet.User;
+import org.apache.ftpserver.ftplet.UserManager;
+import org.apache.ftpserver.listener.ListenerFactory;
+import org.apache.ftpserver.usermanager.UsernamePasswordAuthentication;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.api.Invocation;
+import org.jmock.lib.action.CustomAction;
 
 /**
- * To start this test make sure an ftp server is running with
- * user: activemq and password: activemq
+ * To start this test make sure an ftp server is running with user: activemq and
+ * password: activemq
  */
 public class FTPBlobTest extends EmbeddedBrokerTestSupport {
-	
-	private ActiveMQConnection connection;
 
-	protected void setUp() throws Exception {
-		bindAddress = "vm://localhost?jms.blobTransferPolicy.defaultUploadUrl=ftp://activemq:activemq@localhost/ftptest/";
+    private static final String ftpServerListenerName = "default";
+    private ActiveMQConnection connection;
+    private FtpServer server;
+    final static String userNamePass = "activemq";
+
+    Mockery context = null;
+
+    protected void setUp() throws Exception {
+
+        final File ftpHomeDirFile = new File("target/FTPBlobTest/ftptest");
+        ftpHomeDirFile.mkdirs();
+        ftpHomeDirFile.getParentFile().deleteOnExit();
+
+        FtpServerFactory serverFactory = new FtpServerFactory();
+        ListenerFactory factory = new ListenerFactory();
+
+        // mock up a user manager to validate user activemq:activemq and provide
+        // home dir options
+        context = new Mockery();
+        final UserManager userManager = context.mock(UserManager.class);
+        final User user = context.mock(User.class);
+        context.checking(new Expectations() {{
+                atLeast(1).of(userManager).authenticate(
+                        with(any(UsernamePasswordAuthentication.class))); will(returnValue(user));
+                atLeast(1).of(userManager).getUserByName(userNamePass); will(returnValue(user));
+                atLeast(1).of(user).getHomeDirectory(); will(returnValue(ftpHomeDirFile.getParent()));
+                atLeast(1).of(user).getMaxIdleTime(); will(returnValue(20000));
+                atLeast(1).of(user).getName(); will(returnValue(userNamePass));
+                atLeast(1).of(user).authorize( with(any(AuthorizationRequest.class))); will(new
CustomAction("return first passed in param") {
+                    public Object invoke(Invocation invocation)
+                            throws Throwable {
+                        return invocation.getParameter(0);
+                    }
+                });
+            }
+        });
+
+        serverFactory.setUserManager(userManager);
+        factory.setPort(0);
+        serverFactory.addListener(ftpServerListenerName, factory
+                .createListener());
+        server = serverFactory.createServer();
+        server.start();
+        int ftpPort = serverFactory.getListener(ftpServerListenerName)
+                .getPort();
+
+        bindAddress = "vm://localhost?jms.blobTransferPolicy.defaultUploadUrl=ftp://"
+                + userNamePass
+                + ":"
+                + userNamePass
+                + "@localhost:"
+                + ftpPort
+                + "/ftptest/";
         super.setUp();
 
         connection = (ActiveMQConnection) createConnection();
         connection.start();
-	}
-	
-	public void testBlobFile() throws Exception {
-		// first create Message
-		File file = File.createTempFile("amq-data-file-", ".dat");
+    }
+
+    protected void tearDown() throws Exception {
+        connection.close();
+        super.tearDown();
+        server.stop();
+    }
+
+    public void testBlobFile() throws Exception {
+        // first create Message
+        File file = File.createTempFile("amq-data-file-", ".dat");
         // lets write some data
-		String content = "hello world "+ System.currentTimeMillis();
+        String content = "hello world " + System.currentTimeMillis();
         BufferedWriter writer = new BufferedWriter(new FileWriter(file));
         writer.append(content);
         writer.close();
-        
-        ActiveMQSession session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+        ActiveMQSession session = (ActiveMQSession) connection.createSession(
+                false, Session.AUTO_ACKNOWLEDGE);
         MessageProducer producer = session.createProducer(destination);
         MessageConsumer consumer = session.createConsumer(destination);
         BlobMessage message = session.createBlobMessage(file);
-        
+
         producer.send(message);
         Thread.sleep(1000);
 
@@ -73,11 +141,12 @@
         InputStream input = ((ActiveMQBlobMessage) msg).getInputStream();
         StringBuilder b = new StringBuilder();
         int i = input.read();
-        while(i != -1) {
-        	b.append((char) i);
-        	i = input.read();
+        while (i != -1) {
+            b.append((char) i);
+            i = input.read();
         }
+        input.close();
         Assert.assertEquals(content, b.toString());
-	}
+    }
 
 }

Modified: activemq/trunk/pom.xml
URL: http://svn.apache.org/viewvc/activemq/trunk/pom.xml?rev=801312&r1=801311&r2=801312&view=diff
==============================================================================
--- activemq/trunk/pom.xml (original)
+++ activemq/trunk/pom.xml Wed Aug  5 17:14:17 2009
@@ -80,6 +80,7 @@
     <xbean-version>3.4</xbean-version>
     <felix-version>1.0.0</felix-version>
     <commons-net-version>2.0</commons-net-version>
+    <ftpserver-version>1.0.0</ftpserver-version>
     <site-repo-url>scpexe://people.apache.org/www/activemq.apache.org/maven/</site-repo-url>
     <!-- OSGi bundles properties -->
     <activemq.osgi.import.pkg>*</activemq.osgi.import.pkg>



Mime
View raw message