use of ch.cyberduck.core.NullTransferSession in project cyberduck by iterate-ch.
the class SkipFilterTest method testAccept.
@Test
public void testAccept() throws Exception {
SkipFilter f = new SkipFilter(new DisabledUploadSymlinkResolver(), new NullTransferSession(new Host(new TestProtocol())) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(Class<T> type) {
if (type == Find.class) {
return (T) new Find() {
@Override
public boolean find(Path file, final ListProgressListener listener) {
return true;
}
};
}
return super._getFeature(type);
}
});
assertFalse(f.accept(new Path("a", EnumSet.of(Path.Type.file)), new NullLocal("a") {
@Override
public boolean exists() {
return true;
}
}, new TransferStatus().exists(true)));
}
use of ch.cyberduck.core.NullTransferSession 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());
}
use of ch.cyberduck.core.NullTransferSession 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"))));
}
use of ch.cyberduck.core.NullTransferSession 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]);
}
use of ch.cyberduck.core.NullTransferSession in project cyberduck by iterate-ch.
the class OverwriteFilterTest method testPrepareDirectory.
@Test
public void testPrepareDirectory() throws Exception {
final HashMap<Path, Path> files = new HashMap<Path, Path>();
final Path source = new Path("a", EnumSet.of(Path.Type.directory));
source.attributes().setSize(1L);
final Path target = new Path("a", EnumSet.of(Path.Type.directory));
files.put(source, target);
OverwriteFilter f = new OverwriteFilter(new NullTransferSession(new Host(new TestProtocol())), new NullSession(new Host(new TestProtocol())), files);
final TransferStatus status = f.prepare(source, null, new TransferStatus(), new DisabledProgressListener());
assertEquals(0L, status.getLength());
}
Aggregations