Search in sources :

Example 1 with DefaultTimestampFeature

use of ch.cyberduck.core.shared.DefaultTimestampFeature 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

DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)1 Host (ch.cyberduck.core.Host)1 NullSession (ch.cyberduck.core.NullSession)1 NullTransferSession (ch.cyberduck.core.NullTransferSession)1 Path (ch.cyberduck.core.Path)1 Permission (ch.cyberduck.core.Permission)1 TestProtocol (ch.cyberduck.core.TestProtocol)1 Timestamp (ch.cyberduck.core.features.Timestamp)1 UnixPermission (ch.cyberduck.core.features.UnixPermission)1 DefaultTimestampFeature (ch.cyberduck.core.shared.DefaultTimestampFeature)1 DefaultUnixPermissionFeature (ch.cyberduck.core.shared.DefaultUnixPermissionFeature)1 TransferOptions (ch.cyberduck.core.transfer.TransferOptions)1 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)1 UploadFilterOptions (ch.cyberduck.core.transfer.upload.UploadFilterOptions)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1