Search in sources :

Example 1 with ListProgressListener

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

the class SingleTransferWorkerTest method testDownloadPrepareOverride.

@Test
public void testDownloadPrepareOverride() throws Exception {
    final Path child = new Path("/t/c", EnumSet.of(Path.Type.file));
    final Path root = new Path("/t", EnumSet.of(Path.Type.directory));
    final NullLocal local = new NullLocal("l") {

        @Override
        public boolean exists() {
            return true;
        }

        @Override
        public boolean isDirectory() {
            return true;
        }

        @Override
        public boolean isFile() {
            return false;
        }

        @Override
        public AttributedList<Local> list() {
            return AttributedList.emptyList();
        }
    };
    final Transfer t = new DownloadTransfer(new Host(new TestProtocol()), root, local) {

        @Override
        public void transfer(final Session<?> source, final Session<?> destination, final Path file, Local local, final TransferOptions options, final TransferStatus overall, final TransferStatus segment, final ConnectionCallback connectionCallback, final ProgressListener listener, final StreamListener streamListener) {
            if (file.equals(root)) {
                assertTrue(segment.isExists());
            } else {
                assertFalse(segment.isExists());
            }
        }

        @Override
        public AbstractDownloadFilter filter(final Session<?> source, final Session<?> destination, final TransferAction action, final ProgressListener listener) {
            return super.filter(source, destination, action, listener).withAttributes(new AttributesFinder() {

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

        @Override
        public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
            final AttributedList<Path> children = new AttributedList<Path>();
            children.add(child);
            return children;
        }
    };
    final SingleTransferWorker worker = new SingleTransferWorker(session, session, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            return TransferAction.overwrite;
        }
    }, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()) {

        @Override
        public Future<TransferStatus> transfer(final TransferItem item, final TransferAction action) throws BackgroundException {
            if (item.remote.equals(root)) {
                assertTrue(this.getCache().isCached(new TransferItem(root, local)));
            }
            super.transfer(new TransferItem(item.remote, new NullLocal("l")), action);
            if (item.remote.equals(root)) {
                assertFalse(this.getCache().isCached(new TransferItem(root, local)));
            }
            return null;
        }
    };
    worker.run(session);
    assertFalse(worker.getCache().isCached(new TransferItem(child, local)));
    assertTrue(worker.getCache().isEmpty());
}
Also used : TestProtocol(ch.cyberduck.core.TestProtocol) TransferAction(ch.cyberduck.core.transfer.TransferAction) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) NullSession(ch.cyberduck.core.NullSession) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) NullLocal(ch.cyberduck.core.NullLocal) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ListProgressListener(ch.cyberduck.core.ListProgressListener) StreamListener(ch.cyberduck.core.io.StreamListener) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) PathAttributes(ch.cyberduck.core.PathAttributes) NullLocal(ch.cyberduck.core.NullLocal) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) ListProgressListener(ch.cyberduck.core.ListProgressListener) ProgressListener(ch.cyberduck.core.ProgressListener) AttributedList(ch.cyberduck.core.AttributedList) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) TransferItem(ch.cyberduck.core.transfer.TransferItem) NullSession(ch.cyberduck.core.NullSession) Session(ch.cyberduck.core.Session) Test(org.junit.Test)

Example 2 with ListProgressListener

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

the class OverwriteFilterTest method testOverrideFileWithDirectory.

@Test(expected = AccessDeniedException.class)
public void testOverrideFileWithDirectory() throws Exception {
    final AbstractUploadFilter f = new OverwriteFilter(new DisabledUploadSymlinkResolver(), new NullSession(new Host(new TestProtocol()))).withFinder(new Find() {

        @Override
        public boolean find(final Path file, final ListProgressListener listener) {
            if (file.getType().contains(Path.Type.file)) {
                return true;
            }
            return false;
        }
    });
    f.prepare(new Path("a", EnumSet.of(Path.Type.directory)), new NullLocal(System.getProperty("java.io.tmpdir")), new TransferStatus().exists(true), new DisabledProgressListener());
}
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) 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)

Example 3 with ListProgressListener

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

the class RenameExistingFilterTest method testTemporaryDirectoryUpload.

@Test
public void testTemporaryDirectoryUpload() throws Exception {
    final Path file = new Path("/t", EnumSet.of(Path.Type.directory));
    final AtomicBoolean found = new AtomicBoolean();
    final AtomicBoolean moved = new AtomicBoolean();
    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 f, final Path renamed, TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) {
                        assertFalse(moved.get());
                        assertEquals(file, f);
                        moved.set(true);
                        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 RenameExistingFilter f = new RenameExistingFilter(new DisabledUploadSymlinkResolver(), session, new UploadFilterOptions(host).withTemporary(true));
    f.withFinder(find).withAttributes(attributes);
    final TransferStatus status = f.prepare(file, new NullLocal("/t") {

        @Override
        public boolean isDirectory() {
            return true;
        }

        @Override
        public boolean isFile() {
            return false;
        }
    }, new TransferStatus().exists(true), new DisabledProgressListener());
    assertTrue(found.get());
    assertNull(status.getRename().remote);
    assertNull(status.getRename().local);
    assertFalse(moved.get());
    f.apply(file, new NullLocal("/t") {

        @Override
        public boolean isDirectory() {
            return true;
        }
    }, new TransferStatus().exists(true), new DisabledProgressListener());
    assertTrue(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) 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) Find(ch.cyberduck.core.features.Find) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) Test(org.junit.Test)

Example 4 with ListProgressListener

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

the class ResumeFilterTest method testAppendSmallerSize.

@Test
public void testAppendSmallerSize() throws Exception {
    final Host host = new Host(new TestProtocol());
    final NullSession session = new NullSession(host) {

        @Override
        public AttributedList<Path> list(final Path folder, final ListProgressListener listener) throws BackgroundException {
            final AttributedList<Path> list = new AttributedList<>(Collections.singletonList(new Path(folder, "t", EnumSet.of(Path.Type.file)).withAttributes(new PathAttributes().withSize(2L))));
            listener.chunk(folder, list);
            return list;
        }
    };
    final ResumeFilter f = new ResumeFilter(new DisabledUploadSymlinkResolver(), session, new UploadFilterOptions(host).withTemporary(true), new DefaultUploadFeature<>(new NullWriteFeature(session)));
    final long size = 3L;
    final Path t = new Path("t", EnumSet.of(Path.Type.file));
    final NullLocal l = new NullLocal("t") {

        @Override
        public LocalAttributes attributes() {
            return new LocalAttributes("t") {

                @Override
                public long getSize() {
                    return size;
                }
            };
        }

        @Override
        public boolean isFile() {
            return true;
        }

        @Override
        public boolean exists() {
            return true;
        }
    };
    assertTrue(f.accept(t, l, new TransferStatus().exists(true)));
    // Remaining length to transfer is 1
    assertEquals(1L, f.prepare(t, l, new TransferStatus().exists(true), new DisabledProgressListener()).getLength());
    // Skip first 2 bytes
    assertEquals(2L, f.prepare(t, l, new TransferStatus().exists(true), new DisabledProgressListener()).getOffset());
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledUploadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver) TestProtocol(ch.cyberduck.core.TestProtocol) NullWriteFeature(ch.cyberduck.core.NullWriteFeature) LocalAttributes(ch.cyberduck.core.LocalAttributes) PathAttributes(ch.cyberduck.core.PathAttributes) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) AttributedList(ch.cyberduck.core.AttributedList) NullLocal(ch.cyberduck.core.NullLocal) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ListProgressListener(ch.cyberduck.core.ListProgressListener) Test(org.junit.Test)

Example 5 with ListProgressListener

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

the class ResumeFilterTest method testSkip.

@Test
public void testSkip() throws Exception {
    final Path file = new Path("t", EnumSet.of(Path.Type.file));
    final ResumeFilter f = new ResumeFilter(new DisabledUploadSymlinkResolver(), new NullSession(new Host(new TestProtocol())) {

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

                    @Override
                    public boolean find(final Path file, final ListProgressListener listener) {
                        return true;
                    }
                };
            }
            return super._getFeature(type);
        }

        @Override
        public AttributedList<Path> list(final Path parent, final ListProgressListener listener) {
            return new AttributedList<>(Collections.singletonList(file));
        }
    });
    file.attributes().setSize(1L);
    assertFalse(f.accept(file, new NullLocal("a") {

        @Override
        public boolean exists() {
            return true;
        }

        @Override
        public LocalAttributes attributes() {
            return new LocalAttributes("t") {

                @Override
                public long getSize() {
                    return 1L;
                }
            };
        }
    }, new TransferStatus().exists(true)));
}
Also used : Path(ch.cyberduck.core.Path) DisabledUploadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver) TestProtocol(ch.cyberduck.core.TestProtocol) LocalAttributes(ch.cyberduck.core.LocalAttributes) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) AttributedList(ch.cyberduck.core.AttributedList) 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

ListProgressListener (ch.cyberduck.core.ListProgressListener)49 Path (ch.cyberduck.core.Path)49 Test (org.junit.Test)48 Host (ch.cyberduck.core.Host)43 TestProtocol (ch.cyberduck.core.TestProtocol)43 NullSession (ch.cyberduck.core.NullSession)41 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)30 AttributedList (ch.cyberduck.core.AttributedList)29 NullLocal (ch.cyberduck.core.NullLocal)26 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)25 Find (ch.cyberduck.core.features.Find)14 DisabledUploadSymlinkResolver (ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver)14 PathAttributes (ch.cyberduck.core.PathAttributes)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)11 AttributesFinder (ch.cyberduck.core.features.AttributesFinder)11 Delete (ch.cyberduck.core.features.Delete)10 Session (ch.cyberduck.core.Session)9 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)8 LocalAttributes (ch.cyberduck.core.LocalAttributes)7