Search in sources :

Example 36 with NullSession

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

the class SyncTransferTest method testAction.

@Test
public void testAction() 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("p", "t") {

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

        @Override
        public AttributedList<Local> list() {
            return new AttributedList<Local>(Collections.<Local>singletonList(new NullLocal("p", "a")));
        }
    }));
    final AtomicBoolean prompt = new AtomicBoolean();
    final NullSession session = new NullSession(new Host(new TestProtocol()));
    assertNull(t.action(session, null, false, false, new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            prompt.set(true);
            return null;
        }
    }, new DisabledListProgressListener()));
    assertTrue(prompt.get());
}
Also used : Path(ch.cyberduck.core.Path) TestProtocol(ch.cyberduck.core.TestProtocol) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) NullLocal(ch.cyberduck.core.NullLocal) Local(ch.cyberduck.core.Local) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AttributedList(ch.cyberduck.core.AttributedList) NullLocal(ch.cyberduck.core.NullLocal) Test(org.junit.Test)

Example 37 with NullSession

use of ch.cyberduck.core.NullSession 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 38 with NullSession

use of ch.cyberduck.core.NullSession 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 39 with NullSession

use of ch.cyberduck.core.NullSession 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 40 with NullSession

use of ch.cyberduck.core.NullSession 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)

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