use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class SingleTransferWorkerTest method testDownloadPrepareOverride.
@Test
public void testDownloadPrepareOverride() throws Exception {
final Path child = new Path("/t/c", EnumSet.of(Path.Type.file));
final Path root = new Path("/t", EnumSet.of(Path.Type.directory));
final NullLocal local = new NullLocal("l") {
@Override
public boolean exists() {
return true;
}
@Override
public boolean isDirectory() {
return true;
}
@Override
public boolean isFile() {
return false;
}
@Override
public AttributedList<Local> list() {
return AttributedList.emptyList();
}
};
final Transfer t = new DownloadTransfer(new Host(new TestProtocol()), root, local) {
@Override
public void transfer(final Session<?> source, final Session<?> destination, final Path file, Local local, final TransferOptions options, final TransferStatus overall, final TransferStatus segment, final ConnectionCallback connectionCallback, final ProgressListener listener, final StreamListener streamListener) {
if (file.equals(root)) {
assertTrue(segment.isExists());
} else {
assertFalse(segment.isExists());
}
}
@Override
public AbstractDownloadFilter filter(final Session<?> source, final Session<?> destination, final TransferAction action, final ProgressListener listener) {
return super.filter(source, destination, action, listener).withAttributes(new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
return file.attributes();
}
});
}
};
final NullSession session = new NullSession(new Host(new TestProtocol())) {
@Override
public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
final AttributedList<Path> children = new AttributedList<Path>();
children.add(child);
return children;
}
};
final SingleTransferWorker worker = 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()) {
@Override
public Future<TransferStatus> transfer(final TransferItem item, final TransferAction action) throws BackgroundException {
if (item.remote.equals(root)) {
assertTrue(this.getCache().isCached(new TransferItem(root, local)));
}
super.transfer(new TransferItem(item.remote, new NullLocal("l")), action);
if (item.remote.equals(root)) {
assertFalse(this.getCache().isCached(new TransferItem(root, local)));
}
return null;
}
};
worker.run(session);
assertFalse(worker.getCache().isCached(new TransferItem(child, local)));
assertTrue(worker.getCache().isEmpty());
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class WriteAclWorkerTest method testRunNoFiles.
@Test
public void testRunNoFiles() throws Exception {
final Acl acl = new Acl();
final WriteAclWorker worker = new WriteAclWorker(Collections.<Path>emptyList(), acl, true, new DisabledProgressListener()) {
@Override
public void cleanup(final Boolean result) {
//
}
};
worker.run(new NullSession(new Host(new TestProtocol())) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(Class<T> type) {
if (type.equals(AclPermission.class)) {
return (T) new DefaultAclFeature() {
@Override
public Acl getPermission(final Path file) {
fail();
return null;
}
@Override
public void setPermission(final Path file, final Acl acl) {
fail();
}
@Override
public List<Acl.User> getAvailableAclUsers() {
throw new UnsupportedOperationException();
}
@Override
public List<Acl.Role> getAvailableAclRoles(final List<Path> files) {
throw new UnsupportedOperationException();
}
};
}
return super._getFeature(type);
}
});
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class WriteAclWorkerTest method testRunNew.
@Test
public void testRunNew() throws Exception {
final Acl acl = new Acl(new Acl.EmailUser(), new Acl.Role("r"));
final Path t = new Path("/t", EnumSet.of(Path.Type.file));
final AtomicBoolean set = new AtomicBoolean();
final WriteAclWorker worker = new WriteAclWorker(Collections.singletonList(t), acl, true, new DisabledProgressListener()) {
@Override
public void cleanup(final Boolean result) {
//
}
};
worker.run(new NullSession(new Host(new TestProtocol())) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(Class<T> type) {
if (type.equals(AclPermission.class)) {
return (T) new DefaultAclFeature() {
@Override
public Acl getPermission(final Path file) {
fail();
return null;
}
@Override
public void setPermission(final Path file, final Acl n) {
assertEquals(acl, n);
set.set(true);
}
@Override
public List<Acl.User> getAvailableAclUsers() {
throw new UnsupportedOperationException();
}
@Override
public List<Acl.Role> getAvailableAclRoles(final List<Path> files) {
throw new UnsupportedOperationException();
}
};
}
return super._getFeature(type);
}
});
assertTrue(set.get());
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class WriteAclWorkerTest method testRunEmpty.
@Test
public void testRunEmpty() throws Exception {
final Acl acl = new Acl();
final Path t = new Path("/t", EnumSet.of(Path.Type.file));
final WriteAclWorker worker = new WriteAclWorker(Collections.singletonList(t), acl, true, new DisabledProgressListener()) {
@Override
public void cleanup(final Boolean result) {
//
}
};
worker.run(new NullSession(new Host(new TestProtocol())) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(Class<T> type) {
if (type.equals(AclPermission.class)) {
return (T) new DefaultAclFeature() {
@Override
public Acl getPermission(final Path file) {
fail();
return null;
}
@Override
public void setPermission(final Path file, final Acl acl) {
assertEquals(Acl.EMPTY, acl);
}
@Override
public List<Acl.User> getAvailableAclUsers() {
throw new UnsupportedOperationException();
}
@Override
public List<Acl.Role> getAvailableAclRoles(final List<Path> files) {
throw new UnsupportedOperationException();
}
};
}
return super._getFeature(type);
}
});
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class WriteMetadataWorkerTest method testRunUpdated.
@Test
public void testRunUpdated() throws Exception {
final List<Path> files = new ArrayList<Path>();
final Path p = new Path("a", EnumSet.of(Path.Type.file));
files.add(p);
final Map<String, String> previous = new HashMap<String, String>();
previous.put("nullified", "hash");
previous.put("key", "v1");
p.attributes().setMetadata(previous);
final Map<String, String> updated = new HashMap<String, String>();
updated.put("nullified", null);
updated.put("key", "v2");
WriteMetadataWorker worker = new WriteMetadataWorker(files, updated, false, new DisabledProgressListener()) {
@Override
public void cleanup(final Boolean map) {
fail();
}
};
final AtomicBoolean call = new AtomicBoolean();
worker.run(new NullSession(new Host(new TestProtocol())) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(final Class<T> type) {
if (type == Metadata.class) {
return (T) new Metadata() {
@Override
public Map<String, String> getDefault(final Local local) {
return Collections.emptyMap();
}
@Override
public Map<String, String> getMetadata(final Path file) {
throw new UnsupportedOperationException();
}
@Override
public void setMetadata(final Path file, final TransferStatus status) {
assertTrue(status.getMetadata().containsKey("nullified"));
assertTrue(status.getMetadata().containsKey("key"));
assertEquals("v2", status.getMetadata().get("key"));
assertEquals("hash", status.getMetadata().get("nullified"));
call.set(true);
}
};
}
return super._getFeature(type);
}
});
assertTrue(call.get());
}
Aggregations