Code example for ByteArrayOutputStream

Methods: toString

    @Test(groups = {"Integration"}) 
    public void testAllocatePty() { 
        final ShellTool localtool = newTool(MutableMap.of("host", "localhost", SshTool.PROP_ALLOCATE_PTY.getName(), true));
        Map<String,Object> props = new LinkedHashMap<String, Object>();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ByteArrayOutputStream err = new ByteArrayOutputStream();
        props.put("out", out);
        props.put("err", err);
        int exitcode = localtool.execScript(props, Arrays.asList("echo hello err > /dev/stderr"), null);
        assertTrue(out.toString().contains("hello err"), "no hello in output: "+out+" (err is '"+err+"')");
        assertFalse(err.toString().contains("hello err"), "hello found in stderr: "+err);
        assertEquals(0, exitcode);
    // Requires setting up an extra ssh key, with a passphrase, and adding it to ~/.ssh/authorized_keys 
    @Test(groups = {"Integration"}) 
    public void testSshKeyWithPassphrase() throws Exception { 
        final SshTool localtool = newTool(ImmutableMap.<String,Object>builder()
                .put(SshTool.PROP_HOST.getName(), "localhost") 
                .put(SshTool.PROP_PRIVATE_KEY_FILE.getName(), SSH_KEY_WITH_PASSPHRASE)
Stop searching for code, let great code find you!  Add Codota to your java IDE