Package com.xebialabs.overthere

Examples of com.xebialabs.overthere.OverthereFile


        temp.delete();
    }

    @Test
    public void shouldDoLocalCopyIfOverSameConnection() throws IOException {
        final OverthereFile tempFile = connection.getTempFile("Foo.txt");
        write(generateRandomBytes(1000), new OutputSupplier<OutputStream>() {
            @Override
            public OutputStream getOutput() throws IOException {
                return tempFile.getOutputStream();
            }
        });
        BaseOverthereFile spy = mock(BaseOverthereFile.class);
        when(spy.getConnection()).thenReturn((BaseOverthereConnection) connection);
        tempFile.copyTo(spy);
        verify(spy, times(1)).shortCircuitCopyFrom(tempFile);
    }
View Full Code Here


        verify(spy, times(1)).shortCircuitCopyFrom(tempFile);
    }

    @Test
    public void shouldNotDoLocalCopyIfDifferentConnection() throws IOException {
        final OverthereFile tempFile = connection.getTempFile("Foo.txt");
        write(generateRandomBytes(1000), new OutputSupplier<OutputStream>() {
            @Override
            public OutputStream getOutput() throws IOException {
                return tempFile.getOutputStream();
            }
        });
        BaseOverthereFile spy = mock(BaseOverthereFile.class);
        when(spy.getConnection()).thenReturn((BaseOverthereConnection) otherConnection);
        tempFile.copyTo(spy);
        verify(spy, times(1)).copyFrom(tempFile);
    }
View Full Code Here

    @Test
    @Assumption(methods = "onUnix")
    public void shouldCreateHiddenUnixFileAndBeAbleToListIt() {
        final String prefix = "prefix";
        final String suffix = "suffix";
        OverthereFile tempDir = connection.getTempFile(prefix, suffix);
        tempDir.mkdir();
        byte[] contents = "Hey there, I'm a hidden file.".getBytes();
        OverthereFile hiddenFile = tempDir.getFile(".imhidden");
        OverthereUtils.write(contents, hiddenFile);
        List<OverthereFile> overthereFiles = tempDir.listFiles();
        assertThat("Expected dir listing to list hidden file.", overthereFiles, hasSize(1));
        hiddenFile.delete();
        assertThat("Should have removed hidden file", !hiddenFile.exists());
        tempDir.delete();
    }
View Full Code Here

    @Test
    @Assumption(methods = {"onUnix", "notLocal"})
    public void shouldWriteFileToAndReadFileFromSudoUserHomeDirectoryOnUnix() throws IOException {
        // get handle to file in home dir
        final OverthereFile homeDir = connection.getFile(getUnixHomeDirPath());
        final OverthereFile fileInHomeDir = homeDir.getFile("file" + System.currentTimeMillis() + ".dat");
        assertThat(fileInHomeDir.exists(), equalTo(false));

        // write data to file in home dir
        final byte[] contentsWritten = generateRandomBytes(1024);
        write(contentsWritten, new OutputSupplier<OutputStream>() {
            @Override
            public OutputStream getOutput() throws IOException {
                return fileInHomeDir.getOutputStream();
            }
        });

        assertThat(fileInHomeDir.exists(), equalTo(true));

        // restrict access to file in home dir
        connection.execute(sysoutHandler(), syserrHandler(), CmdLine.build("chmod", "0600", fileInHomeDir.getPath()));

        // read file from home dir
        byte[] contentsRead = readFile(fileInHomeDir);
        assertThat(contentsRead, equalTo(contentsWritten));

        // restrict access to file in home dir
        fileInHomeDir.delete();
        assertThat(fileInHomeDir.exists(), equalTo(false));
    }
View Full Code Here

    @Test
    @Assumption(methods = {"onUnix", "notLocal"})
    public void shouldCopyFileToAndFromSudoUserHomeDirectoryOnUnix() throws IOException {
        // get handle to file in home dir
        final OverthereFile homeDir = connection.getFile(getUnixHomeDirPath());
        final OverthereFile fileInHomeDir = homeDir.getFile("file" + System.currentTimeMillis() + ".dat");
        assertThat(fileInHomeDir.exists(), equalTo(false));

        // write random data to local file
        File smallFile = temp.newFile("small.dat");
        byte[] contentsWritten = writeRandomBytes(smallFile, 1024);
        OverthereFile smallLocalFile = LocalFile.valueOf(smallFile);

        // copy local file to file in home dir
        smallLocalFile.copyTo(fileInHomeDir);

        assertThat(fileInHomeDir.exists(), equalTo(true));

        // restrict access to file in home dir
        connection.execute(sysoutHandler(), syserrHandler(), CmdLine.build("chmod", "0600", fileInHomeDir.getPath()));

        // copy file in home dir to local file
        File smallFileReadBack = temp.newFile("small-read-back.dat");
        OverthereFile smallLocalFileReadBack = LocalFile.valueOf(smallFileReadBack);
        fileInHomeDir.copyTo(smallLocalFileReadBack);

        // read new local file
        byte[] contentsRead = readFile(smallLocalFileReadBack);
        assertThat(contentsRead, equalTo(contentsWritten));
View Full Code Here

    }

    @Test
    @Assumption(methods = "onUnix")
    public void shouldSetExecutableOnUnix() {
        OverthereFile remoteFile = connection.getTempFile("executable.sh");
        OverthereUtils.write(generateRandomBytes(256), remoteFile);

        assertThat(remoteFile.canExecute(), equalTo(false));
        remoteFile.setExecutable(true);
        assertThat(remoteFile.canExecute(), equalTo(true));
        remoteFile.setExecutable(false);
        assertThat(remoteFile.canExecute(), equalTo(false));
    }
View Full Code Here

    private static byte[] OTHER_DEST_FILE_CONTENT = "This should be left as-is".getBytes();

    @Test
    public void shouldCopyLocalFileToNonExistentRemoteFile() {
        OverthereFile srcFile = getLocalSourceFile();
        OverthereFile dstFile = getRemoteDestinationFile();

        populateSourceFile(srcFile);

        srcFile.copyTo(dstFile);
View Full Code Here

        assertSourceFileWasCopiedToDestinationFile(dstFile);
    }

    @Test
    public void shouldCopyLocalFileToExistentRemoteFile() {
        OverthereFile srcFile = getLocalSourceFile();
        OverthereFile dstFile = getRemoteDestinationFile();

        populateSourceFile(srcFile);
        populateExistentDestinationFile(dstFile);

        srcFile.copyTo(dstFile);
View Full Code Here

        assertSourceFileWasCopiedToDestinationFile(dstFile);
    }

    @Test
    public void shouldCopyLocalFileToNonExistentRemoteFileWithDifferentName() {
        OverthereFile srcFile = getLocalSourceFile();
        OverthereFile dstFile = getRemoteDestinationFileWithDifferentName();

        populateSourceFile(srcFile);

        srcFile.copyTo(dstFile);
View Full Code Here

        assertSourceFileWasCopiedToDestinationFile(dstFile);
    }

    @Test
    public void shouldCopyLocalFileToExistentRemoteFileWithDifferentName() {
        OverthereFile srcFile = getLocalSourceFile();
        OverthereFile dstFile = getRemoteDestinationFileWithDifferentName();

        populateSourceFile(srcFile);
        populateExistentDestinationFile(dstFile);

        srcFile.copyTo(dstFile);
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.