use of ch.cyberduck.core.TestProtocol in project cyberduck by iterate-ch.
the class RenameExistingFilterTest method testApplyRename.
@Test
public void testApplyRename() throws Exception {
RenameExistingFilter f = new RenameExistingFilter(new DisabledDownloadSymlinkResolver(), new NullTransferSession(new Host(new TestProtocol())));
final String name = new AsciiRandomStringService().random();
final Local local = LocalFactory.get(System.getProperty("java.io.tmpdir"), name);
new DefaultLocalTouchFeature().touch(local);
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(RandomUtils.nextBytes(1)), local.getOutputStream(false));
final Path p = new Path(name, EnumSet.of(Path.Type.file));
final TransferStatus status = f.prepare(p, local, new TransferStatus().exists(true), new DisabledProgressListener());
assertTrue(status.isExists());
assertNull(status.getRename().local);
f.apply(p, local, status, new DisabledProgressListener());
assertEquals(name, local.getName());
assertFalse(status.isExists());
}
use of ch.cyberduck.core.TestProtocol in project cyberduck by iterate-ch.
the class RenameExistingFilterTest method testPrepare.
@Test
public void testPrepare() throws Exception {
final Host host = new Host(new TestProtocol());
final DownloadFilterOptions options = new DownloadFilterOptions(host);
options.icon = false;
RenameExistingFilter f = new RenameExistingFilter(new DisabledDownloadSymlinkResolver(), new NullTransferSession(host), options);
final String name = new AsciiRandomStringService().random();
final Local local = new NullLocal(System.getProperty("java.io.tmpdir"), name) {
@Override
public boolean exists() {
return false;
}
@Override
public void rename(final Local renamed) {
// Must not rename original file but copy
fail();
}
};
final Path p = new Path(name, EnumSet.of(Path.Type.file));
final TransferStatus status = f.prepare(p, local, new TransferStatus(), new DisabledProgressListener());
assertNull(status.getRename().local);
assertFalse(status.isExists());
f.apply(p, local, new TransferStatus(), new DisabledProgressListener());
}
use of ch.cyberduck.core.TestProtocol in project cyberduck by iterate-ch.
the class RenameFilterTest method testDirectoryDownload.
@Test
public void testDirectoryDownload() throws Exception {
RenameFilter f = new RenameFilter(new DisabledDownloadSymlinkResolver(), new NullTransferSession(new Host(new TestProtocol())));
final String name = new AsciiRandomStringService().random();
final NullLocal local = new NullLocal("/tmp", name) {
@Override
public boolean exists() {
return name.equals(this.getName());
}
@Override
public boolean isFile() {
return false;
}
@Override
public boolean isDirectory() {
return true;
}
};
final Path directory = new Path("t", EnumSet.of(Path.Type.directory));
final Path file = new Path(directory, name, EnumSet.of(Path.Type.file));
final TransferStatus directoryStatus = f.prepare(directory, local, new TransferStatus().exists(true), new DisabledProgressListener());
final TransferStatus fileStatus = f.prepare(file, new NullLocal(local, "f"), directoryStatus, new DisabledProgressListener());
assertNotNull(fileStatus.getRename().local);
final String s = System.getProperty("file.separator");
assertEquals(String.format("%stmp%st-1%s%s", s, s, s, name), fileStatus.getRename().local.getAbsolute());
}
use of ch.cyberduck.core.TestProtocol in project cyberduck by iterate-ch.
the class ResumeFilterTest method testPrepareDirectoryExistsFalse.
@Test
public void testPrepareDirectoryExistsFalse() throws Exception {
final Host host = new Host(new TestProtocol());
final NullSession session = new NullTransferSession(host);
ResumeFilter f = new ResumeFilter(new DisabledDownloadSymlinkResolver(), session, new DownloadFilterOptions(host), new DefaultDownloadFeature(session.getFeature(Read.class)) {
@Override
public boolean offset(final Path file) {
return true;
}
});
Path p = new Path("a", EnumSet.of(Path.Type.directory));
final NullLocal local = new NullLocal("a") {
@Override
public boolean exists() {
return false;
}
};
final TransferStatus status = f.prepare(p, local, new TransferStatus(), new DisabledProgressListener());
assertFalse(status.isAppend());
}
use of ch.cyberduck.core.TestProtocol in project cyberduck by iterate-ch.
the class ResumeFilterTest method testPrepareDirectoryExists.
@Test
public void testPrepareDirectoryExists() throws Exception {
final Host host = new Host(new TestProtocol());
final NullSession session = new NullTransferSession(host);
ResumeFilter f = new ResumeFilter(new DisabledDownloadSymlinkResolver(), session, new DownloadFilterOptions(host), new DefaultDownloadFeature(session.getFeature(Read.class)) {
@Override
public boolean offset(final Path file) {
return true;
}
});
Path p = new Path("a", EnumSet.of(Path.Type.directory));
final NullLocal local = new NullLocal("a") {
@Override
public boolean exists() {
return true;
}
@Override
public boolean isFile() {
return false;
}
@Override
public boolean isDirectory() {
return true;
}
};
final TransferStatus status = f.prepare(p, local, new TransferStatus().exists(true), new DisabledProgressListener());
assertTrue(status.isExists());
}
Aggregations