use of ch.cyberduck.core.TestProtocol in project cyberduck by iterate-ch.
the class SyncTransferTest method testFilterDownload.
@Test
public void testFilterDownload() throws Exception {
final Path p = new Path("t", EnumSet.of(Path.Type.directory));
Transfer t = new SyncTransfer(new Host(new TestProtocol()), new TransferItem(p, new NullLocal(System.getProperty("java.io.tmpdir"), "t")));
final NullSession session = new NullSession(new Host(new TestProtocol())) {
@Override
public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
return AttributedList.emptyList();
}
};
final TransferPathFilter filter = t.filter(session, null, TransferAction.download, new DisabledProgressListener());
final Path test = new Path(p, "a", EnumSet.of(Path.Type.file));
assertFalse(filter.accept(test, new NullLocal(System.getProperty("java.io.tmpdir"), "a"), new TransferStatus().exists(true)));
}
use of ch.cyberduck.core.TestProtocol in project cyberduck by iterate-ch.
the class SyncTransferTest method testChildrenLocalOnly.
@Test
public void testChildrenLocalOnly() throws Exception {
final Path root = new Path("t", EnumSet.of(Path.Type.directory));
final NullSession session = new NullSession(new Host(new TestProtocol())) {
@Override
public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
return AttributedList.emptyList();
}
};
final NullLocal directory = new NullLocal(System.getProperty("java.io.tmpdir"), "t") {
@Override
public AttributedList<Local> list() {
final AttributedList<Local> list = new AttributedList<Local>();
list.add(new NullLocal(System.getProperty("java.io.tmpdir") + "/t", "a") {
@Override
public boolean exists() {
return true;
}
});
return list;
}
};
new DefaultLocalDirectoryFeature().mkdir(directory);
Transfer t = new SyncTransfer(new Host(new TestProtocol()), new TransferItem(root, directory));
final List<TransferItem> list = t.list(session, root, directory, new DisabledListProgressListener());
assertEquals(1, list.size());
final NullLocal local = new NullLocal(System.getProperty("java.io.tmpdir"), "a") {
@Override
public boolean exists() {
return true;
}
};
assertFalse(t.filter(session, null, TransferAction.download, new DisabledProgressListener()).accept(root, local, new TransferStatus().exists(true)));
assertTrue(t.filter(session, null, TransferAction.upload, new DisabledProgressListener()).accept(root, local, new TransferStatus().exists(true)));
assertTrue(t.filter(session, null, TransferAction.mirror, new DisabledProgressListener()).accept(root, local, new TransferStatus().exists(true)));
}
use of ch.cyberduck.core.TestProtocol 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.TestProtocol 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.TestProtocol in project cyberduck by iterate-ch.
the class OverwriteFilterTest method testAcceptDirectoryNew.
@Test
public void testAcceptDirectoryNew() throws Exception {
final HashMap<Path, Path> files = new HashMap<Path, Path>();
final Path source = new Path("a", EnumSet.of(Path.Type.directory));
files.put(source, new Path("a", EnumSet.of(Path.Type.directory)));
AbstractCopyFilter f = new OverwriteFilter(new NullSession(new Host(new TestProtocol())), new NullSession(new Host(new TestProtocol())), files);
assertTrue(f.accept(source, null, new TransferStatus()));
}
Aggregations