@Override public Integer apply(ShellTool ssh) { return ((SshTool)ssh).copyToServer(props, src, destination); }}); }
@Override public Integer apply(ShellTool ssh) { return ((SshTool) ssh).copyToServer(props, new KnownSizeInputStream(src, filesize), destination); }}); }
@Test(groups = {"Integration"}) public void testCopyToServerWithPermissions() throws Exception { tool().copyToServer(ImmutableMap.of("permissions","0754"), "echo hello world!\n".getBytes(), remoteFilePath); assertRemoteFilePermissions(remoteFilePath, "-rwxr-xr--"); }
@Test(groups = {"Integration"}) public void testCopyToServerWithLastModifiedDate() throws Exception { long lastModificationTime = 1234567; tool().copyToServer(ImmutableMap.of("lastModificationDate", lastModificationTime), "echo hello world!\n".getBytes(), remoteFilePath); String lsout = execCommands("ls -l "+remoteFilePath);//+" | awk '{print \$6 \" \" \$7 \" \" \$8}'"]) //execCommands([ "ls -l "+remoteFilePath+" | awk '{print \$6 \" \" \$7 \" \" \$8}'"]) //varies depending on timezone assertTrue(lsout.contains("Jan 15 1970") || lsout.contains("Jan 14 1970") || lsout.contains("Jan 16 1970"), lsout); //assertLastModified(lsout, lastModifiedDate) }
@Test(groups = {"Integration"}) public void testCopyFileToServerWithPermissions() throws Exception { String contents = "echo hello world!\n"; Files.write(contents, new File(localFilePath), Charsets.UTF_8); tool().copyToServer(ImmutableMap.of("permissions", "0754"), new File(localFilePath), remoteFilePath); assertRemoteFileContents(remoteFilePath, contents); String lsout = execCommands("ls -l "+remoteFilePath); assertTrue(lsout.contains("-rwxr-xr--"), lsout); }
@Test(groups = {"Integration"}) public void testCopyFromServer() throws Exception { String contentsWithoutLineBreak = "echo hello world!"; String contents = contentsWithoutLineBreak+"\n"; tool().copyToServer(MutableMap.<String,Object>of(), contents.getBytes(), remoteFilePath); tool().copyFromServer(MutableMap.<String,Object>of(), remoteFilePath, new File(localFilePath)); List<String> actual = Files.readLines(new File(localFilePath), Charsets.UTF_8); assertEquals(actual, ImmutableList.of(contentsWithoutLineBreak)); }
@Test(groups = {"Integration"}) public void testCopyToServerFromInputStream() throws Exception { String contents = "echo hello world!\n"; ByteArrayInputStream contentsStream = new ByteArrayInputStream(contents.getBytes()); tool().copyToServer(MutableMap.<String,Object>of(), contentsStream, remoteFilePath); assertRemoteFileContents(remoteFilePath, contents); }
@Test(enabled=false, groups = {"Integration"}) public void testCopyFileToNonExistantDir() throws Exception { String contents = "echo hello world!\n"; String remoteFileDirPath = "/tmp/ssh-test-remote-dir-"+Identifiers.makeRandomId(8); String remoteFileInDirPath = remoteFileDirPath + File.separator + "ssh-test-remote-"+Identifiers.makeRandomId(8); filesCreated.add(remoteFileInDirPath); filesCreated.add(remoteFileDirPath); tool().copyToServer(MutableMap.<String,Object>of(), contents.getBytes(), remoteFileInDirPath); assertRemoteFileContents(remoteFileInDirPath, contents); }
@Test(groups = {"Integration"}) public void testCopyToServerFromBytes() throws Exception { String contents = "echo hello world!\n"; byte[] contentBytes = contents.getBytes(); tool().copyToServer(MutableMap.<String,Object>of(), contentBytes, remoteFilePath); assertRemoteFileContents(remoteFilePath, contents); assertRemoteFilePermissions(remoteFilePath, "-rw-r--r--"); // TODO would like to also assert lastModified time, but on jenkins the jvm locale // and the OS locale are different (i.e. different timezones) so the file time-stamp // is several hours out. //assertRemoteFileLastModifiedIsNow(remoteFilePath); }