Search in sources :

Example 71 with TestProtocol

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

the class SyncTransferTest method testFilterDownload.

@Test
public void testFilterDownload() throws Exception {
    final Path p = new Path("t", EnumSet.of(Path.Type.directory));
    Transfer t = new SyncTransfer(new Host(new TestProtocol()), new TransferItem(p, new NullLocal(System.getProperty("java.io.tmpdir"), "t")));
    final NullSession session = new NullSession(new Host(new TestProtocol())) {

        @Override
        public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
            return AttributedList.emptyList();
        }
    };
    final TransferPathFilter filter = t.filter(session, null, TransferAction.download, new DisabledProgressListener());
    final Path test = new Path(p, "a", EnumSet.of(Path.Type.file));
    assertFalse(filter.accept(test, new NullLocal(System.getProperty("java.io.tmpdir"), "a"), new TransferStatus().exists(true)));
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) TestProtocol(ch.cyberduck.core.TestProtocol) NullLocal(ch.cyberduck.core.NullLocal) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) ListProgressListener(ch.cyberduck.core.ListProgressListener) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) Test(org.junit.Test)

Example 72 with TestProtocol

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

the class SyncTransferTest method testChildrenLocalOnly.

@Test
public void testChildrenLocalOnly() throws Exception {
    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 file, final ListProgressListener listener) {
            return AttributedList.emptyList();
        }
    };
    final NullLocal directory = new NullLocal(System.getProperty("java.io.tmpdir"), "t") {

        @Override
        public AttributedList<Local> list() {
            final AttributedList<Local> list = new AttributedList<Local>();
            list.add(new NullLocal(System.getProperty("java.io.tmpdir") + "/t", "a") {

                @Override
                public boolean exists() {
                    return true;
                }
            });
            return list;
        }
    };
    new DefaultLocalDirectoryFeature().mkdir(directory);
    Transfer t = new SyncTransfer(new Host(new TestProtocol()), new TransferItem(root, directory));
    final List<TransferItem> list = t.list(session, root, directory, new DisabledListProgressListener());
    assertEquals(1, list.size());
    final NullLocal local = new NullLocal(System.getProperty("java.io.tmpdir"), "a") {

        @Override
        public boolean exists() {
            return true;
        }
    };
    assertFalse(t.filter(session, null, TransferAction.download, new DisabledProgressListener()).accept(root, local, new TransferStatus().exists(true)));
    assertTrue(t.filter(session, null, TransferAction.upload, new DisabledProgressListener()).accept(root, local, new TransferStatus().exists(true)));
    assertTrue(t.filter(session, null, TransferAction.mirror, new DisabledProgressListener()).accept(root, local, new TransferStatus().exists(true)));
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) TestProtocol(ch.cyberduck.core.TestProtocol) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) NullSession(ch.cyberduck.core.NullSession) NullLocal(ch.cyberduck.core.NullLocal) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) AttributedList(ch.cyberduck.core.AttributedList) NullLocal(ch.cyberduck.core.NullLocal) DefaultLocalDirectoryFeature(ch.cyberduck.core.local.DefaultLocalDirectoryFeature) ListProgressListener(ch.cyberduck.core.ListProgressListener) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) Test(org.junit.Test)

Example 73 with TestProtocol

use of ch.cyberduck.core.TestProtocol 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 74 with TestProtocol

use of ch.cyberduck.core.TestProtocol 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 75 with TestProtocol

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

the class OverwriteFilterTest method testAcceptDirectoryNew.

@Test
public void testAcceptDirectoryNew() throws Exception {
    final HashMap<Path, Path> files = new HashMap<Path, Path>();
    final Path source = new Path("a", EnumSet.of(Path.Type.directory));
    files.put(source, new Path("a", EnumSet.of(Path.Type.directory)));
    AbstractCopyFilter f = new OverwriteFilter(new NullSession(new Host(new TestProtocol())), new NullSession(new Host(new TestProtocol())), files);
    assertTrue(f.accept(source, null, new TransferStatus()));
}
Also used : Path(ch.cyberduck.core.Path) 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

TestProtocol (ch.cyberduck.core.TestProtocol)253 Test (org.junit.Test)251 Host (ch.cyberduck.core.Host)230 Path (ch.cyberduck.core.Path)173 NullSession (ch.cyberduck.core.NullSession)131 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)107 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)96 Local (ch.cyberduck.core.Local)79 NullLocal (ch.cyberduck.core.NullLocal)76 ListProgressListener (ch.cyberduck.core.ListProgressListener)44 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)35 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)34 AttributedList (ch.cyberduck.core.AttributedList)33 ProtocolFactory (ch.cyberduck.core.ProtocolFactory)29 Transfer (ch.cyberduck.core.transfer.Transfer)28 DisabledUploadSymlinkResolver (ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver)28 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)27 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)27 VaultCredentials (ch.cyberduck.core.vault.VaultCredentials)27 UploadTransfer (ch.cyberduck.core.transfer.UploadTransfer)25