INT-2477 allow control encoding to be set

INT-2477 added tests

Polishing - Spring Standard tabs Vs. spaces, formatting
This commit is contained in:
Shane Witbeck
2012-03-23 22:42:58 -04:00
committed by Gary Russell
parent 6975da83da
commit 175bc8554c
2 changed files with 41 additions and 1 deletions

View File

@@ -54,13 +54,15 @@ public abstract class AbstractFtpSessionFactory<T extends FTPClient> implements
protected String password;
protected int port = FTP.DEFAULT_PORT;
protected int bufferSize = 2048; //see https://issues.apache.org/jira/browse/NET-207
protected int clientMode = FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE;
protected int fileType = FTP.BINARY_FILE_TYPE;
protected String controlEncoding = FTP.DEFAULT_CONTROL_ENCODING;
/**
* File types defined by {@link org.apache.commons.net.ftp.FTP} constants:
@@ -76,6 +78,11 @@ public abstract class AbstractFtpSessionFactory<T extends FTPClient> implements
this.fileType = fileType;
}
public void setControlEncoding(String controlEncoding) {
Assert.hasText(controlEncoding);
this.controlEncoding = controlEncoding;
}
public void setConfig(FTPClientConfig config) {
Assert.notNull(config);
this.config = config;
@@ -161,6 +168,7 @@ public abstract class AbstractFtpSessionFactory<T extends FTPClient> implements
this.updateClientMode(client);
client.setFileType(fileType);
client.setBufferSize(bufferSize);
client.setControlEncoding(controlEncoding);
return client;
}

View File

@@ -22,6 +22,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import junit.framework.Assert;
import org.apache.commons.net.ftp.FTPClient;
import org.junit.Ignore;
import org.junit.Test;
@@ -42,6 +43,37 @@ import static org.junit.Assert.assertEquals;
@SuppressWarnings({"rawtypes","unchecked"})
public class SessionFactoryTests {
@Test
public void testWithControlEncoding() {
DefaultFtpSessionFactory sessionFactory = new DefaultFtpSessionFactory();
sessionFactory.setControlEncoding("UTF-8");
Assert.assertEquals("Expected controlEncoding value of 'UTF-8'",
"UTF-8",
TestUtils.getPropertyValue(sessionFactory, "controlEncoding"));
}
@Test
public void testWithoutControlEncoding() {
DefaultFtpSessionFactory sessionFactory = new DefaultFtpSessionFactory();
Assert.assertEquals("Expected controlEncoding value of 'ISO-8859-1'",
"ISO-8859-1",
TestUtils.getPropertyValue(sessionFactory, "controlEncoding"));
}
@Test(expected=IllegalArgumentException.class)
public void testEmptyControlEncoding() {
DefaultFtpSessionFactory sessionFactory = new DefaultFtpSessionFactory();
sessionFactory.setControlEncoding("");
}
@Test(expected=IllegalArgumentException.class)
public void testNullControlEncoding() {
DefaultFtpSessionFactory sessionFactory = new DefaultFtpSessionFactory();
sessionFactory.setControlEncoding(null);
}
@Test
public void testClientModes() throws Exception{
DefaultFtpSessionFactory sessionFactory = new DefaultFtpSessionFactory();