Search in sources :

Example 31 with NullSession

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

the class SynchronizationPathFilterTest method testPrepare.

@Test
public void testPrepare() throws Exception {
    final Path test = new Path("/t/a", EnumSet.of(Path.Type.file));
    Session session = new NullSession(new Host(new TestProtocol()));
    final NullLocal local = new NullLocal(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()) {

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

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

                @Override
                public long getSize() {
                    return 1L;
                }
            };
        }

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

        @Override
        public boolean exists() {
            return true;
        }
    };
    final SynchronizationPathFilter mirror = new SynchronizationPathFilter(new DefaultComparePathFilter(session, TimeZone.getDefault()), new OverwriteFilter(new DownloadSymlinkResolver(Collections.<TransferItem>emptyList()), session), new ch.cyberduck.core.transfer.upload.OverwriteFilter(new UploadSymlinkResolver(null, Collections.<TransferItem>emptyList()), session), TransferAction.mirror);
    assertTrue(mirror.accept(test, local, new TransferStatus().exists(true)));
    final TransferStatus status = mirror.prepare(test, local, new TransferStatus().exists(true), new DisabledProgressListener());
    assertNotNull(status);
    assertEquals(1L, status.getLength());
    final SynchronizationPathFilter download = new SynchronizationPathFilter(new DefaultComparePathFilter(session, TimeZone.getDefault()), new OverwriteFilter(new DownloadSymlinkResolver(Collections.<TransferItem>emptyList()), session), new ch.cyberduck.core.transfer.upload.OverwriteFilter(new UploadSymlinkResolver(null, Collections.<TransferItem>emptyList()), session), TransferAction.download);
    assertFalse(download.accept(test, local, new TransferStatus().exists(true)));
    final SynchronizationPathFilter upload = new SynchronizationPathFilter(new DefaultComparePathFilter(session, TimeZone.getDefault()), new OverwriteFilter(new DownloadSymlinkResolver(Collections.<TransferItem>emptyList()), session), new ch.cyberduck.core.transfer.upload.OverwriteFilter(new UploadSymlinkResolver(null, Collections.<TransferItem>emptyList()), session), TransferAction.upload);
    assertTrue(upload.accept(test, local, new TransferStatus().exists(true)));
}
Also used : Path(ch.cyberduck.core.Path) 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) DownloadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DownloadSymlinkResolver) DefaultComparePathFilter(ch.cyberduck.core.synchronization.DefaultComparePathFilter) NullLocal(ch.cyberduck.core.NullLocal) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) UploadSymlinkResolver(ch.cyberduck.core.transfer.symlink.UploadSymlinkResolver) OverwriteFilter(ch.cyberduck.core.transfer.download.OverwriteFilter) NullSession(ch.cyberduck.core.NullSession) Session(ch.cyberduck.core.Session) Test(org.junit.Test)

Example 32 with NullSession

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

the class CompareFilterTest method testAcceptDirectory.

@Test
public void testAcceptDirectory() throws Exception {
    final Host host = new Host(new TestProtocol());
    final CompareFilter filter = new CompareFilter(new DisabledUploadSymlinkResolver(), new NullSession(host), new UploadFilterOptions(host), new DisabledProgressListener(), new DefaultComparePathFilter(new NullSession(host), null) {

        @Override
        public Comparison compare(final Path file, final Local local, final ProgressListener listener) {
            return Comparison.equal;
        }
    });
    assertTrue(filter.accept(new Path("/n", EnumSet.of(Path.Type.directory)), new NullLocal("/n") {

        @Override
        public boolean exists() {
            return true;
        }
    }, new TransferStatus().exists(true)));
}
Also used : DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) Path(ch.cyberduck.core.Path) DisabledUploadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver) TestProtocol(ch.cyberduck.core.TestProtocol) NullSession(ch.cyberduck.core.NullSession) NullLocal(ch.cyberduck.core.NullLocal) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) DefaultComparePathFilter(ch.cyberduck.core.synchronization.DefaultComparePathFilter) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) ProgressListener(ch.cyberduck.core.ProgressListener) Comparison(ch.cyberduck.core.synchronization.Comparison) NullLocal(ch.cyberduck.core.NullLocal) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) Test(org.junit.Test)

Example 33 with NullSession

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

the class WritePermissionWorkerTest method testRunRecursiveRetainDirectoryExecute.

@Test
@Ignore
public void testRunRecursiveRetainDirectoryExecute() throws Exception {
    final PermissionOverwrite permission = new PermissionOverwrite(new PermissionOverwrite.Action(true, true, false), new PermissionOverwrite.Action(false, true, false), new PermissionOverwrite.Action(false, true, false));
    final Path a = new Path("a", EnumSet.of(Path.Type.directory), new TestPermissionAttributes(Permission.Action.all));
    final WritePermissionWorker worker = new WritePermissionWorker(Collections.singletonList(a), permission, new BooleanRecursiveCallback<Permission>(true), new DisabledProgressListener());
    worker.run(new NullSession(new Host(new TestProtocol())) {

        @Override
        public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
            if (file.equals(a)) {
                final AttributedList<Path> children = new AttributedList<Path>();
                final Path d = new Path("d", EnumSet.of(Path.Type.directory));
                d.attributes().setPermission(new Permission(744));
                children.add(d);
                children.add(new Path("f", EnumSet.of(Path.Type.file)));
                return children;
            }
            return AttributedList.emptyList();
        }

        @Override
        @SuppressWarnings("unchecked")
        public <T> T _getFeature(final Class<T> type) {
            if (type == 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) {
                        switch(file.getName()) {
                            case "a":
                                assertEquals(new Permission(644), permission);
                                break;
                            case "d":
                                assertEquals(new Permission(544), permission);
                                break;
                            case "f":
                                assertEquals(new Permission(644), permission);
                                break;
                            default:
                                fail();
                                break;
                        }
                    }
                };
            }
            return super._getFeature(type);
        }
    });
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) TestPermissionAttributes(ch.cyberduck.core.TestPermissionAttributes) TestProtocol(ch.cyberduck.core.TestProtocol) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) UnixPermission(ch.cyberduck.core.features.UnixPermission) DefaultUnixPermissionFeature(ch.cyberduck.core.shared.DefaultUnixPermissionFeature) AttributedList(ch.cyberduck.core.AttributedList) UnixPermission(ch.cyberduck.core.features.UnixPermission) Permission(ch.cyberduck.core.Permission) PermissionOverwrite(ch.cyberduck.core.PermissionOverwrite) ListProgressListener(ch.cyberduck.core.ListProgressListener) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 34 with NullSession

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

the class WritePermissionWorkerTest method testRetainStickyBit.

@Test
public void testRetainStickyBit() throws Exception {
    final PermissionOverwrite permission = new PermissionOverwrite(new PermissionOverwrite.Action(true, true, true), new PermissionOverwrite.Action(null, false, false), new PermissionOverwrite.Action(true, false, false));
    final Path path = new Path("a", EnumSet.of(Path.Type.directory));
    path.attributes().setPermission(new Permission(Permission.Action.none, Permission.Action.read, Permission.Action.none, true, false, false));
    final WritePermissionWorker worker = new WritePermissionWorker(Collections.singletonList(path), permission, new BooleanRecursiveCallback<Permission>(true), new DisabledProgressListener());
    worker.run(new NullSession(new Host(new TestProtocol())) {

        @Override
        public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
            final AttributedList<Path> children = new AttributedList<Path>();
            // File has all set
            children.add(new Path("b", EnumSet.of(Path.Type.file), new TestPermissionAttributes(Permission.Action.all)));
            return children;
        }

        @Override
        @SuppressWarnings("unchecked")
        public <T> T _getFeature(final Class<T> type) {
            if (type == 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(1744), permission);
                    }
                };
            }
            return super._getFeature(type);
        }
    });
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) TestProtocol(ch.cyberduck.core.TestProtocol) TestPermissionAttributes(ch.cyberduck.core.TestPermissionAttributes) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) UnixPermission(ch.cyberduck.core.features.UnixPermission) DefaultUnixPermissionFeature(ch.cyberduck.core.shared.DefaultUnixPermissionFeature) AttributedList(ch.cyberduck.core.AttributedList) UnixPermission(ch.cyberduck.core.features.UnixPermission) Permission(ch.cyberduck.core.Permission) PermissionOverwrite(ch.cyberduck.core.PermissionOverwrite) ListProgressListener(ch.cyberduck.core.ListProgressListener) Test(org.junit.Test)

Example 35 with NullSession

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

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