public void testDownloadOneFileWithOverwrite() { System.out.println(this.getClass().getName() + ".testDownloadOneFileWithOverwrite()"); try { String filename = "testDownloadOneFileWithOverwrite.txt"; File file1 = new File("./test/samples/tmp", filename); Utility.stringToFile(file1, "UTF-8", filename); assertEquals(true, file1.exists()); this.params.clear(); this.params.add("-source"); this.params.add(file1.getCanonicalPath()); this.params.add("-target"); this.params.add(this.remotePath + "/" + filename); this.params.add("-o"); runme = new Runme(); runme.runme((String[]) this.params.toArray(new String[0])); assertNull(actualThrowable); file1.delete(); File file2 = new File("./test/samples/testDownloadOneFileWithOverwrite", filename); Utility.stringToFile(file2, "UTF-8", filename); assertEquals(true, file2.exists()); this.params.clear(); this.params.add("-source"); this.params.add(this.remotePath + "/" + filename); this.params.add("-target"); this.params.add(file2.getAbsolutePath()); runme = new Runme(); runme.runme((String[]) this.params.toArray(new String[0])); String actual = actualThrowable.getMessage(); String expected = "uk.co.marcoratto.ftp.FTPException: Local file " + file2.getAbsolutePath() + " already exists!"; System.out.println(" actual :" + actual); System.out.println("expected:" + expected); assertEquals(expected, actual); actualReturnCode = Runme.getRetCode(); assertEquals(2, actualReturnCode); assertEquals(1, actualEndTotalFiles); } catch (Throwable t) { t.printStackTrace(); fail(t.getMessage()); } }
public void testDownloadFiles() { System.out.println(this.getClass().getName() + ".testDownloadFiles()"); try { Utility.stringToFile( new File("./test/samples/tmp/testDownloadFiles-01.txt"), "UTF-8", "testDownloadFiles-01.txt"); Utility.stringToFile( new File("./test/samples/tmp/testDownloadFiles-02.txt"), "UTF-8", "testDownloadFiles-02.txt"); Utility.stringToFile( new File("./test/samples/tmp/testDownloadFiles-03.txt"), "UTF-8", "testDownloadFiles-03.txt"); this.params.clear(); this.params.add("-source"); this.params.add("./test/samples/tmp/testDownloadFiles-*.txt"); this.params.add("-target"); this.params.add(this.remotePath); this.params.add("-o"); runme = new Runme(); runme.runme((String[]) this.params.toArray(new String[0])); assertNull(actualThrowable); File localDir = new File("./test/samples/testDownloadFiles"); this.params.clear(); this.params.add("-source"); this.params.add(this.remotePath + "/testDownloadFiles-*.txt"); this.params.add("-target"); this.params.add(localDir.getCanonicalPath()); this.params.add("-o"); runme = new Runme(); runme.runme((String[]) this.params.toArray(new String[0])); assertNull(actualThrowable); actualReturnCode = Runme.getRetCode(); assertEquals(0, actualReturnCode); assertEquals(3, actualEndTotalFiles); } catch (Throwable t) { t.printStackTrace(); fail(t.getMessage()); } }
public void testUploadOneFileWithDelete() { System.out.println(this.getClass().getName() + ".testUploadOneFileWithDelete()"); try { File file1 = new File("./test/samples/testUploadOneFileWithDelete/testUploadOneFileWithDelete.txt"); file1.delete(); Utility.stringToFile(file1, "UTF-8", "testUploadOneFileWithDelete.txt"); assertEquals(true, file1.exists()); this.params.clear(); this.params.add("-source"); this.params.add("./test/samples/testUploadOneFileWithDelete/testUploadOneFileWithDelete.txt"); this.params.add("-target"); this.params.add(this.remotePath + "/testUploadOneFileWithDelete.txt"); this.params.add("-d"); this.params.add("-o"); runme = new Runme(); runme.runme((String[]) this.params.toArray(new String[0])); assertNull(actualThrowable); actualReturnCode = Runme.getRetCode(); assertEquals(0, actualReturnCode); assertEquals(1, actualEndTotalFiles); assertEquals(false, file1.exists()); } catch (Throwable t) { t.printStackTrace(); fail(t.getMessage()); } }
public void testParamAskPassword() { System.out.println(this.getClass().getName() + ".testParamAskPassword()"); try { String filename = "testParamAskPassword.txt"; File file1 = new File("./test/samples/testParamAskPassword", filename); file1.delete(); Utility.stringToFile(file1, "UTF-8", "testParamAskPassword.txt"); assertEquals(true, file1.exists()); this.params.clear(); this.params.add("-source"); this.params.add(file1.getAbsolutePath()); this.params.add("-target"); this.params.add(this.remotePathWithoutPassword + "/" + filename); this.params.add("-o"); this.params.add("-ask"); runme = new Runme(); runme.runme((String[]) this.params.toArray(new String[0])); assertNull(actualThrowable); actualReturnCode = Runme.getRetCode(); assertEquals(0, actualReturnCode); assertEquals(1, actualEndTotalFiles); } catch (Throwable t) { t.printStackTrace(); fail(t.getMessage()); } }
public void testDownloadOneFileWithDelete() { System.out.println(this.getClass().getName() + ".testDownloadOneFileWithDelete()"); try { String filename = "testDownloadOneFileWithDelete.txt"; File file1 = new File("./test/samples/tmp", filename); Utility.stringToFile(file1, "UTF-8", filename); this.params.clear(); this.params.add("-source"); this.params.add(file1.getCanonicalPath()); this.params.add("-target"); this.params.add(this.remotePath + "/" + filename); runme = new Runme(); runme.runme((String[]) this.params.toArray(new String[0])); assertNull(actualThrowable); file1.delete(); File file2 = new File("./test/samples/testDownloadOneFileWithNameWithDelete", filename); if (file2.exists()) { file2.delete(); } this.params.clear(); this.params.add("-source"); this.params.add(this.remotePath + "/" + filename); this.params.add("-target"); this.params.add(file2.getCanonicalPath()); this.params.add("-d"); runme = new Runme(); runme.runme((String[]) this.params.toArray(new String[0])); assertNull(actualThrowable); actualReturnCode = Runme.getRetCode(); assertEquals(0, actualReturnCode); assertEquals(1, actualEndTotalFiles); assertEquals(true, file2.exists()); file2.delete(); actualEndTotalFiles = -1; this.params.clear(); this.params.add("-source"); this.params.add(this.remotePath + "/" + filename); this.params.add("-target"); this.params.add(file2.getCanonicalPath()); runme = new Runme(); runme.runme((String[]) this.params.toArray(new String[0])); String actual = actualThrowable.getMessage(); String expected = "uk.co.marcoratto.ftp.FTPException: Remote file /home/rattom/tmp/" + filename + " not found!"; System.out.println(actual); System.out.println(expected); assertEquals(expected, actual); actualReturnCode = Runme.getRetCode(); assertEquals(2, actualReturnCode); assertEquals(-1, actualEndTotalFiles); assertEquals(false, file2.exists()); } catch (Throwable t) { t.printStackTrace(); fail(t.getMessage()); } }