Search in sources :

Example 1 with NullTransferSession

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

the class SkipFilterTest method testAccept.

@Test
public void testAccept() throws Exception {
    SkipFilter f = new SkipFilter(new DisabledUploadSymlinkResolver(), new NullTransferSession(new Host(new TestProtocol())) {

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

                    @Override
                    public boolean find(Path file, final ListProgressListener listener) {
                        return true;
                    }
                };
            }
            return super._getFeature(type);
        }
    });
    assertFalse(f.accept(new Path("a", EnumSet.of(Path.Type.file)), new NullLocal("a") {

        @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) Host(ch.cyberduck.core.Host) NullTransferSession(ch.cyberduck.core.NullTransferSession) 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 2 with NullTransferSession

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

the class TransferDictionaryTest method testSerializeComplete.

@Test
public void testSerializeComplete() throws Exception {
    // Test transfer to complete with existing directory
    final Host host = new Host(new TestProtocol());
    final Transfer t = new DownloadTransfer(host, new Path("/t", EnumSet.of(Path.Type.directory)), new NullLocal("t") {

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

        @Override
        public AttributedList<Local> list(final Filter<String> filter) {
            return AttributedList.emptyList();
        }

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

        @Override
        public boolean isDirectory() {
            return true;
        }
    });
    final NullSession session = new NullTransferSession(host);
    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);
    assertTrue(t.isComplete());
    final Transfer serialized = new TransferDictionary().deserialize(t.serialize(SerializerFactory.get()));
    assertNotSame(t, serialized);
    assertTrue(serialized.isComplete());
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) TestProtocol(ch.cyberduck.core.TestProtocol) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) SingleTransferWorker(ch.cyberduck.core.worker.SingleTransferWorker) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) NullTransferSession(ch.cyberduck.core.NullTransferSession) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) AttributedList(ch.cyberduck.core.AttributedList) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) NullLocal(ch.cyberduck.core.NullLocal) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) SyncTransfer(ch.cyberduck.core.transfer.SyncTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) TransferItem(ch.cyberduck.core.transfer.TransferItem) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) Test(org.junit.Test)

Example 3 with NullTransferSession

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

the class SyncTransferTest method testFilterMirror.

@Test
public void testFilterMirror() throws Exception {
    final Path p = new Path("t", EnumSet.of(Path.Type.directory));
    final Path a = new Path(p, "a", EnumSet.of(Path.Type.file));
    final Path b = new Path(p, "b", EnumSet.of(Path.Type.file));
    final PathCache cache = new PathCache(1);
    cache.put(p, new AttributedList<>(Arrays.asList(a, b)));
    SyncTransfer t = new SyncTransfer(new Host(new TestProtocol()), new TransferItem(p, new NullLocal(System.getProperty("java.io.tmpdir"), "t")));
    t.withCache(cache);
    final NullSession session = new NullTransferSession(new Host(new TestProtocol()));
    final TransferPathFilter filter = t.filter(session, null, TransferAction.mirror, new DisabledProgressListener());
    assertTrue(filter.accept(a, new NullLocal(System.getProperty("java.io.tmpdir"), "a") {

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

        @Override
        public LocalAttributes attributes() {
            return new LocalAttributes(this.getAbsolute()) {

                @Override
                public long getSize() {
                    return 1L;
                }
            };
        }
    }, new TransferStatus().exists(true)));
    assertTrue(filter.accept(b, new NullLocal(System.getProperty("java.io.tmpdir"), "b") {

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

        @Override
        public LocalAttributes attributes() {
            return new LocalAttributes(this.getAbsolute()) {

                @Override
                public long getSize() {
                    return 0L;
                }
            };
        }
    }, new TransferStatus().exists(true)));
    assertEquals(Comparison.local, t.compare(new TransferItem(a, new NullLocal(System.getProperty("java.io.tmpdir"), "a"))));
    assertEquals(Comparison.remote, t.compare(new TransferItem(b, new NullLocal(System.getProperty("java.io.tmpdir"), "b"))));
}
Also used : Path(ch.cyberduck.core.Path) PathCache(ch.cyberduck.core.PathCache) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) TestProtocol(ch.cyberduck.core.TestProtocol) LocalAttributes(ch.cyberduck.core.LocalAttributes) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) NullTransferSession(ch.cyberduck.core.NullTransferSession) NullLocal(ch.cyberduck.core.NullLocal) Test(org.junit.Test)

Example 4 with NullTransferSession

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

the class OverwriteFilterTest method testComplete.

@Test
public void testComplete() throws Exception {
    final HashMap<Path, Path> files = new HashMap<Path, Path>();
    final Path source = new Path("a", EnumSet.of(Path.Type.file));
    source.attributes().setSize(1L);
    source.attributes().setPermission(new Permission(777));
    final Long time = System.currentTimeMillis();
    source.attributes().setModificationDate(time);
    final boolean[] timestampWrite = new boolean[1];
    final boolean[] permissionWrite = new boolean[1];
    final Path target = new Path("a", EnumSet.of(Path.Type.file));
    files.put(source, target);
    final Host host = new Host(new TestProtocol());
    OverwriteFilter f = new OverwriteFilter(new NullTransferSession(host), new NullSession(host) {

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

                    @Override
                    public void setTimestamp(final Path file, final TransferStatus status) {
                        assertEquals(time, status.getTimestamp());
                        timestampWrite[0] = true;
                    }
                };
            }
            if (type.equals(UnixPermission.class)) {
                return (T) new DefaultUnixPermissionFeature() {

                    @Override
                    public void setUnixOwner(final Path file, final String owner) {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public void setUnixGroup(final Path file, final String group) {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public Permission getUnixPermission(final Path file) {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public void setUnixPermission(final Path file, final Permission permission) {
                        assertEquals(new Permission(777), permission);
                        permissionWrite[0] = true;
                    }
                };
            }
            return super._getFeature(type);
        }
    }, files, new UploadFilterOptions(host).withPermission(true).withTimestamp(true));
    final TransferStatus status = f.prepare(source, null, new TransferStatus(), new DisabledProgressListener());
    f.complete(source, null, new TransferOptions(), status, new DisabledProgressListener());
    assertFalse(permissionWrite[0]);
    assertFalse(timestampWrite[0]);
    status.setComplete();
    f.complete(source, null, new TransferOptions(), status, new DisabledProgressListener());
    assertTrue(permissionWrite[0]);
    assertTrue(timestampWrite[0]);
}
Also used : TestProtocol(ch.cyberduck.core.TestProtocol) HashMap(java.util.HashMap) NullSession(ch.cyberduck.core.NullSession) Timestamp(ch.cyberduck.core.features.Timestamp) NullTransferSession(ch.cyberduck.core.NullTransferSession) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) DefaultTimestampFeature(ch.cyberduck.core.shared.DefaultTimestampFeature) UnixPermission(ch.cyberduck.core.features.UnixPermission) Permission(ch.cyberduck.core.Permission) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) UploadFilterOptions(ch.cyberduck.core.transfer.upload.UploadFilterOptions) Host(ch.cyberduck.core.Host) UnixPermission(ch.cyberduck.core.features.UnixPermission) DefaultUnixPermissionFeature(ch.cyberduck.core.shared.DefaultUnixPermissionFeature) Test(org.junit.Test)

Example 5 with NullTransferSession

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

the class OverwriteFilterTest method testPrepareDirectory.

@Test
public void testPrepareDirectory() throws Exception {
    final HashMap<Path, Path> files = new HashMap<Path, Path>();
    final Path source = new Path("a", EnumSet.of(Path.Type.directory));
    source.attributes().setSize(1L);
    final Path target = new Path("a", EnumSet.of(Path.Type.directory));
    files.put(source, target);
    OverwriteFilter f = new OverwriteFilter(new NullTransferSession(new Host(new TestProtocol())), new NullSession(new Host(new TestProtocol())), files);
    final TransferStatus status = f.prepare(source, null, new TransferStatus(), new DisabledProgressListener());
    assertEquals(0L, status.getLength());
}
Also used : Path(ch.cyberduck.core.Path) NullTransferSession(ch.cyberduck.core.NullTransferSession) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) TestProtocol(ch.cyberduck.core.TestProtocol) HashMap(java.util.HashMap) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) Test(org.junit.Test)

Aggregations

Host (ch.cyberduck.core.Host)22 NullTransferSession (ch.cyberduck.core.NullTransferSession)22 Path (ch.cyberduck.core.Path)22 TestProtocol (ch.cyberduck.core.TestProtocol)22 Test (org.junit.Test)22 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)17 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)16 NullLocal (ch.cyberduck.core.NullLocal)13 NullSession (ch.cyberduck.core.NullSession)12 DisabledDownloadSymlinkResolver (ch.cyberduck.core.transfer.symlink.DisabledDownloadSymlinkResolver)10 AsciiRandomStringService (ch.cyberduck.core.AsciiRandomStringService)5 ListProgressListener (ch.cyberduck.core.ListProgressListener)4 Local (ch.cyberduck.core.Local)4 TransferOptions (ch.cyberduck.core.transfer.TransferOptions)4 LocalAttributes (ch.cyberduck.core.LocalAttributes)3 DefaultDownloadFeature (ch.cyberduck.core.shared.DefaultDownloadFeature)3 DownloadTransfer (ch.cyberduck.core.transfer.DownloadTransfer)3 Transfer (ch.cyberduck.core.transfer.Transfer)3 HashMap (java.util.HashMap)3 AbstractController (ch.cyberduck.core.AbstractController)2