Search in sources :

Example 16 with DisabledNotificationService

use of ch.cyberduck.core.notification.DisabledNotificationService in project cyberduck by iterate-ch.

the class UploadTransferTest method testPrepareUploadOverrideFilter.

@Test
public void testPrepareUploadOverrideFilter() throws Exception {
    final Host host = new Host(new TestProtocol());
    final String directoryname = new AlphanumericRandomStringService().random();
    final Session<?> session = new NullSession(host) {

        @Override
        public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
            if (file.equals(new Path("/", EnumSet.of(Path.Type.volume, Path.Type.directory)))) {
                return new AttributedList<>(Collections.singletonList(new Path("/" + directoryname, EnumSet.of(Path.Type.directory))));
            }
            final Path f = new Path("/" + directoryname + "/test", EnumSet.of(Path.Type.file));
            f.attributes().setSize(5L);
            return new AttributedList<>(Collections.singletonList(f));
        }
    };
    final Path test = new Path(directoryname, EnumSet.of(Path.Type.directory));
    final String name = UUID.randomUUID().toString();
    final Local local = new Local(System.getProperty("java.io.tmpdir"), directoryname);
    new DefaultLocalDirectoryFeature().mkdir(local);
    new DefaultLocalTouchFeature().touch(new Local(local, name));
    final Transfer transfer = new UploadTransfer(host, test, local);
    final SingleTransferWorker worker = new SingleTransferWorker(session, null, transfer, new TransferOptions(), new TransferSpeedometer(transfer), new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            fail();
            return null;
        }
    }, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService());
    worker.prepare(test, new Local(System.getProperty("java.io.tmpdir"), directoryname), new TransferStatus().exists(true), TransferAction.overwrite);
    assertEquals(new TransferStatus().exists(true), worker.getStatus().get(new TransferItem(test, local)));
    final TransferStatus expected = new TransferStatus();
    assertEquals(expected, worker.getStatus().get(new TransferItem(new Path(directoryname + "/" + name, EnumSet.of(Path.Type.file)), new Local(local, name))));
}
Also used : SingleTransferWorker(ch.cyberduck.core.worker.SingleTransferWorker) DefaultLocalDirectoryFeature(ch.cyberduck.core.local.DefaultLocalDirectoryFeature) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DefaultLocalTouchFeature(ch.cyberduck.core.local.DefaultLocalTouchFeature) Test(org.junit.Test)

Example 17 with DisabledNotificationService

use of ch.cyberduck.core.notification.DisabledNotificationService in project cyberduck by iterate-ch.

the class UploadTransferTest method testCacheRename.

@Test
public void testCacheRename() throws Exception {
    final AtomicInteger c = new AtomicInteger();
    final NullLocal local = new NullLocal("t") {

        @Override
        public AttributedList<Local> list() {
            AttributedList<Local> l = new AttributedList<>();
            l.add(new NullLocal(this.getAbsolute(), "a") {

                @Override
                public boolean exists() {
                    return true;
                }
            });
            l.add(new NullLocal(this.getAbsolute(), "b") {

                @Override
                public boolean exists() {
                    return true;
                }
            });
            l.add(new NullLocal(this.getAbsolute(), "c") {

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

        @Override
        public boolean exists() {
            return true;
        }
    };
    final Path root = new Path("/t", EnumSet.of(Path.Type.directory));
    final NullSession session = new NullSession(new Host(new TestProtocol())) {

        @Override
        public AttributedList<Path> list(final Path folder, final ListProgressListener listener) throws ConnectionCanceledException {
            c.incrementAndGet();
            listener.chunk(folder, AttributedList.emptyList());
            return AttributedList.emptyList();
        }
    };
    Transfer t = new UploadTransfer(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) {
        // 
        }
    };
    new SingleTransferWorker(session, null, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            return TransferAction.rename;
        }
    }, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()).run(session);
    assertEquals(1, c.get());
}
Also used : SingleTransferWorker(ch.cyberduck.core.worker.SingleTransferWorker) StreamListener(ch.cyberduck.core.io.StreamListener) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 18 with DisabledNotificationService

use of ch.cyberduck.core.notification.DisabledNotificationService in project cyberduck by iterate-ch.

the class UploadTransferTest method testCacheResume.

@Test
public void testCacheResume() throws Exception {
    final AtomicInteger c = new AtomicInteger();
    final NullLocal local = new NullLocal("t") {

        @Override
        public AttributedList<Local> list() {
            AttributedList<Local> l = new AttributedList<>();
            l.add(new NullLocal(this.getAbsolute(), "a") {

                @Override
                public boolean exists() {
                    return true;
                }
            });
            l.add(new NullLocal(this.getAbsolute(), "b") {

                @Override
                public boolean exists() {
                    return true;
                }
            });
            l.add(new NullLocal(this.getAbsolute(), "c") {

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

        @Override
        public boolean exists() {
            return true;
        }
    };
    final Path root = new Path("/t", EnumSet.of(Path.Type.directory));
    final NullSession session = new NullSession(new Host(new TestProtocol())) {

        @Override
        public AttributedList<Path> list(final Path folder, final ListProgressListener listener) throws ConnectionCanceledException {
            if (folder.equals(root.getParent())) {
                c.incrementAndGet();
            }
            listener.chunk(folder, AttributedList.emptyList());
            return AttributedList.emptyList();
        }
    };
    Transfer t = new UploadTransfer(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) {
            assertTrue(options.resumeRequested);
        }
    };
    final TransferOptions options = new TransferOptions();
    options.resumeRequested = true;
    new SingleTransferWorker(session, null, t, options, new TransferSpeedometer(t), new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            fail();
            return null;
        }
    }, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()).run(session);
    assertEquals(1, c.get());
}
Also used : SingleTransferWorker(ch.cyberduck.core.worker.SingleTransferWorker) StreamListener(ch.cyberduck.core.io.StreamListener) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 19 with DisabledNotificationService

use of ch.cyberduck.core.notification.DisabledNotificationService in project cyberduck by iterate-ch.

the class UploadTransferTest method testUploadTemporaryName.

@Test
public void testUploadTemporaryName() throws Exception {
    final Path test = new Path("/f", EnumSet.of(Path.Type.file));
    final AtomicBoolean moved = new AtomicBoolean();
    final Host host = new Host(new TestProtocol());
    final Session session = new NullSession(host) {

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

                    @Override
                    public boolean find(final Path f, final ListProgressListener listener) {
                        return true;
                    }
                };
            }
            if (type.equals(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) {
                        assertEquals(test, renamed);
                        moved.set(true);
                        return renamed;
                    }

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

                    @Override
                    public boolean isSupported(final Path source, final Path target) {
                        return true;
                    }
                };
            }
            if (type.equals(AttributesFinder.class)) {
                return (T) new AttributesFinder() {

                    @Override
                    public PathAttributes find(final Path file, final ListProgressListener listener) {
                        return new PathAttributes();
                    }
                };
            }
            if (type.equals(Write.class)) {
                return (T) new Write() {

                    @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 Write.Append(false);
                    }
                };
            }
            return super._getFeature(type);
        }
    };
    final AtomicBoolean set = new AtomicBoolean();
    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    LocalTouchFactory.get().touch(local);
    final Transfer transfer = new UploadTransfer(host, test, 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) {
            segment.setComplete();
            set.set(true);
        }

        @Override
        public AbstractUploadFilter filter(final Session<?> source, final Session<?> destination, final TransferAction action, final ProgressListener listener) {
            return super.filter(source, destination, action, listener).withOptions(new UploadFilterOptions(host).withTemporary(true));
        }
    };
    final SingleTransferWorker worker = new SingleTransferWorker(session, null, transfer, new TransferOptions(), new TransferSpeedometer(transfer), new DisabledTransferPrompt() {

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

        @Override
        public Future<TransferStatus> transfer(final TransferItem item, final TransferAction action) throws BackgroundException {
            return super.transfer(item, action);
        }
    };
    worker.prepare(test, local, new TransferStatus().exists(true), TransferAction.overwrite);
    assertNotNull(worker.getStatus().get(new TransferItem(test, local)));
    assertNotNull(worker.getStatus().get(new TransferItem(test, local)).getRename());
    worker.transfer(new TransferItem(test, local), TransferAction.overwrite);
    assertTrue(set.get());
    assertTrue(moved.get());
}
Also used : Delete(ch.cyberduck.core.features.Delete) Write(ch.cyberduck.core.features.Write) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) SingleTransferWorker(ch.cyberduck.core.worker.SingleTransferWorker) Move(ch.cyberduck.core.features.Move) StreamListener(ch.cyberduck.core.io.StreamListener) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) StatusOutputStream(ch.cyberduck.core.io.StatusOutputStream) UploadFilterOptions(ch.cyberduck.core.transfer.upload.UploadFilterOptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Find(ch.cyberduck.core.features.Find) Test(org.junit.Test)

Example 20 with DisabledNotificationService

use of ch.cyberduck.core.notification.DisabledNotificationService in project cyberduck by iterate-ch.

the class SDSSingleTransferWorkerTest method testDownloadVersioned.

@Test
public void testDownloadVersioned() throws Exception {
    final SDSNodeIdProvider fileid = new SDSNodeIdProvider(session);
    final Path room = new SDSDirectoryFeature(session, fileid).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus());
    final Path test = new Path(room, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Local localFile = new DefaultTemporaryFileService().create(test.getName());
    {
        final byte[] content = RandomUtils.nextBytes(39864);
        final TransferStatus writeStatus = new TransferStatus().withLength(content.length).withChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), new TransferStatus()));
        final StatusOutputStream<Node> out = new SDSMultipartWriteFeature(session, fileid).write(test, writeStatus, new DisabledConnectionCallback());
        assertNotNull(out);
        new StreamCopier(writeStatus, writeStatus).withLimit((long) content.length).transfer(new ByteArrayInputStream(content), out);
        out.close();
    }
    final byte[] content = RandomUtils.nextBytes(39864);
    final TransferStatus writeStatus = new TransferStatus().exists(true).withLength(content.length).withChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), new TransferStatus()));
    final StatusOutputStream<Node> out = new SDSMultipartWriteFeature(session, fileid).write(test, writeStatus, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(writeStatus, writeStatus).withLimit((long) content.length).transfer(new ByteArrayInputStream(content), out);
    out.close();
    final String versionId = test.attributes().getVersionId();
    assertEquals(versionId, new SDSAttributesFinderFeature(session, fileid).find(test).getVersionId());
    assertEquals(versionId, new DefaultAttributesFinderFeature(session).find(test).getVersionId());
    final Transfer t = new DownloadTransfer(new Host(new TestProtocol()), Collections.singletonList(new TransferItem(test, localFile)), new NullFilter<>());
    assertTrue(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()) {
    }.run(session));
    byte[] compare = new byte[content.length];
    assertArrayEquals(content, IOUtils.toByteArray(localFile.getInputStream()));
    test.attributes().setVersionId(versionId);
    assertEquals(versionId, new DefaultAttributesFinderFeature(session).find(test).getVersionId());
    new SDSDeleteFeature(session, fileid).delete(Arrays.asList(test, room), new DisabledLoginCallback(), new Delete.DisabledCallback());
    localFile.delete();
    session.close();
}
Also used : Delete(ch.cyberduck.core.features.Delete) SDSDeleteFeature(ch.cyberduck.core.sds.SDSDeleteFeature) TestProtocol(ch.cyberduck.core.TestProtocol) TransferAction(ch.cyberduck.core.transfer.TransferAction) Node(ch.cyberduck.core.sds.io.swagger.client.model.Node) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) SDSAttributesFinderFeature(ch.cyberduck.core.sds.SDSAttributesFinderFeature) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DefaultTemporaryFileService(ch.cyberduck.core.local.DefaultTemporaryFileService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) StatusOutputStream(ch.cyberduck.core.io.StatusOutputStream) Local(ch.cyberduck.core.Local) SDSMultipartWriteFeature(ch.cyberduck.core.sds.SDSMultipartWriteFeature) Host(ch.cyberduck.core.Host) SDSNodeIdProvider(ch.cyberduck.core.sds.SDSNodeIdProvider) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) DefaultAttributesFinderFeature(ch.cyberduck.core.shared.DefaultAttributesFinderFeature) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) SDSDirectoryFeature(ch.cyberduck.core.sds.SDSDirectoryFeature) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) TransferItem(ch.cyberduck.core.transfer.TransferItem) SHA256ChecksumCompute(ch.cyberduck.core.io.SHA256ChecksumCompute) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) AbstractSDSTest(ch.cyberduck.core.sds.AbstractSDSTest) IntegrationTest(ch.cyberduck.test.IntegrationTest) Test(org.junit.Test)

Aggregations

DisabledNotificationService (ch.cyberduck.core.notification.DisabledNotificationService)45 Test (org.junit.Test)44 DisabledTransferErrorCallback (ch.cyberduck.core.transfer.DisabledTransferErrorCallback)37 DisabledTransferPrompt (ch.cyberduck.core.transfer.DisabledTransferPrompt)37 Transfer (ch.cyberduck.core.transfer.Transfer)37 TransferOptions (ch.cyberduck.core.transfer.TransferOptions)37 TransferSpeedometer (ch.cyberduck.core.transfer.TransferSpeedometer)37 DisabledStreamListener (ch.cyberduck.core.io.DisabledStreamListener)36 UploadTransfer (ch.cyberduck.core.transfer.UploadTransfer)35 TransferItem (ch.cyberduck.core.transfer.TransferItem)32 TransferAction (ch.cyberduck.core.transfer.TransferAction)31 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)27 Delete (ch.cyberduck.core.features.Delete)26 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)25 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)25 Path (ch.cyberduck.core.Path)25 Local (ch.cyberduck.core.Local)23 IntegrationTest (ch.cyberduck.test.IntegrationTest)23 Host (ch.cyberduck.core.Host)21 DownloadTransfer (ch.cyberduck.core.transfer.DownloadTransfer)21