Search in sources :

Example 96 with NullSession

use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.

the class OverwriteFilterTest method testTemporary.

@Test
public void testTemporary() throws Exception {
    final Host host = new Host(new TestProtocol());
    final OverwriteFilter f = new OverwriteFilter(new DisabledUploadSymlinkResolver(), new NullSession(host), new UploadFilterOptions(host).withTemporary(true));
    final Path file = new Path("/t", EnumSet.of(Path.Type.file));
    final TransferStatus status = f.prepare(file, new NullLocal("t"), new TransferStatus(), new DisabledProgressListener());
    assertNotNull(status.getRename());
    assertNotEquals(file, status.getRename().remote);
    assertNull(status.getRename().local);
    assertNotNull(status.getRename().remote);
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledUploadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver) TestProtocol(ch.cyberduck.core.TestProtocol) NullLocal(ch.cyberduck.core.NullLocal) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) Test(org.junit.Test)

Example 97 with NullSession

use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.

the class RenameExistingFilterTest method testAccept.

@Test
public void testAccept() throws Exception {
    final RenameExistingFilter f = new RenameExistingFilter(new DisabledUploadSymlinkResolver(), new NullSession(new Host(new TestProtocol())));
    final Path t = new Path("t", EnumSet.of(Path.Type.file));
    assertTrue(f.accept(t, new NullLocal(System.getProperty("java.io.tmpdir"), "t") {

        @Override
        public boolean exists() {
            return true;
        }
    }, new TransferStatus().exists(true)));
}
Also used : Path(ch.cyberduck.core.Path) DisabledUploadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver) TestProtocol(ch.cyberduck.core.TestProtocol) NullLocal(ch.cyberduck.core.NullLocal) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) Test(org.junit.Test)

Example 98 with NullSession

use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.

the class RenameExistingFilterTest method testPrepare.

@Test
public void testPrepare() throws Exception {
    final AtomicBoolean c = new AtomicBoolean();
    final RenameExistingFilter f = new RenameExistingFilter(new DisabledUploadSymlinkResolver(), new NullSession(new Host(new TestProtocol())) {

        @Override
        @SuppressWarnings("unchecked")
        public <T> T _getFeature(final Class<T> type) {
            if (type == Move.class) {
                return (T) new Move() {

                    @Override
                    public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) {
                        assertNotSame(file.getName(), renamed.getName());
                        c.set(true);
                        return renamed;
                    }

                    @Override
                    public boolean isRecursive(final Path source, final Path target) {
                        return true;
                    }
                };
            }
            return super._getFeature(type);
        }

        @Override
        public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
            final AttributedList<Path> l = new AttributedList<Path>();
            l.add(new Path("t", EnumSet.of(Path.Type.file)));
            return l;
        }
    });
    final Path p = new Path("t", EnumSet.of(Path.Type.file)) {

        @Override
        public Path getParent() {
            return new Path("p", EnumSet.of(Path.Type.directory));
        }
    };
    f.prepare(p, new NullLocal(System.getProperty("java.io.tmpdir"), "t"), new TransferStatus().exists(true), new DisabledProgressListener());
    assertFalse(c.get());
    f.apply(p, new NullLocal(System.getProperty("java.io.tmpdir"), "t"), new TransferStatus().exists(true), new DisabledProgressListener());
    assertTrue(c.get());
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledUploadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver) TestProtocol(ch.cyberduck.core.TestProtocol) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) AttributedList(ch.cyberduck.core.AttributedList) Move(ch.cyberduck.core.features.Move) NullLocal(ch.cyberduck.core.NullLocal) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) ListProgressListener(ch.cyberduck.core.ListProgressListener) Test(org.junit.Test)

Example 99 with NullSession

use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.

the class RenameExistingFilterTest method testTemporaryFileUpload.

@Test
public void testTemporaryFileUpload() throws Exception {
    final Path file = new Path("/t", EnumSet.of(Path.Type.file));
    final AtomicBoolean found = new AtomicBoolean();
    final AtomicInteger moved = new AtomicInteger();
    final Find find = new Find() {

        @Override
        public boolean find(final Path f, final ListProgressListener listener) {
            if (f.equals(file)) {
                found.set(true);
                return true;
            }
            return false;
        }
    };
    final AttributesFinder attributes = new AttributesFinder() {

        @Override
        public PathAttributes find(final Path file, final ListProgressListener listener) {
            return new PathAttributes();
        }
    };
    final Host host = new Host(new TestProtocol());
    final NullSession session = new NullSession(host) {

        @Override
        @SuppressWarnings("unchecked")
        public <T> T _getFeature(final Class<T> type) {
            if (type.equals(Move.class)) {
                return (T) new Move() {

                    @Override
                    public Path move(final Path source, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) {
                        if (moved.incrementAndGet() == 1) {
                            // Rename existing target file
                            assertEquals(file, source);
                        } else if (moved.get() == 2) {
                            // Move temporary renamed file in place
                            assertEquals(file, renamed);
                        } else {
                            fail();
                        }
                        return renamed;
                    }

                    @Override
                    public boolean isRecursive(final Path source, final Path target) {
                        return true;
                    }
                };
            }
            if (type.equals(Write.class)) {
                return (T) new Write<Void>() {

                    @Override
                    public StatusOutputStream write(final Path file, final TransferStatus status, final ConnectionCallback callback) {
                        fail();
                        return null;
                    }

                    @Override
                    public Append append(final Path file, final TransferStatus status) {
                        fail();
                        return new Append(false);
                    }
                };
            }
            return null;
        }
    };
    final UploadFilterOptions options = new UploadFilterOptions(host).withTemporary(true);
    final RenameExistingFilter f = new RenameExistingFilter(new DisabledUploadSymlinkResolver(), session, options);
    f.withFinder(find).withAttributes(attributes);
    assertTrue(options.temporary);
    final TransferStatus status = f.prepare(file, new NullLocal("t"), new TransferStatus().exists(true), new DisabledProgressListener());
    assertNotNull(status.getRename());
    assertNotNull(status.getRename().remote);
    assertNotEquals(file, status.getDisplayname().local);
    assertNull(status.getRename().local);
    f.apply(file, new NullLocal("t"), status, new DisabledProgressListener());
    // Complete
    status.setComplete();
    f.complete(file, new NullLocal("t"), new TransferOptions(), status, new DisabledProgressListener());
    assertTrue(found.get());
    assertEquals(2, moved.get());
}
Also used : Delete(ch.cyberduck.core.features.Delete) DisabledUploadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver) TestProtocol(ch.cyberduck.core.TestProtocol) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) NullSession(ch.cyberduck.core.NullSession) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) Move(ch.cyberduck.core.features.Move) NullLocal(ch.cyberduck.core.NullLocal) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ListProgressListener(ch.cyberduck.core.ListProgressListener) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) StatusOutputStream(ch.cyberduck.core.io.StatusOutputStream) PathAttributes(ch.cyberduck.core.PathAttributes) Host(ch.cyberduck.core.Host) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Find(ch.cyberduck.core.features.Find) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) Test(org.junit.Test)

Example 100 with NullSession

use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.

the class RenameFilterTest method testDirectoryUpload.

@Test
public void testDirectoryUpload() throws Exception {
    final Path directory = new Path("/t", EnumSet.of(Path.Type.directory));
    final Path file = new Path(directory, "f", EnumSet.of(Path.Type.file));
    final AtomicBoolean found = new AtomicBoolean();
    final AtomicBoolean moved = new AtomicBoolean();
    final AttributesFinder attributes = new AttributesFinder() {

        @Override
        public PathAttributes find(final Path file, final ListProgressListener listener) {
            return new PathAttributes();
        }
    };
    final Find find = new Find() {

        @Override
        public boolean find(final Path f, final ListProgressListener listener) {
            if (f.equals(directory)) {
                found.set(true);
                return true;
            }
            return false;
        }
    };
    final NullSession session = new NullSession(new Host(new TestProtocol()));
    final RenameFilter f = new RenameFilter(new DisabledUploadSymlinkResolver(), session);
    f.withFinder(find).withAttributes(attributes);
    final TransferStatus directoryStatus = f.prepare(directory, new NullLocal("t"), new TransferStatus().exists(true), new DisabledProgressListener());
    assertTrue(found.get());
    assertNotNull(directoryStatus.getRename());
    assertNull(directoryStatus.getRename().local);
    assertNotNull(directoryStatus.getRename().remote);
    final TransferStatus fileStatus = f.prepare(file, new NullLocal("t/f"), directoryStatus, new DisabledProgressListener());
    assertNotNull(fileStatus.getRename());
    assertNull(fileStatus.getRename().local);
    assertNotNull(fileStatus.getRename().remote);
    assertEquals(new Path("/t-1/f", EnumSet.of(Path.Type.file)), fileStatus.getRename().remote);
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledUploadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver) TestProtocol(ch.cyberduck.core.TestProtocol) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) PathAttributes(ch.cyberduck.core.PathAttributes) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NullLocal(ch.cyberduck.core.NullLocal) Find(ch.cyberduck.core.features.Find) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ListProgressListener(ch.cyberduck.core.ListProgressListener) Test(org.junit.Test)

Aggregations

Host (ch.cyberduck.core.Host)128 NullSession (ch.cyberduck.core.NullSession)128 TestProtocol (ch.cyberduck.core.TestProtocol)128 Test (org.junit.Test)127 Path (ch.cyberduck.core.Path)118 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)81 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)69 NullLocal (ch.cyberduck.core.NullLocal)59 ListProgressListener (ch.cyberduck.core.ListProgressListener)40 AttributedList (ch.cyberduck.core.AttributedList)32 DisabledUploadSymlinkResolver (ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver)27 Local (ch.cyberduck.core.Local)24 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)24 ConnectionCallback (ch.cyberduck.core.ConnectionCallback)19 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)18 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)17 Session (ch.cyberduck.core.Session)17 VaultCredentials (ch.cyberduck.core.vault.VaultCredentials)17 HashMap (java.util.HashMap)14 LocalAttributes (ch.cyberduck.core.LocalAttributes)13