@SuppressWarnings("resource") @Test public void testTryExecuteWithDirectory() throws IOException { Session session = mock(Session.class); when(client.startSession()).thenReturn(session); Command command = mock(Command.class); when(session.exec("\"cd\" \"/test/dir\" && \"test command\" \"param\"")) .thenReturn(command); when(command.getExitStatus()).thenReturn(1); when(command.getInputStream()).thenReturn(IOUtils.toInputStream("output\n")); when(command.getErrorStream()).thenReturn(IOUtils.toInputStream("error line\n")); SshConfig config = new SshConfig("localhost", "me"); new SshConnection(config, client) .tryExecute(Paths.get("/test/dir"), "test command", "param"); }
@Override public ExecutionResult tryExecute(Path workingDirectory, String... cmd) throws IOException { String workdir = workingDirectory == null ? null : workingDirectory.toString(); return tryExecuteIn(workdir, cmd); }
SshConnection implements AutoCloseable, CommandExecutor { @Override public ExecutionResult tryExecute(Path workingDirectory, String... cmd) throws IOException { String workdir = workingDirectory == null ? null : workingDirectory.toString(); return tryExecuteIn(workdir, cmd); } }
SshConnection implements AutoCloseable, CommandExecutor { @Override public ExecutionResult tryExecute(Path workingDirectory, String... cmd) throws IOException { String workdir = workingDirectory == null ? null : workingDirectory.toString(); return tryExecuteIn(workdir, cmd); } SshConnection(SshConfig config, SSHClient client); }
SshConnection implements AutoCloseable, CommandExecutor { @Override public ExecutionResult tryExecute(Path workingDirectory, String... cmd) throws IOException { String workdir = workingDirectory == null ? null : workingDirectory.toString(); return tryExecuteIn(workdir, cmd); } SshConnection(SshConfig config, SSHClient client); SshConfig getConfig(); InteractiveSession startShell(); @Override void close(); @Override ExecutionResult tryExecute(Path workingDirectory, String... cmd); ExecutionResult executeIn(String workingDirectory, String... cmd); ExecutionResult tryExecuteIn(String workingDirectory, String... cmd); void uploadFile(Path localFile, String targetPath); void writeTextFile(String targetPath, String contents); String readTextFile(String remotePath); void downloadFile(String remotePath, Path localPath); }
SshConnection implements AutoCloseable, CommandExecutor { @Override public ExecutionResult tryExecute(Path workingDirectory, String... cmd) throws IOException { String workdir = workingDirectory == null ? null : workingDirectory.toString(); return tryExecuteIn(workdir, cmd); } SshConnection(SshConfig config, SSHClient client); SshConfig getConfig(); InteractiveSession startShell(); @Override void close(); @Override ExecutionResult tryExecute(Path workingDirectory, String... cmd); ExecutionResult executeIn(String workingDirectory, String... cmd); ExecutionResult tryExecuteIn(String workingDirectory, String... cmd); void uploadFile(Path localFile, String targetPath); void writeTextFile(String targetPath, String contents); String readTextFile(String remotePath); void downloadFile(String remotePath, Path localPath);  }