use of org.apache.ftpserver.FtpServer in project fess-crawler by codelibs.
the class FtpClientTest method test_doGet_file_with_space.
public void test_doGet_file_with_space() throws Exception {
FtpServer server = null;
try {
String username = "testuser";
String password = "testpass";
server = startFtpServer(FTP_PORT, username, password);
Map<String, Object> params = new HashMap<String, Object>();
FtpAuthentication auth = new FtpAuthentication();
auth.setUsername(username);
auth.setPassword(password);
params.put(FtpClient.FTP_AUTHENTICATIONS_PROPERTY, new FtpAuthentication[] { auth });
ftpClient.setInitParameterMap(params);
final ResponseData responseData = ftpClient.doGet("ftp://localhost:" + FTP_PORT + "/text 3.txt");
assertEquals(200, responseData.getHttpStatusCode());
assertEquals("UTF-8", responseData.getCharSet());
assertEquals(6, responseData.getContentLength());
assertNotNull(responseData.getLastModified());
assertEquals(Constants.GET_METHOD, responseData.getMethod());
assertEquals("text/plain", responseData.getMimeType());
assertTrue(responseData.getUrl().endsWith("text 3.txt"));
final String content = new String(InputStreamUtil.getBytes(responseData.getResponseBody()), "UTF-8");
assertEquals("test3\n", content);
} finally {
if (server != null) {
server.stop();
}
}
}
use of org.apache.ftpserver.FtpServer in project fess-crawler by codelibs.
the class FtpClientTest method test_doGet_root_dir.
public void test_doGet_root_dir() throws FtpException {
FtpServer server = null;
try {
String username = "testuser";
String password = "testpass";
server = startFtpServer(FTP_PORT, username, password);
Map<String, Object> params = new HashMap<String, Object>();
FtpAuthentication auth = new FtpAuthentication();
auth.setUsername(username);
auth.setPassword(password);
params.put(FtpClient.FTP_AUTHENTICATIONS_PROPERTY, new FtpAuthentication[] { auth });
ftpClient.setInitParameterMap(params);
ftpClient.doGet("ftp://localhost:" + FTP_PORT + "/");
fail();
} catch (final ChildUrlsException e) {
final Set<RequestData> urlSet = e.getChildUrlList();
assertEquals(5, urlSet.size());
for (final RequestData requestData : urlSet.toArray(new RequestData[urlSet.size()])) {
String url = requestData.getUrl();
assertTrue(url.contains("dir1") || url.contains("dir2") || url.contains("text1.txt") || url.contains("text2.txt") || url.contains("text 3.txt"));
}
} finally {
if (server != null) {
server.stop();
}
}
}
use of org.apache.ftpserver.FtpServer in project fess-crawler by codelibs.
the class FtpClientTest method test_doGet_dir1.
public void test_doGet_dir1() throws FtpException {
FtpServer server = null;
try {
String username = "testuser";
String password = "testpass";
server = startFtpServer(FTP_PORT, username, password);
Map<String, Object> params = new HashMap<String, Object>();
FtpAuthentication auth = new FtpAuthentication();
auth.setUsername(username);
auth.setPassword(password);
params.put(FtpClient.FTP_AUTHENTICATIONS_PROPERTY, new FtpAuthentication[] { auth });
ftpClient.setInitParameterMap(params);
ftpClient.doGet("ftp://localhost:" + FTP_PORT + "/dir1");
fail();
} catch (final ChildUrlsException e) {
final Set<RequestData> urlSet = e.getChildUrlList();
assertEquals(1, urlSet.size());
for (final RequestData requestData : urlSet.toArray(new RequestData[urlSet.size()])) {
String url = requestData.getUrl();
assertTrue(url.contains("dir1/test3.txt"));
}
} finally {
if (server != null) {
server.stop();
}
}
}
use of org.apache.ftpserver.FtpServer in project fess-crawler by codelibs.
the class FtpClientTest method test_doHead_file.
public void test_doHead_file() throws Exception {
FtpServer server = null;
try {
String username = "testuser";
String password = "testpass";
server = startFtpServer(FTP_PORT, username, password);
Map<String, Object> params = new HashMap<String, Object>();
FtpAuthentication auth = new FtpAuthentication();
auth.setUsername(username);
auth.setPassword(password);
params.put(FtpClient.FTP_AUTHENTICATIONS_PROPERTY, new FtpAuthentication[] { auth });
ftpClient.setInitParameterMap(params);
final ResponseData responseData = ftpClient.doHead("ftp://localhost:" + FTP_PORT + "/text1.txt");
assertNotNull(responseData.getLastModified());
assertTrue(responseData.getLastModified().getTime() < new Date().getTime());
assertNull(responseData.getResponseBody());
} finally {
if (server != null) {
server.stop();
}
}
}
Aggregations