use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class MoveWorkerTest method testCompile.
@Test
public void testCompile() throws Exception {
final Session session = new NullSession(new Host(new TestProtocol())) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(final Class<T> type) {
if (type == Delete.class) {
return (T) new Delete() {
private final AtomicInteger count = new AtomicInteger();
@Override
public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) {
for (Path file : files.keySet()) {
if (count.get() == 0) {
assertEquals(new Path("/t/d", EnumSet.of(Path.Type.directory)), file);
}
if (count.get() == 1) {
assertEquals(new Path("/t", EnumSet.of(Path.Type.directory)), file);
}
count.incrementAndGet();
}
}
@Override
public boolean isRecursive() {
return false;
}
};
}
if (type == Directory.class) {
return (T) new Directory<Void>() {
@Override
public Path mkdir(final Path folder, final TransferStatus status) {
return folder;
}
@Override
public Directory<Void> withWriter(final Write<Void> writer) {
return this;
}
};
}
if (type == Move.class) {
return (T) new Move() {
private final AtomicInteger count = new AtomicInteger();
@Override
public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) {
if (count.get() == 0) {
assertEquals(new Path("/t/a", EnumSet.of(Path.Type.file)), file);
assertEquals(new Path("/t2/a", EnumSet.of(Path.Type.file)), renamed);
}
if (count.get() == 1) {
assertEquals(new Path("/t/d/b", EnumSet.of(Path.Type.file)), file);
assertEquals(new Path("/t2/d/b", EnumSet.of(Path.Type.file)), renamed);
}
if (count.get() == 2) {
assertEquals(new Path("/t/d", EnumSet.of(Path.Type.directory)), file);
assertEquals(new Path("/t2/d", EnumSet.of(Path.Type.directory)), renamed);
}
if (count.get() == 3) {
assertEquals(new Path("/t", EnumSet.of(Path.Type.directory)), file);
assertEquals(new Path("/t2", EnumSet.of(Path.Type.directory)), renamed);
}
count.incrementAndGet();
return renamed;
}
@Override
public boolean isRecursive(final Path source, final Path target) {
return false;
}
};
}
return super._getFeature(type);
}
@Override
public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
if (file.equals(new Path("/t", EnumSet.of(Path.Type.directory)))) {
return new AttributedList<Path>(Arrays.asList(new Path("/t/a", EnumSet.of(Path.Type.file)), new Path("/t/d", EnumSet.of(Path.Type.directory))));
}
if (file.equals(new Path("/t/d", EnumSet.of(Path.Type.directory)))) {
return new AttributedList<Path>(Collections.singletonList(new Path("/t/d/b", EnumSet.of(Path.Type.file))));
}
if (file.equals(new Path("/", EnumSet.of(Path.Type.directory)))) {
return AttributedList.emptyList();
}
if (file.equals(new Path("/t2", EnumSet.of(Path.Type.directory)))) {
return AttributedList.emptyList();
}
if (file.equals(new Path("/t2/d", EnumSet.of(Path.Type.directory)))) {
return AttributedList.emptyList();
}
fail();
return null;
}
};
final MoveWorker worker = new MoveWorker(Collections.singletonMap(new Path("/t", EnumSet.of(Path.Type.directory)), new Path("/t2", EnumSet.of(Path.Type.directory))), new SessionPool.SingleSessionPool(session), PathCache.empty(), new DisabledProgressListener(), new DisabledLoginCallback());
final Collection<Path> targets = worker.run(session).values();
assertEquals(4, targets.size());
assertTrue(targets.contains(new Path("/t2", EnumSet.of(Path.Type.directory))));
assertTrue(targets.contains(new Path("/t2/a", EnumSet.of(Path.Type.file))));
assertTrue(targets.contains(new Path("/t2/d", EnumSet.of(Path.Type.directory))));
assertTrue(targets.contains(new Path("/t2/d/b", EnumSet.of(Path.Type.file))));
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class ReadMetadataWorkerTest method testDifferent.
@Test
public void testDifferent() throws Exception {
final List<Path> files = new ArrayList<Path>();
files.add(new Path("a", EnumSet.of(Path.Type.file)));
files.add(new Path("b", EnumSet.of(Path.Type.file)));
files.add(new Path("c", EnumSet.of(Path.Type.file)));
ReadMetadataWorker worker = new ReadMetadataWorker(files) {
@Override
public void cleanup(final Map<String, String> result) {
fail();
}
};
final Map<String, String> map = 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) {
switch(file.getName()) {
case "a":
return Collections.singletonMap("key1", "value1");
case "b":
return Collections.singletonMap("key2", "value2");
case "c":
return Collections.singletonMap("key2", "value2");
default:
fail();
break;
}
throw new UnsupportedOperationException();
}
@Override
public void setMetadata(final Path file, final TransferStatus status) {
throw new UnsupportedOperationException();
}
};
}
return super._getFeature(type);
}
});
assertTrue(map.containsKey("key1"));
assertTrue(map.containsKey("key2"));
assertNull(map.get("key1"));
assertNull(map.get("key2"));
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class ReadSizeWorkerTest method testRun.
@Test
public void testRun() throws Exception {
final Path d = new Path("/d", EnumSet.of(Path.Type.directory));
d.attributes().setSize(-1L);
final ReadSizeWorker worker = new ReadSizeWorker(Collections.singletonList(d)) {
@Override
public void cleanup(final Long result) {
//
}
};
assertEquals(0L, worker.run(new NullSession(new Host(new TestProtocol()))), 0L);
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class SearchWorkerTest method testRun.
@Test
public void testRun() throws Exception {
final PathCache cache = new PathCache(Integer.MAX_VALUE);
final AttributedList<Path> root = new AttributedList<>();
root.add(new Path("/t1.png", EnumSet.of(Path.Type.file)));
root.add(new Path("/t1.gif", EnumSet.of(Path.Type.file)));
final Path folder = new Path("/folder", EnumSet.of(Path.Type.directory));
root.add(folder);
root.add(new Path("/folder2", EnumSet.of(Path.Type.directory)));
cache.put(new Path("/", EnumSet.of(Path.Type.directory)), root);
final AttributedList<Path> folderContents = new AttributedList<>();
folderContents.add(new Path(folder, "/t2.png", EnumSet.of(Path.Type.file)));
folderContents.add(new Path(folder, "/t2.gif", EnumSet.of(Path.Type.file)));
final Path subfolder = new Path(folder, "/subfolder", EnumSet.of(Path.Type.directory));
folderContents.add(subfolder);
cache.put(folder, folderContents);
final AttributedList<Path> subfolderContents = new AttributedList<>();
subfolderContents.add(new Path(subfolder, "t2.png", EnumSet.of(Path.Type.file)));
subfolderContents.add(new Path(subfolder, "t2.gif", EnumSet.of(Path.Type.file)));
cache.put(subfolder, subfolderContents);
final SearchWorker search = new SearchWorker(new Path("/", EnumSet.of(Path.Type.directory)), new SearchFilter(".png"), cache, new DisabledListProgressListener());
final AttributedList<Path> found = search.run(new NullSession(new Host(new TestProtocol())));
assertTrue(found.contains(new Path("/t1.png", EnumSet.of(Path.Type.file))));
assertFalse(found.contains(new Path("/t1.gif", EnumSet.of(Path.Type.file))));
assertFalse(found.contains(new Path("/t2.png", EnumSet.of(Path.Type.file))));
assertFalse(found.contains(new Path("/t2.gif", EnumSet.of(Path.Type.file))));
assertTrue(found.contains(folder));
assertTrue(found.contains(new Path(folder, "/t2.png", EnumSet.of(Path.Type.file))));
assertTrue(found.contains(subfolder));
assertTrue(found.contains(new Path(subfolder, "/t2.png", EnumSet.of(Path.Type.file))));
assertFalse(found.contains(new Path(new Path("/folder2", EnumSet.of(Path.Type.directory)), "/t2.gif", EnumSet.of(Path.Type.file))));
assertFalse(found.contains(new Path("/folder2", EnumSet.of(Path.Type.directory))));
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class SynchronizationPathFilterTest method testAcceptDirectory.
@Test
public void testAcceptDirectory() throws Exception {
Session session = new NullSession(new Host(new TestProtocol()));
final SynchronizationPathFilter mirror = new SynchronizationPathFilter(new ComparePathFilter() {
@Override
public Comparison compare(Path file, Local local, final ProgressListener listener) {
return Comparison.equal;
}
}, 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(new Path("/p", EnumSet.of(Path.Type.directory)), null, new TransferStatus().exists(true)));
}
Aggregations