Search in sources :

Example 6 with NullSession

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

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

the class WriteAclWorkerTest method testRunNoFiles.

@Test
public void testRunNoFiles() throws Exception {
    final Acl acl = new Acl();
    final WriteAclWorker worker = new WriteAclWorker(Collections.<Path>emptyList(), acl, true, new DisabledProgressListener()) {

        @Override
        public void cleanup(final Boolean result) {
        // 
        }
    };
    worker.run(new NullSession(new Host(new TestProtocol())) {

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

                    @Override
                    public Acl getPermission(final Path file) {
                        fail();
                        return null;
                    }

                    @Override
                    public void setPermission(final Path file, final Acl acl) {
                        fail();
                    }

                    @Override
                    public List<Acl.User> getAvailableAclUsers() {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public List<Acl.Role> getAvailableAclRoles(final List<Path> files) {
                        throw new UnsupportedOperationException();
                    }
                };
            }
            return super._getFeature(type);
        }
    });
}
Also used : DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) Path(ch.cyberduck.core.Path) DefaultAclFeature(ch.cyberduck.core.shared.DefaultAclFeature) TestProtocol(ch.cyberduck.core.TestProtocol) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) Acl(ch.cyberduck.core.Acl) AclPermission(ch.cyberduck.core.features.AclPermission) List(java.util.List) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 8 with NullSession

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

the class WriteAclWorkerTest method testRunNew.

@Test
public void testRunNew() throws Exception {
    final Acl acl = new Acl(new Acl.EmailUser(), new Acl.Role("r"));
    final Path t = new Path("/t", EnumSet.of(Path.Type.file));
    final AtomicBoolean set = new AtomicBoolean();
    final WriteAclWorker worker = new WriteAclWorker(Collections.singletonList(t), acl, true, new DisabledProgressListener()) {

        @Override
        public void cleanup(final Boolean result) {
        // 
        }
    };
    worker.run(new NullSession(new Host(new TestProtocol())) {

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

                    @Override
                    public Acl getPermission(final Path file) {
                        fail();
                        return null;
                    }

                    @Override
                    public void setPermission(final Path file, final Acl n) {
                        assertEquals(acl, n);
                        set.set(true);
                    }

                    @Override
                    public List<Acl.User> getAvailableAclUsers() {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public List<Acl.Role> getAvailableAclRoles(final List<Path> files) {
                        throw new UnsupportedOperationException();
                    }
                };
            }
            return super._getFeature(type);
        }
    });
    assertTrue(set.get());
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DefaultAclFeature(ch.cyberduck.core.shared.DefaultAclFeature) TestProtocol(ch.cyberduck.core.TestProtocol) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) Acl(ch.cyberduck.core.Acl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AclPermission(ch.cyberduck.core.features.AclPermission) List(java.util.List) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 9 with NullSession

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

the class WriteAclWorkerTest method testRunEmpty.

@Test
public void testRunEmpty() throws Exception {
    final Acl acl = new Acl();
    final Path t = new Path("/t", EnumSet.of(Path.Type.file));
    final WriteAclWorker worker = new WriteAclWorker(Collections.singletonList(t), acl, true, new DisabledProgressListener()) {

        @Override
        public void cleanup(final Boolean result) {
        // 
        }
    };
    worker.run(new NullSession(new Host(new TestProtocol())) {

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

                    @Override
                    public Acl getPermission(final Path file) {
                        fail();
                        return null;
                    }

                    @Override
                    public void setPermission(final Path file, final Acl acl) {
                        assertEquals(Acl.EMPTY, acl);
                    }

                    @Override
                    public List<Acl.User> getAvailableAclUsers() {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public List<Acl.Role> getAvailableAclRoles(final List<Path> files) {
                        throw new UnsupportedOperationException();
                    }
                };
            }
            return super._getFeature(type);
        }
    });
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DefaultAclFeature(ch.cyberduck.core.shared.DefaultAclFeature) TestProtocol(ch.cyberduck.core.TestProtocol) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) Acl(ch.cyberduck.core.Acl) AclPermission(ch.cyberduck.core.features.AclPermission) List(java.util.List) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 10 with NullSession

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

the class WriteMetadataWorkerTest method testRunUpdated.

@Test
public void testRunUpdated() throws Exception {
    final List<Path> files = new ArrayList<Path>();
    final Path p = new Path("a", EnumSet.of(Path.Type.file));
    files.add(p);
    final Map<String, String> previous = new HashMap<String, String>();
    previous.put("nullified", "hash");
    previous.put("key", "v1");
    p.attributes().setMetadata(previous);
    final Map<String, String> updated = new HashMap<String, String>();
    updated.put("nullified", null);
    updated.put("key", "v2");
    WriteMetadataWorker worker = new WriteMetadataWorker(files, updated, false, new DisabledProgressListener()) {

        @Override
        public void cleanup(final Boolean map) {
            fail();
        }
    };
    final AtomicBoolean call = new AtomicBoolean();
    worker.run(new NullSession(new Host(new TestProtocol())) {

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

                    @Override
                    public Map<String, String> getDefault(final Local local) {
                        return Collections.emptyMap();
                    }

                    @Override
                    public Map<String, String> getMetadata(final Path file) {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public void setMetadata(final Path file, final TransferStatus status) {
                        assertTrue(status.getMetadata().containsKey("nullified"));
                        assertTrue(status.getMetadata().containsKey("key"));
                        assertEquals("v2", status.getMetadata().get("key"));
                        assertEquals("hash", status.getMetadata().get("nullified"));
                        call.set(true);
                    }
                };
            }
            return super._getFeature(type);
        }
    });
    assertTrue(call.get());
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) TestProtocol(ch.cyberduck.core.TestProtocol) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Metadata(ch.cyberduck.core.features.Metadata) NullSession(ch.cyberduck.core.NullSession) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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