You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ftpserver-commits@incubator.apache.org by ng...@apache.org on 2006/11/17 19:49:29 UTC
svn commit: r476280 - in /incubator/ftpserver/trunk/core: ./
src/java/org/apache/ftpserver/ src/java/org/apache/ftpserver/command/
src/java/org/apache/ftpserver/message/ src/java/org/apache/ftpserver/util/
src/test/org/apache/ftpserver/ src/test/org/ap...
Author: ngn
Date: Fri Nov 17 11:49:28 2006
New Revision: 476280
URL: http://svn.apache.org/viewvc?view=rev&rev=476280
Log:
Some new tests
Some minor fixes based on result of static analysis
Added:
incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/FtpStatisticsImplTest.java (with props)
incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/interfaces/
incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/interfaces/ServerFtpStatisticsTest.java (with props)
incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/util/
incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/util/BasePropertiesTest.java (with props)
Modified:
incubator/ftpserver/trunk/core/pom.xml
incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpDataConnection.java
incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpStatisticsImpl.java
incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/EPSV.java
incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/SITE_DESCUSER.java
incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/message/MessageResourceImpl.java
incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/BaseProperties.java
incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/CdTest.java
incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DeleteTest.java
incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DirectoryTest.java
incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/FtpMd5Test.java
Modified: incubator/ftpserver/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/pom.xml?view=diff&rev=476280&r1=476279&r2=476280
==============================================================================
--- incubator/ftpserver/trunk/core/pom.xml (original)
+++ incubator/ftpserver/trunk/core/pom.xml Fri Nov 17 11:49:28 2006
@@ -67,7 +67,11 @@
</reports>
</reportSet>
</reportSets>
- </plugin>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ </plugin>
</plugins>
</reporting>
@@ -122,7 +126,7 @@
</exclusions>
</dependency>
- <!--Only used for testing -->
+ <!--Only used for testing -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpDataConnection.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpDataConnection.java?view=diff&rev=476280&r1=476279&r2=476280
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpDataConnection.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpDataConnection.java Fri Nov 17 11:49:28 2006
@@ -45,7 +45,7 @@
private Socket dataSoc;
private ServerSocket servSoc;
- private InetAddress address = null;
+ private InetAddress address;
private int port = 0;
private long requestTime = 0L;
Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpStatisticsImpl.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpStatisticsImpl.java?view=diff&rev=476280&r1=476279&r2=476280
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpStatisticsImpl.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpStatisticsImpl.java Fri Nov 17 11:49:28 2006
@@ -112,7 +112,7 @@
* Get server start time.
*/
public Date getStartTime() {
- return startTime;
+ return (Date) startTime.clone();
}
/**
@@ -300,7 +300,9 @@
* Decrement open connection count.
*/
public void setCloseConnection(Connection connection) {
- --currConnections;
+ if(currConnections > 0) {
+ --currConnections;
+ }
notifyCloseConnection(connection);
}
Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/EPSV.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/EPSV.java?view=diff&rev=476280&r1=476279&r2=476280
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/EPSV.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/EPSV.java Fri Nov 17 11:49:28 2006
@@ -65,7 +65,7 @@
int servPort = dataCon.getPort();
// send connection info to client
- String portStr = "|||" + servPort + "|";
+ String portStr = "|||" + servPort + '|';
out.send(229, "EPSV", portStr);
}
}
Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/SITE_DESCUSER.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/SITE_DESCUSER.java?view=diff&rev=476280&r1=476279&r2=476280
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/SITE_DESCUSER.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/SITE_DESCUSER.java Fri Nov 17 11:49:28 2006
@@ -75,6 +75,7 @@
}
}
catch(FtpException ex) {
+ user = null;
}
if(user == null) {
out.send(501, "SITE.DESCUSER", userName);
@@ -84,14 +85,14 @@
// send the user information
StringBuffer sb = new StringBuffer(128);
sb.append("\n");
- sb.append("uid : " + user.getName() + "\n");
+ sb.append("uid : ").append(user.getName()).append("\n");
sb.append("userpassword : ********\n");
- sb.append("homedirectory : " + user.getHomeDirectory() + "\n");
- sb.append("writepermission : " + user.getWritePermission() + "\n");
- sb.append("enableflag : " + user.getEnabled() + "\n");
- sb.append("idletime : " + user.getMaxIdleTime() + "\n");
- sb.append("uploadrate : " + user.getMaxUploadRate() + "\n");
- sb.append("downloadrate : " + user.getMaxDownloadRate() + "\n");
+ sb.append("homedirectory : ").append(user.getHomeDirectory()).append("\n");
+ sb.append("writepermission : ").append(user.getWritePermission()).append("\n");
+ sb.append("enableflag : ").append(user.getEnabled()).append("\n");
+ sb.append("idletime : ").append(user.getMaxIdleTime()).append("\n");
+ sb.append("uploadrate : ").append(user.getMaxUploadRate()).append("\n");
+ sb.append("downloadrate : ").append(user.getMaxDownloadRate()).append("\n");
sb.append('\n');
out.write(200, sb.toString());
}
Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/message/MessageResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/message/MessageResourceImpl.java?view=diff&rev=476280&r1=476279&r2=476280
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/message/MessageResourceImpl.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/message/MessageResourceImpl.java Fri Nov 17 11:49:28 2006
@@ -163,7 +163,7 @@
* Get all the available languages.
*/
public String[] getAvailableLanguages() {
- return languages;
+ return (String[]) languages.clone();
}
/**
Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/BaseProperties.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/BaseProperties.java?view=diff&rev=476280&r1=476279&r2=476280
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/BaseProperties.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/BaseProperties.java Fri Nov 17 11:49:28 2006
@@ -62,9 +62,14 @@
* Load properties from file
*/
public BaseProperties(File fl) throws IOException {
- FileInputStream fis = new FileInputStream(fl);
- load(fis);
- fis.close();
+ FileInputStream fis = null;
+ try {
+ fis = new FileInputStream(fl);
+ load(fis);
+ } catch(IOException e) {
+ IoUtils.close(fis);
+ throw e;
+ }
}
/**
@@ -81,16 +86,16 @@
/**
* Get boolean value.
*/
- public boolean getBoolean(String str) throws FtpException {
- str = getProperty(str);
- if (str == null) {
- throw new FtpException(str + " : not found");
+ public boolean getBoolean(final String str) throws FtpException {
+ String prop = getProperty(str);
+ if (prop == null) {
+ throw new FtpException(str + " not found");
}
- return str.toLowerCase().equals("true");
+ return prop.toLowerCase().equals("true");
}
- public boolean getBoolean(String str, boolean bol) {
+ public boolean getBoolean(final String str, final boolean bol) {
try {
return getBoolean(str);
} catch (FtpException ex) {
@@ -102,21 +107,21 @@
/**
* Get integer value.
*/
- public int getInteger(String str) throws FtpException {
- str = getProperty(str);
- if (str == null) {
- throw new FtpException(str + " : not found");
+ public int getInteger(final String str) throws FtpException {
+ String value = getProperty(str);
+ if (value == null) {
+ throw new FtpException(str + " not found");
}
try {
- return Integer.parseInt(str);
+ return Integer.parseInt(value);
}
catch (NumberFormatException ex) {
throw new FtpException("BaseProperties.getInteger()", ex);
}
}
- public int getInteger(String str, int intVal) {
+ public int getInteger(final String str, final int intVal) {
try {
return getInteger(str);
}
@@ -128,21 +133,21 @@
/**
* Get long value.
*/
- public long getLong(String str) throws FtpException {
- str = getProperty(str);
- if (str == null) {
- throw new FtpException(str + " : not found");
+ public long getLong(final String str) throws FtpException {
+ String value = getProperty(str);
+ if (value == null) {
+ throw new FtpException(str + " not found");
}
try {
- return Long.parseLong(str);
+ return Long.parseLong(value);
}
catch (NumberFormatException ex) {
throw new FtpException("BaseProperties.getLong()", ex);
}
}
- public long getLong(String str, long val) {
+ public long getLong(final String str, final long val) {
try {
return getLong(str);
}
@@ -155,21 +160,21 @@
/**
* Get double value.
*/
- public double getDouble(String str) throws FtpException {
- str = getProperty(str);
- if (str == null) {
- throw new FtpException(str + " : not found");
+ public double getDouble(final String str) throws FtpException {
+ String value = getProperty(str);
+ if (value == null) {
+ throw new FtpException(str + " not found");
}
try {
- return Double.parseDouble(str);
+ return Double.parseDouble(value);
}
catch (NumberFormatException ex) {
throw new FtpException("BaseProperties.getDouble()", ex);
}
}
- public double getDouble(String str, double doubleVal) {
+ public double getDouble(final String str, final double doubleVal) {
try {
return getDouble(str);
}
@@ -181,21 +186,21 @@
/**
* Get <code>InetAddress</code>.
*/
- public InetAddress getInetAddress(String str) throws FtpException {
- str = getProperty(str);
- if(str == null) {
- throw new FtpException(str + " : not found");
+ public InetAddress getInetAddress(final String str) throws FtpException {
+ String value = getProperty(str);
+ if(value == null) {
+ throw new FtpException(str + " not found");
}
try {
- return InetAddress.getByName(str);
+ return InetAddress.getByName(value);
}
catch(UnknownHostException ex) {
- throw new FtpException("Host " + str + " not found");
+ throw new FtpException("Host " + value + " not found");
}
}
- public InetAddress getInetAddress(String str, InetAddress addr) {
+ public InetAddress getInetAddress(final String str, final InetAddress addr) {
try {
return getInetAddress(str);
}
@@ -207,16 +212,16 @@
/**
* Get <code>String</code>.
*/
- public String getString(String str) throws FtpException {
- str = getProperty(str);
- if(str == null) {
- throw new FtpException(str + " : not found");
+ public String getString(final String str) throws FtpException {
+ String value = getProperty(str);
+ if(value == null) {
+ throw new FtpException(str + " not found");
}
- return str;
+ return value;
}
- public String getString(String str, String s) {
+ public String getString(final String str, final String s) {
try {
return getString(str);
}
@@ -228,15 +233,15 @@
/**
* Get <code>File</code> object.
*/
- public File getFile(String str) throws FtpException {
- str = getProperty(str);
- if (str == null) {
- throw new FtpException(str + " : not found");
+ public File getFile(final String str) throws FtpException {
+ String value = getProperty(str);
+ if (value == null) {
+ throw new FtpException(str + " not found");
}
- return new File(str);
+ return new File(value);
}
- public File getFile(String str, File fl) {
+ public File getFile(final String str, final File fl) {
try {
return getFile(str);
}
@@ -249,21 +254,21 @@
/**
* Get <code>Class</code> object
*/
- public Class getClass(String str) throws FtpException {
- str = getProperty(str);
- if (str == null) {
- throw new FtpException(str + " : not found");
+ public Class getClass(final String str) throws FtpException {
+ String value = getProperty(str);
+ if (value == null) {
+ throw new FtpException(str + " not found");
}
try {
- return Class.forName(str);
+ return Class.forName(value);
}
catch (ClassNotFoundException ex) {
throw new FtpException("BaseProperties.getClass()", ex);
}
}
- public Class getClass(String str, Class cls) {
+ public Class getClass(final String str, final Class cls) {
try {
return getClass(str);
}
@@ -275,15 +280,15 @@
/**
* Get <code>TimeZone</code>
*/
- public TimeZone getTimeZone(String str) throws FtpException {
- str = getProperty(str);
- if (str == null) {
- throw new FtpException(str + " : not found");
+ public TimeZone getTimeZone(final String str) throws FtpException {
+ String value = getProperty(str);
+ if (value == null) {
+ throw new FtpException(str + " not found");
}
- return TimeZone.getTimeZone(str);
+ return TimeZone.getTimeZone(value);
}
- public TimeZone getTimeZone(String str, TimeZone tz) {
+ public TimeZone getTimeZone(final String str, final TimeZone tz) {
try {
return getTimeZone(str);
}
@@ -295,15 +300,19 @@
/**
* Get <code>DateFormat</code> object.
*/
- public SimpleDateFormat getDateFormat(String str) throws FtpException {
- str = getProperty(str);
- if (str == null) {
- throw new FtpException(str + " : not found");
+ public SimpleDateFormat getDateFormat(final String str) throws FtpException {
+ String value = getProperty(str);
+ if (value == null) {
+ throw new FtpException(str + " not found");
+ }
+ try {
+ return new SimpleDateFormat(value);
+ } catch(IllegalArgumentException e) {
+ throw new FtpException("Date format was incorrect: " + value, e);
}
- return new SimpleDateFormat(str);
}
- public SimpleDateFormat getDateFormat(String str, SimpleDateFormat fmt) {
+ public SimpleDateFormat getDateFormat(final String str, final SimpleDateFormat fmt) {
try {
return getDateFormat(str);
}
@@ -316,21 +325,21 @@
/**
* Get <code>Date</code> object.
*/
- public Date getDate(String str, DateFormat fmt) throws FtpException {
- str = getProperty(str);
- if (str == null) {
- throw new FtpException(str + " : not found");
+ public Date getDate(final String str, final DateFormat fmt) throws FtpException {
+ String value = getProperty(str);
+ if (value == null) {
+ throw new FtpException(str + " not found");
}
try {
- return fmt.parse(str);
+ return fmt.parse(value);
}
catch (ParseException ex) {
throw new FtpException("BaseProperties.getdate()", ex);
}
}
- public Date getDate(String str, DateFormat fmt, Date dt) {
+ public Date getDate(final String str, final DateFormat fmt, final Date dt) {
try {
return getDate(str, fmt);
}
@@ -346,14 +355,14 @@
/**
* Set boolean value.
*/
- public void setProperty(String key, boolean val) {
+ public void setProperty(final String key, final boolean val) {
setProperty(key, String.valueOf(val));
}
/**
* Set integer value.
*/
- public void setProperty(String key, int val) {
+ public void setProperty(final String key, final int val) {
setProperty(key, String.valueOf(val));
}
@@ -361,63 +370,63 @@
/**
* Set double value.
*/
- public void setProperty(String key, double val) {
+ public void setProperty(final String key, final double val) {
setProperty(key, String.valueOf(val));
}
/**
* Set float value.
*/
- public void setProperty(String key, float val) {
+ public void setProperty(final String key, final float val) {
setProperty(key, String.valueOf(val));
}
/**
* Set long value.
*/
- public void setProperty(String key, long val) {
+ public void setProperty(final String key, final long val) {
setProperty(key, String.valueOf(val));
}
/**
* Set <code>InetAddress</code>.
*/
- public void setInetAddress(String key, InetAddress val) {
+ public void setInetAddress(final String key, final InetAddress val) {
setProperty(key, val.getHostAddress());
}
/**
* Set <code>File</code> object.
*/
- public void setProperty(String key, File val) {
+ public void setProperty(final String key, final File val) {
setProperty(key, val.getAbsolutePath());
}
/**
* Set <code>DateFormat</code> object.
*/
- public void setProperty(String key, SimpleDateFormat val) {
+ public void setProperty(final String key, final SimpleDateFormat val) {
setProperty(key, val.toPattern());
}
/**
* Set <code>TimeZone</code> object.
*/
- public void setProperty(String key, TimeZone val) {
+ public void setProperty(final String key, final TimeZone val) {
setProperty(key, val.getID());
}
/**
* Set <code>Date</code> object.
*/
- public void setProperty(String key, Date val, DateFormat fmt) {
+ public void setProperty(final String key, final Date val, final DateFormat fmt) {
setProperty(key, fmt.format(val));
}
/**
* Set <code>Class</code> object.
*/
- public void setProperty(String key, Class val) {
+ public void setProperty(final String key, final Class val) {
setProperty(key, val.getName());
}
Added: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/FtpStatisticsImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/FtpStatisticsImplTest.java?view=auto&rev=476280
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/FtpStatisticsImplTest.java (added)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/FtpStatisticsImplTest.java Fri Nov 17 11:49:28 2006
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+import org.apache.ftpserver.interfaces.ServerFtpStatisticsTest;
+
+public class FtpStatisticsImplTest extends ServerFtpStatisticsTest {
+
+ protected FtpStatisticsImpl createStatistics() {
+ return new FtpStatisticsImpl();
+ }
+
+}
\ No newline at end of file
Propchange: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/FtpStatisticsImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/CdTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/CdTest.java?view=diff&rev=476280&r1=476279&r2=476280
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/CdTest.java (original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/CdTest.java Fri Nov 17 11:49:28 2006
@@ -51,7 +51,7 @@
assertTrue(client.changeWorkingDirectory(TEST_DIR_IN_DIR1.getName()));
assertEquals("/dir1/dir3", client.printWorkingDirectory());
- assertTrue(client.changeWorkingDirectory("/" + TEST_DIR2.getName()));
+ assertTrue(client.changeWorkingDirectory('/' + TEST_DIR2.getName()));
assertEquals("/dir2", client.printWorkingDirectory());
assertTrue(client.changeWorkingDirectory("/"));
@@ -67,14 +67,14 @@
assertEquals("/", client.printWorkingDirectory());
assertTrue(client.changeWorkingDirectory(
- TEST_DIR1.getName() + "/" + TEST_DIR_IN_DIR1.getName()));
+ TEST_DIR1.getName() + '/' + TEST_DIR_IN_DIR1.getName()));
assertEquals("/dir1/dir3", client.printWorkingDirectory());
}
public void testCDUP() throws Exception {
assertTrue(client.changeWorkingDirectory(
- TEST_DIR1.getName() + "/" + TEST_DIR_IN_DIR1.getName()));
+ TEST_DIR1.getName() + '/' + TEST_DIR_IN_DIR1.getName()));
assertEquals("/dir1/dir3", client.printWorkingDirectory());
assertTrue(client.changeToParentDirectory());
Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DeleteTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DeleteTest.java?view=diff&rev=476280&r1=476279&r2=476280
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DeleteTest.java (original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DeleteTest.java Fri Nov 17 11:49:28 2006
@@ -105,7 +105,7 @@
assertTrue(TEST_FILE_IN_DIR1.exists());
assertTrue(client.deleteFile(
- TEST_DIR1.getName() + "/" + TEST_FILE_IN_DIR1.getName()));
+ TEST_DIR1.getName() + '/' + TEST_FILE_IN_DIR1.getName()));
assertTrue(TEST_DIR1.exists());
assertFalse(TEST_FILE_IN_DIR1.exists());
Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DirectoryTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DirectoryTest.java?view=diff&rev=476280&r1=476279&r2=476280
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DirectoryTest.java (original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DirectoryTest.java Fri Nov 17 11:49:28 2006
@@ -58,7 +58,7 @@
assertFalse(TEST_DIR_IN_DIR1.exists());
assertTrue(FTPReply.isPositiveCompletion(client.mkd(
- TEST_DIR1.getName() + "/" + TEST_DIR_IN_DIR1.getName())));
+ TEST_DIR1.getName() + '/' + TEST_DIR_IN_DIR1.getName())));
assertTrue(TEST_DIR1.exists());
assertTrue(TEST_DIR_IN_DIR1.exists());
@@ -70,7 +70,7 @@
assertFalse(TEST_DIR_IN_DIR1.exists());
assertTrue(FTPReply.isPositiveCompletion(client.mkd(
- TEST_DIR1.getName() + "/" + TEST_DIR_IN_DIR1.getName())));
+ TEST_DIR1.getName() + '/' + TEST_DIR_IN_DIR1.getName())));
assertTrue(TEST_DIR1.exists());
assertTrue(TEST_DIR_IN_DIR1.exists());
Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/FtpMd5Test.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/FtpMd5Test.java?view=diff&rev=476280&r1=476279&r2=476280
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/FtpMd5Test.java (original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/FtpMd5Test.java Fri Nov 17 11:49:28 2006
@@ -30,10 +30,8 @@
public class FtpMd5Test extends ClientTestTemplate {
private static final File TEST_FILE1 = new File(ROOT_DIR, "test1.txt");
private static final File TEST_FILE_WITH_SPACE = new File(ROOT_DIR, "test 2.txt");
- private static final File TEST_FILE3 = new File(ROOT_DIR, "test3.txt");
private static final File TEST_DIR1 = new File(ROOT_DIR, "dir1");
- private static final File TEST_DIR2 = new File(ROOT_DIR, "dir2");
private static final File TEST_FILE_IN_DIR1 = new File(TEST_DIR1, "test4.txt");
private static byte[] testData = null;
Added: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/interfaces/ServerFtpStatisticsTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/interfaces/ServerFtpStatisticsTest.java?view=auto&rev=476280
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/interfaces/ServerFtpStatisticsTest.java (added)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/interfaces/ServerFtpStatisticsTest.java Fri Nov 17 11:49:28 2006
@@ -0,0 +1,89 @@
+/*
+ * 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.interfaces;
+
+import java.util.Date;
+
+import org.apache.ftpserver.FtpStatisticsImpl;
+import org.apache.ftpserver.ftplet.FtpRequest;
+
+import junit.framework.TestCase;
+
+public abstract class ServerFtpStatisticsTest extends TestCase {
+
+ public static class MockConnection implements Connection {
+
+ public void close() {
+ }
+
+ public FtpRequest getRequest() {
+ return null;
+ }
+
+ public void setObserver(ConnectionObserver observer) {
+ }
+
+ public void run() {
+ }
+
+ }
+
+ public void testConnectionCount() {
+ ServerFtpStatistics stats = createStatistics();
+
+ assertEquals(0, stats.getTotalConnectionNumber());
+ assertEquals(0, stats.getCurrentConnectionNumber());
+
+ stats.setOpenConnection(new MockConnection());
+ assertEquals(1, stats.getTotalConnectionNumber());
+ assertEquals(1, stats.getCurrentConnectionNumber());
+
+ stats.setOpenConnection(new MockConnection());
+ assertEquals(2, stats.getTotalConnectionNumber());
+ assertEquals(2, stats.getCurrentConnectionNumber());
+
+ stats.setCloseConnection(new MockConnection());
+ assertEquals(2, stats.getTotalConnectionNumber());
+ assertEquals(1, stats.getCurrentConnectionNumber());
+
+ stats.setCloseConnection(new MockConnection());
+ assertEquals(2, stats.getTotalConnectionNumber());
+ assertEquals(0, stats.getCurrentConnectionNumber());
+
+ // This should never occure
+ stats.setCloseConnection(new MockConnection());
+ assertEquals(2, stats.getTotalConnectionNumber());
+ assertEquals(0, stats.getCurrentConnectionNumber());
+ }
+
+ public void testStartDateImmutable() {
+ ServerFtpStatistics stats = createStatistics();
+ Date date = stats.getStartTime();
+ date.setYear(1);
+
+ Date actual = stats.getStartTime();
+
+ assertFalse(1 == actual.getYear());
+
+ }
+
+ protected abstract FtpStatisticsImpl createStatistics();
+
+}
\ No newline at end of file
Propchange: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/interfaces/ServerFtpStatisticsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/util/BasePropertiesTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/util/BasePropertiesTest.java?view=auto&rev=476280
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/util/BasePropertiesTest.java (added)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/util/BasePropertiesTest.java Fri Nov 17 11:49:28 2006
@@ -0,0 +1,517 @@
+/*
+ * 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.util;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+import junit.framework.TestCase;
+
+import org.apache.ftpserver.ftplet.FtpException;
+
+public class BasePropertiesTest extends TestCase {
+
+ public void testGetBoolean() throws FtpException {
+ BaseProperties props = new BaseProperties();
+ props.setProperty("bool1", "true");
+ props.setProperty("bool2", "TRUE");
+ props.setProperty("bool3", "True");
+ props.setProperty("bool4", "false");
+ props.setProperty("bool5", "FALSE");
+ props.setProperty("bool6", "False");
+ props.setProperty("bool7", "foo");
+ props.setProperty("bool8", "");
+
+ assertEquals(true, props.getBoolean("bool1"));
+ assertEquals(true, props.getBoolean("bool2"));
+ assertEquals(true, props.getBoolean("bool3"));
+ assertEquals(false, props.getBoolean("bool4"));
+ assertEquals(false, props.getBoolean("bool5"));
+ assertEquals(false, props.getBoolean("bool6"));
+ assertEquals(false, props.getBoolean("bool7"));
+ assertEquals(false, props.getBoolean("bool8"));
+
+ // Unknown key
+ try{
+ props.getBoolean("foo");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // default values
+ assertEquals(true, props.getBoolean("foo", true));
+ assertEquals(false, props.getBoolean("foo", false));
+ assertEquals(true, props.getBoolean("bool1", false));
+ assertEquals(false, props.getBoolean("bool4", true));
+ }
+
+ public void testSetBoolean() throws FtpException {
+ BaseProperties props = new BaseProperties();
+ props.setProperty("b1", true);
+
+ assertEquals(true, props.getBoolean("b1"));
+ assertEquals("true", props.getProperty("b1"));
+ assertEquals("true", props.getString("b1"));
+ }
+
+ public void testGetString() throws FtpException {
+ BaseProperties props = new BaseProperties();
+ props.setProperty("s1", "bar");
+
+ assertEquals("bar", props.getString("s1"));
+
+
+ // Unknown value
+ try{
+ props.getString("foo");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // default values
+ assertEquals("bar", props.getString("s1", "baz"));
+ assertEquals("baz", props.getString("foo", "baz"));
+ }
+
+ public void testSetString() throws FtpException {
+ BaseProperties props = new BaseProperties();
+ props.setProperty("s1", "bar");
+
+ assertEquals("bar", props.getProperty("s1"));
+ assertEquals("bar", props.getString("s1"));
+ }
+
+ public void testGetInteger() throws FtpException {
+ BaseProperties props = new BaseProperties();
+ props.setProperty("int1", "1");
+ props.setProperty("int2", "123");
+ props.setProperty("int3", "1.23");
+ props.setProperty("int4", "foo");
+ props.setProperty("int5", "");
+ props.setProperty("int6", "99999999999999999");
+
+ assertEquals(1, props.getInteger("int1"));
+ assertEquals(123, props.getInteger("int2"));
+
+ try{
+ props.getInteger("int3");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+ try{
+ props.getInteger("int4");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+ try{
+ props.getInteger("int5");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+ try{
+ props.getInteger("int6");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // Unknown value
+ try{
+ props.getInteger("foo");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // default values
+ assertEquals(1, props.getInteger("int1", 7));
+ assertEquals(7, props.getInteger("int3", 7));
+ assertEquals(7, props.getInteger("int4", 7));
+ assertEquals(7, props.getInteger("int5", 7));
+ assertEquals(7, props.getInteger("int6", 7));
+ assertEquals(7, props.getInteger("foo", 7));
+ }
+
+ public void testSetInteger() throws FtpException {
+ BaseProperties props = new BaseProperties();
+ props.setProperty("i1", 1);
+
+ assertEquals(1, props.getInteger("i1"));
+ assertEquals("1", props.getProperty("i1"));
+ assertEquals("1", props.getString("i1"));
+ }
+
+ public void testGetDouble() throws FtpException {
+ BaseProperties props = new BaseProperties();
+ props.setProperty("d1", "1");
+ props.setProperty("d2", "1.23");
+ props.setProperty("d3", "1,23");
+ props.setProperty("d4", "foo");
+ props.setProperty("d5", "");
+
+ assertEquals(1D, props.getDouble("d1"), 0.1);
+ assertEquals(1.23D, props.getDouble("d2"), 0.1);
+
+ try{
+ props.getDouble("d3");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+ try{
+ props.getDouble("d4");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+ try{
+ props.getDouble("d5");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // Unknown value
+ try{
+ props.getDouble("foo");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // default values
+ assertEquals(1, props.getDouble("d1", 7), 0.1);
+ assertEquals(7, props.getDouble("d3", 7), 0.1);
+ assertEquals(7, props.getDouble("d4", 7), 0.1);
+ assertEquals(7, props.getDouble("d5", 7), 0.1);
+ assertEquals(7, props.getDouble("foo", 7), 0.1);
+ }
+
+ public void testSetDouble() throws FtpException {
+ BaseProperties props = new BaseProperties();
+ props.setProperty("d1", 1.23);
+
+ assertEquals(1.23, props.getDouble("d1"), 0.1);
+ assertEquals("1.23", props.getProperty("d1"));
+ assertEquals("1.23", props.getString("d1"));
+ }
+
+ public void testGetLong() throws FtpException {
+ BaseProperties props = new BaseProperties();
+ props.setProperty("l1", "1");
+ props.setProperty("l2", "123");
+ props.setProperty("l3", "1.23");
+ props.setProperty("l4", "foo");
+ props.setProperty("l5", "");
+ props.setProperty("l6", "99999999999999999");
+
+ assertEquals(1, props.getLong("l1"));
+ assertEquals(123, props.getLong("l2"));
+ assertEquals(99999999999999999L, props.getLong("l6"));
+
+ try{
+ props.getLong("l3");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+ try{
+ props.getLong("l4");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+ try{
+ props.getLong("l5");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // Unknown value
+ try{
+ props.getLong("foo");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // default values
+ assertEquals(1, props.getLong("l1", 7));
+ assertEquals(7, props.getLong("l3", 7));
+ assertEquals(7, props.getLong("l4", 7));
+ assertEquals(7, props.getLong("l5", 7));
+ assertEquals(7, props.getLong("foo", 7));
+ }
+
+ public void testSetLong() throws FtpException {
+ BaseProperties props = new BaseProperties();
+ props.setProperty("l1", 1L);
+
+ assertEquals(1, props.getLong("l1"));
+ assertEquals("1", props.getProperty("l1"));
+ assertEquals("1", props.getString("l1"));
+ }
+
+ public void testGetClass() throws FtpException {
+ BaseProperties props = new BaseProperties();
+ props.setProperty("c1", "java.lang.String");
+ props.setProperty("c2", "foo");
+
+
+ assertEquals(String.class, props.getClass("c1"));
+
+ try{
+ props.getClass("c2");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // Unknown value
+ try{
+ props.getClass("foo");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // default values
+ assertEquals(String.class, props.getClass("c1", Integer.class));
+ assertEquals(Integer.class, props.getClass("c2", Integer.class));
+ assertEquals(Integer.class, props.getClass("foo", Integer.class));
+ }
+
+ public void testSetClass() throws FtpException {
+ BaseProperties props = new BaseProperties();
+ props.setProperty("c1", String.class);
+
+ assertEquals(String.class, props.getClass("c1"));
+ assertEquals("java.lang.String", props.getProperty("c1"));
+ assertEquals("java.lang.String", props.getString("c1"));
+ }
+
+ public void testGetDate() throws FtpException {
+ Date d1 = new Date();
+ Date d2 = new Date(100);
+ DateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSSzzz");
+
+ BaseProperties props = new BaseProperties();
+ props.setProperty("d1", format.format(d1));
+ props.setProperty("d2", "foo");
+
+
+ assertEquals(d1, props.getDate("d1", format));
+
+ try{
+ props.getDate("d2", format);
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // Unknown value
+ try{
+ props.getDate("foo", format);
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // default values
+ assertEquals(d1, props.getDate("d1", format, d2));
+ assertEquals(d2, props.getDate("d2", format, d2));
+ assertEquals(d2, props.getDate("foo", format, d2));
+ }
+
+ public void testSetDate() throws FtpException {
+ Date d = new Date();
+ SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSSzzz");
+
+ BaseProperties props = new BaseProperties();
+ props.setProperty("d1", d, format);
+
+ assertEquals(d, props.getDate("d1", format));
+ assertEquals(format.format(d), props.getProperty("d1"));
+ assertEquals(format.format(d), props.getString("d1"));
+ }
+
+ public void testGetDateFormat() throws FtpException {
+ SimpleDateFormat format1 = new SimpleDateFormat("yyyyMMddHHmmssSSSzzz");
+ SimpleDateFormat format2 = new SimpleDateFormat("yyyy");
+
+ BaseProperties props = new BaseProperties();
+ props.setProperty("d1", "yyyyMMddHHmmssSSSzzz");
+ props.setProperty("d2", "foo");
+
+
+ assertEquals(format1, props.getDateFormat("d1"));
+
+ try{
+ props.getDateFormat("d2");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // Unknown value
+ try{
+ props.getDateFormat("foo");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // default values
+ assertEquals(format1, props.getDateFormat("d1", format2));
+ assertEquals(format2, props.getDateFormat("d2", format2));
+ assertEquals(format2, props.getDateFormat("foo", format2));
+ }
+
+ public void testSetDateFormat() throws FtpException {
+ SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSSzzz");
+
+ BaseProperties props = new BaseProperties();
+ props.setProperty("f1", format);
+
+ assertEquals(format, props.getDateFormat("f1"));
+ assertEquals("yyyyMMddHHmmssSSSzzz", props.getProperty("f1"));
+ assertEquals("yyyyMMddHHmmssSSSzzz", props.getString("f1"));
+ }
+
+ public void testGetFile() throws FtpException {
+ File file1 = new File("test-tmp/test1.txt").getAbsoluteFile();
+ File file2 = new File("test-tmp/test2.txt").getAbsoluteFile();
+
+ BaseProperties props = new BaseProperties();
+ props.setProperty("f1", file1.getAbsolutePath());
+
+
+ assertEquals(file1, props.getFile("f1"));
+
+ // Unknown value
+ try{
+ props.getFile("foo");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // default values
+ assertEquals(file1, props.getFile("f1", file2));
+ assertEquals(file2, props.getFile("foo", file2));
+ }
+
+ public void testSetFile() throws FtpException {
+ File file = new File("test-tmp/test1.txt").getAbsoluteFile();
+
+ BaseProperties props = new BaseProperties();
+ props.setProperty("f1", file);
+
+ assertEquals(file, props.getFile("f1"));
+ assertEquals(file.getAbsolutePath(), props.getProperty("f1"));
+ assertEquals(file.getAbsolutePath(), props.getString("f1"));
+ }
+
+ public void testGetInetAddress() throws FtpException, UnknownHostException {
+ InetAddress a1 = InetAddress.getByName("1.2.3.4");
+ InetAddress a2 = InetAddress.getByName("localhost");
+ InetAddress a3 = InetAddress.getByName("1.2.3.5");
+
+ BaseProperties props = new BaseProperties();
+ props.setProperty("a1", "1.2.3.4");
+ props.setProperty("a2", "localhost");
+ props.setProperty("a4", "1.2.3.4.5");
+
+
+ assertEquals(a1, props.getInetAddress("a1"));
+ assertEquals(a2, props.getInetAddress("a2"));
+
+ // Unknown value
+ try{
+ props.getInetAddress("foo");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // Incorrect host name
+ try{
+ props.getInetAddress("a4");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+ // default values
+ assertEquals(a1, props.getInetAddress("a1", a3));
+ assertEquals(a3, props.getInetAddress("foo", a3));
+ }
+
+ public void testGetTimeZone() throws FtpException {
+ TimeZone tz1 = TimeZone.getTimeZone("PST");
+ TimeZone tz2 = TimeZone.getTimeZone("GMT-8:00");
+ TimeZone tz3 = TimeZone.getTimeZone("foo");
+
+ BaseProperties props = new BaseProperties();
+ props.setProperty("tz1", "PST");
+ props.setProperty("tz2", "GMT-8:00");
+ props.setProperty("tz3", "foo");
+
+
+ assertEquals(tz1, props.getTimeZone("tz1"));
+ assertEquals(tz2, props.getTimeZone("tz2"));
+ assertEquals(tz3, props.getTimeZone("tz3"));
+
+ // Unknown value
+ try{
+ props.getTimeZone("foo");
+ fail("Must throw FtpException");
+ } catch(FtpException e) {
+ // ok
+ }
+
+
+ // default values
+ assertEquals(tz1, props.getTimeZone("tz1", tz2));
+ assertEquals(tz2, props.getTimeZone("foo", tz2));
+ }
+
+ public void testSetTimeZone() throws FtpException {
+ TimeZone tz1 = TimeZone.getTimeZone("PST");
+
+ BaseProperties props = new BaseProperties();
+ props.setProperty("tz1", tz1);
+
+ assertEquals(tz1, props.getTimeZone("tz1"));
+ assertEquals("PST", props.getProperty("tz1"));
+ assertEquals("PST", props.getString("tz1"));
+ }
+}
\ No newline at end of file
Propchange: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/util/BasePropertiesTest.java
------------------------------------------------------------------------------
svn:eol-style = native