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]);
}
Aggregations