Package com.xebialabs.overthere

Examples of com.xebialabs.overthere.OverthereFile


    @Test
    public void shouldCopyLargeFile() throws IOException {
        File largeFile = temp.newFile("large.dat");
        byte[] expected = writeRandomBytes(largeFile, LARGE_FILE_SIZE);

        OverthereFile remoteLargeFile = connection.getTempFile("large.dat");
        LocalFile.valueOf(largeFile).copyTo(remoteLargeFile);

        byte[] actual = readFile(remoteLargeFile);
        assertThat("Data read is not identical to data written", Arrays.equals(actual, expected), equalTo(true));
    }
View Full Code Here


        File largeFolder = temp.newFolder("small.folder");
        for (int i = 0; i < NR_OF_SMALL_FILES; i++) {
            writeRandomBytes(new File(largeFolder, "small" + i + ".dat"), SMALL_FILE_SIZE);
        }

        OverthereFile remoteLargeFolder = connection.getTempFile("small.folder");
        LocalFile.valueOf(largeFolder).copyTo(remoteLargeFolder);

        for (int i = 0; i < NR_OF_SMALL_FILES; i++) {
            OverthereFile remoteFile = remoteLargeFolder.getFile("small" + i + ".dat");
            byte[] remoteBytes = OverthereUtils.read(remoteFile);
            assertThat(remoteBytes.length, equalTo(SMALL_FILE_SIZE));
        }
    }
View Full Code Here

        return LocalConnection.class.getName();
    }

    @Test
    public void isDirectoryWorks() {
        OverthereFile tempFile = connection.getTempFile("tmpDir");
        tempFile.mkdir();
        assertThat("expected temp is a dir", tempFile.isDirectory(), equalTo(true));
    }
View Full Code Here

        assertThat("expected temp is a dir", tempFile.isDirectory(), equalTo(true));
    }

    @Test
    public void canExecuteCommand() {
        OverthereFile tempFile = connection.getTempFile("afile");
        OverthereUtils.write("Some text", "UTF-8", tempFile);
        String lsCommand = connection.getHostOperatingSystem() == UNIX ? "ls" : "dir";
        CmdLine commandLine = CmdLine.build(lsCommand, tempFile.getParentFile().getPath());
        CapturingOverthereExecutionOutputHandler handler = capturingHandler();

        int res = connection.execute(handler, syserrHandler(), commandLine);
        assertThat(res, equalTo(0));
        assertThat(handler.getOutputLines().contains(tempFile.getName()), equalTo(true));
    }
View Full Code Here

        assertThat(handler.getOutputLines().contains(tempFile.getName()), equalTo(true));
    }

    @Test
    public void localFileShouldBeSerializable() throws IOException, ClassNotFoundException {
        OverthereFile tempFile = connection.getTempFile("afile");

        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        ObjectOutputStream objectsOut = new ObjectOutputStream(bytes);
        objectsOut.writeObject(tempFile);

        ObjectInputStream objectsIn = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()));
        Object read = objectsIn.readObject();
        assertThat(read, instanceOf(LocalFile.class));
        assertThat(((LocalFile) read).getPath(), equalTo(tempFile.getPath()));
    }
View Full Code Here

    options.set(PASSWORD, "secret");
    options.set(OPERATING_SYSTEM, UNIX);
    options.set(CONNECTION_TYPE, SFTP);
    OverthereConnection connection = Overthere.getConnection("ssh", options);
    try {
      OverthereFile motd = connection.getFile("/etc/motd");
      System.out.println("Length        : " + motd.length());
      System.out.println("Last modified : " + motd.lastModified());
      System.out.println("Exists        : " + motd.exists());
      System.out.println("Can read      : " + motd.canRead());
      System.out.println("Can write     : " + motd.canWrite());
      System.out.println("Can execute   : " + motd.canExecute());
    } finally {
      connection.close();
    }
  }
View Full Code Here

    options.set(OPERATING_SYSTEM, UNIX);
    options.set(CONNECTION_TYPE, SFTP);
    OverthereConnection connection = Overthere.getConnection("ssh", options);
    try {
      connection.execute(CmdLine.build("cp", "-r", "/var/log/apt", "/tmp/logs1"));
      OverthereFile logs1 = connection.getFile("/tmp/logs1");
      OverthereFile logs2 = connection.getFile("/tmp/logs2");
      logs2.delete();

      System.err.println("Exists #1: " + logs1.exists());
      System.err.println("Exists #2: " + logs2.exists());

      logs1.renameTo(logs2);
      System.err.println("Exists #1: " + logs1.exists());
      System.err.println("Exists #2: " + logs2.exists());

      logs2.copyTo(logs1);
      System.err.println("Exists #1: " + logs1.exists());
      System.err.println("Exists #2: " + logs2.exists());

      logs1.deleteRecursively();
      logs2.deleteRecursively();
      System.err.println("Exists #1: " + logs1.exists());
      System.err.println("Exists #2: " + logs2.exists());
    } finally {
      connection.close();
    }
  }
View Full Code Here

    options.set(PASSWORD, "secret");
    options.set(OPERATING_SYSTEM, UNIX);
    options.set(CONNECTION_TYPE, SCP);
    OverthereConnection connection = Overthere.getConnection("ssh", options);
    try {
      OverthereFile motd = connection.getFile("/tmp/new-motd");
      PrintWriter w = new PrintWriter(motd.getOutputStream());
      try {
        w.println("An Overthere a day keeps the doctor away");
        w.println("Written on " + new java.util.Date() + " from " + InetAddress.getLocalHost() + " running " + System.getProperty("os.name") + " " + System.getProperty("os.version"));
      } finally {
        w.close();
View Full Code Here

        host, remoteFolder);
    return remoteFolder;
  }

  public void getFile(String targetFile, String origFile) {
    OverthereFile motd = connection.getFile(origFile);
    InputStream is = motd.getInputStream();
    try {
      Files.copy(is, Paths.get(targetFile));
      is.close();
    } catch (IOException e) {
      log.error("Exception getting file: {} to {} ()", origFile,
View Full Code Here

          targetFile, e.getMessage());
    }
  }

  public void scp(String origFile, String targetFile) throws IOException {
    OverthereFile motd = connection.getFile(targetFile);
    OutputStream w = motd.getOutputStream();

    byte[] origBytes = Files.readAllBytes(Paths.get(origFile));
    w.write(origBytes);
    w.close();
  }
View Full Code Here

TOP

Related Classes of com.xebialabs.overthere.OverthereFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.