use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class OverwriteFilterTest method testTemporary.
@Test
public void testTemporary() throws Exception {
final Host host = new Host(new TestProtocol());
final OverwriteFilter f = new OverwriteFilter(new DisabledUploadSymlinkResolver(), new NullSession(host), new UploadFilterOptions(host).withTemporary(true));
final Path file = new Path("/t", EnumSet.of(Path.Type.file));
final TransferStatus status = f.prepare(file, new NullLocal("t"), new TransferStatus(), new DisabledProgressListener());
assertNotNull(status.getRename());
assertNotEquals(file, status.getRename().remote);
assertNull(status.getRename().local);
assertNotNull(status.getRename().remote);
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class RenameExistingFilterTest method testAccept.
@Test
public void testAccept() throws Exception {
final RenameExistingFilter f = new RenameExistingFilter(new DisabledUploadSymlinkResolver(), new NullSession(new Host(new TestProtocol())));
final Path t = new Path("t", EnumSet.of(Path.Type.file));
assertTrue(f.accept(t, new NullLocal(System.getProperty("java.io.tmpdir"), "t") {
@Override
public boolean exists() {
return true;
}
}, new TransferStatus().exists(true)));
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class RenameExistingFilterTest method testPrepare.
@Test
public void testPrepare() throws Exception {
final AtomicBoolean c = new AtomicBoolean();
final RenameExistingFilter f = new RenameExistingFilter(new DisabledUploadSymlinkResolver(), new NullSession(new Host(new TestProtocol())) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(final Class<T> type) {
if (type == Move.class) {
return (T) new Move() {
@Override
public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) {
assertNotSame(file.getName(), renamed.getName());
c.set(true);
return renamed;
}
@Override
public boolean isRecursive(final Path source, final Path target) {
return true;
}
};
}
return super._getFeature(type);
}
@Override
public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
final AttributedList<Path> l = new AttributedList<Path>();
l.add(new Path("t", EnumSet.of(Path.Type.file)));
return l;
}
});
final Path p = new Path("t", EnumSet.of(Path.Type.file)) {
@Override
public Path getParent() {
return new Path("p", EnumSet.of(Path.Type.directory));
}
};
f.prepare(p, new NullLocal(System.getProperty("java.io.tmpdir"), "t"), new TransferStatus().exists(true), new DisabledProgressListener());
assertFalse(c.get());
f.apply(p, new NullLocal(System.getProperty("java.io.tmpdir"), "t"), new TransferStatus().exists(true), new DisabledProgressListener());
assertTrue(c.get());
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class RenameExistingFilterTest method testTemporaryFileUpload.
@Test
public void testTemporaryFileUpload() throws Exception {
final Path file = new Path("/t", EnumSet.of(Path.Type.file));
final AtomicBoolean found = new AtomicBoolean();
final AtomicInteger moved = new AtomicInteger();
final Find find = new Find() {
@Override
public boolean find(final Path f, final ListProgressListener listener) {
if (f.equals(file)) {
found.set(true);
return true;
}
return false;
}
};
final AttributesFinder attributes = new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
return new PathAttributes();
}
};
final Host host = new Host(new TestProtocol());
final NullSession session = new NullSession(host) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(final Class<T> type) {
if (type.equals(Move.class)) {
return (T) new Move() {
@Override
public Path move(final Path source, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) {
if (moved.incrementAndGet() == 1) {
// Rename existing target file
assertEquals(file, source);
} else if (moved.get() == 2) {
// Move temporary renamed file in place
assertEquals(file, renamed);
} else {
fail();
}
return renamed;
}
@Override
public boolean isRecursive(final Path source, final Path target) {
return true;
}
};
}
if (type.equals(Write.class)) {
return (T) new Write<Void>() {
@Override
public StatusOutputStream write(final Path file, final TransferStatus status, final ConnectionCallback callback) {
fail();
return null;
}
@Override
public Append append(final Path file, final TransferStatus status) {
fail();
return new Append(false);
}
};
}
return null;
}
};
final UploadFilterOptions options = new UploadFilterOptions(host).withTemporary(true);
final RenameExistingFilter f = new RenameExistingFilter(new DisabledUploadSymlinkResolver(), session, options);
f.withFinder(find).withAttributes(attributes);
assertTrue(options.temporary);
final TransferStatus status = f.prepare(file, new NullLocal("t"), new TransferStatus().exists(true), new DisabledProgressListener());
assertNotNull(status.getRename());
assertNotNull(status.getRename().remote);
assertNotEquals(file, status.getDisplayname().local);
assertNull(status.getRename().local);
f.apply(file, new NullLocal("t"), status, new DisabledProgressListener());
// Complete
status.setComplete();
f.complete(file, new NullLocal("t"), new TransferOptions(), status, new DisabledProgressListener());
assertTrue(found.get());
assertEquals(2, moved.get());
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class RenameFilterTest method testDirectoryUpload.
@Test
public void testDirectoryUpload() throws Exception {
final Path directory = new Path("/t", EnumSet.of(Path.Type.directory));
final Path file = new Path(directory, "f", EnumSet.of(Path.Type.file));
final AtomicBoolean found = new AtomicBoolean();
final AtomicBoolean moved = new AtomicBoolean();
final AttributesFinder attributes = new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
return new PathAttributes();
}
};
final Find find = new Find() {
@Override
public boolean find(final Path f, final ListProgressListener listener) {
if (f.equals(directory)) {
found.set(true);
return true;
}
return false;
}
};
final NullSession session = new NullSession(new Host(new TestProtocol()));
final RenameFilter f = new RenameFilter(new DisabledUploadSymlinkResolver(), session);
f.withFinder(find).withAttributes(attributes);
final TransferStatus directoryStatus = f.prepare(directory, new NullLocal("t"), new TransferStatus().exists(true), new DisabledProgressListener());
assertTrue(found.get());
assertNotNull(directoryStatus.getRename());
assertNull(directoryStatus.getRename().local);
assertNotNull(directoryStatus.getRename().remote);
final TransferStatus fileStatus = f.prepare(file, new NullLocal("t/f"), directoryStatus, new DisabledProgressListener());
assertNotNull(fileStatus.getRename());
assertNull(fileStatus.getRename().local);
assertNotNull(fileStatus.getRename().remote);
assertEquals(new Path("/t-1/f", EnumSet.of(Path.Type.file)), fileStatus.getRename().remote);
}
Aggregations