Author: ngn
Date: Wed Dec 10 13:28:04 2008
New Revision: 725442

URL: http://svn.apache.org/viewvc?rev=725442&view=rev
Log:
Add test case to ensure we treat TYPE consistent (FTPSERVER-234)

Added:
    
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/TypeTest.java
Modified:
    
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/TYPE.java

Modified: 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/TYPE.java
URL: 
http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/TYPE.java?rev=725442&r1=725441&r2=725442&view=diff
==============================================================================
--- 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/TYPE.java
 (original)
+++ 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/TYPE.java
 Wed Dec 10 13:28:04 2008
@@ -56,7 +56,7 @@
         session.resetState();
 
         // get type from argument
-        char type = 'A';
+        char type;
         if (request.hasArgument()) {
             type = request.getArgument().charAt(0);
         }else{

Added: 
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/TypeTest.java
URL: 
http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/TypeTest.java?rev=725442&view=auto
==============================================================================
--- 
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/TypeTest.java
 (added)
+++ 
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/TypeTest.java
 Wed Dec 10 13:28:04 2008
@@ -0,0 +1,81 @@
+/*
+ * 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.ftpserver.clienttests;
+
+import org.apache.commons.net.ftp.FTPReply;
+import org.apache.ftpserver.ftplet.DataType;
+import org.apache.ftpserver.ftplet.FtpSession;
+
+/**
+*
+* @author The Apache MINA Project ([EMAIL PROTECTED])
+* @version $Rev$, $Date$
+*
+*/
+public class TypeTest extends ClientTestTemplate {
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.ftpserver.clienttests.ClientTestTemplate#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
+    }
+
+    private FtpSession getFtpSession() {
+        return 
server.getListener("default").getActiveSessions().iterator().next().getFtpletSession();
+    }
+    
+    public void testTypeIAndA() throws Exception {
+        assertEquals(DataType.ASCII, getFtpSession().getDataType());
+        
+        // send TYPE I
+        assertTrue(FTPReply.isPositiveCompletion(client.type(2)));
+
+        assertEquals(DataType.BINARY, getFtpSession().getDataType());
+
+        // send TYPE A
+        assertTrue(FTPReply.isPositiveCompletion(client.type(0)));
+
+        assertEquals(DataType.ASCII, getFtpSession().getDataType());
+    }
+
+    public void testUnknownType() throws Exception {
+        assertEquals(DataType.ASCII, getFtpSession().getDataType());
+        
+        // send TYPE N, not supported by FtpServer
+        assertTrue(FTPReply.isNegativePermanent(client.type(4)));
+
+        assertEquals(DataType.ASCII, getFtpSession().getDataType());
+    }
+
+    public void testTypeNoArgument() throws Exception {
+        assertEquals(DataType.ASCII, getFtpSession().getDataType());
+        
+        // send TYPE N, not supported by FtpServer
+        assertTrue(FTPReply.isNegativePermanent(client.sendCommand("TYPE")));
+
+        assertEquals(DataType.ASCII, getFtpSession().getDataType());
+    }
+
+}


Reply via email to