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