Search in sources :

Example 26 with NullSession

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))));
}
Also used : Delete(ch.cyberduck.core.features.Delete) TestProtocol(ch.cyberduck.core.TestProtocol) NullSession(ch.cyberduck.core.NullSession) Move(ch.cyberduck.core.features.Move) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) PasswordCallback(ch.cyberduck.core.PasswordCallback) ListProgressListener(ch.cyberduck.core.ListProgressListener) Directory(ch.cyberduck.core.features.Directory) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) SessionPool(ch.cyberduck.core.pool.SessionPool) Host(ch.cyberduck.core.Host) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) PasswordCallback(ch.cyberduck.core.PasswordCallback) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) AttributedList(ch.cyberduck.core.AttributedList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) NullSession(ch.cyberduck.core.NullSession) Session(ch.cyberduck.core.Session) Test(org.junit.Test)

Example 27 with NullSession

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"));
}
Also used : Path(ch.cyberduck.core.Path) TestProtocol(ch.cyberduck.core.TestProtocol) ArrayList(java.util.ArrayList) Metadata(ch.cyberduck.core.features.Metadata) NullSession(ch.cyberduck.core.NullSession) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 28 with NullSession

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);
}
Also used : Path(ch.cyberduck.core.Path) TestProtocol(ch.cyberduck.core.TestProtocol) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) Test(org.junit.Test)

Example 29 with NullSession

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))));
}
Also used : PathCache(ch.cyberduck.core.PathCache) Path(ch.cyberduck.core.Path) TestProtocol(ch.cyberduck.core.TestProtocol) AttributedList(ch.cyberduck.core.AttributedList) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) NullSession(ch.cyberduck.core.NullSession) SearchFilter(ch.cyberduck.ui.browser.SearchFilter) Host(ch.cyberduck.core.Host) Test(org.junit.Test)

Example 30 with NullSession

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)));
}
Also used : Path(ch.cyberduck.core.Path) ComparePathFilter(ch.cyberduck.core.synchronization.ComparePathFilter) DefaultComparePathFilter(ch.cyberduck.core.synchronization.DefaultComparePathFilter) TestProtocol(ch.cyberduck.core.TestProtocol) NullSession(ch.cyberduck.core.NullSession) NullLocal(ch.cyberduck.core.NullLocal) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) DownloadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DownloadSymlinkResolver) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) ProgressListener(ch.cyberduck.core.ProgressListener) Comparison(ch.cyberduck.core.synchronization.Comparison) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) UploadSymlinkResolver(ch.cyberduck.core.transfer.symlink.UploadSymlinkResolver) OverwriteFilter(ch.cyberduck.core.transfer.download.OverwriteFilter) NullSession(ch.cyberduck.core.NullSession) Session(ch.cyberduck.core.Session) Test(org.junit.Test)

Aggregations

Host (ch.cyberduck.core.Host)128 NullSession (ch.cyberduck.core.NullSession)128 TestProtocol (ch.cyberduck.core.TestProtocol)128 Test (org.junit.Test)127 Path (ch.cyberduck.core.Path)118 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)81 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)69 NullLocal (ch.cyberduck.core.NullLocal)59 ListProgressListener (ch.cyberduck.core.ListProgressListener)40 AttributedList (ch.cyberduck.core.AttributedList)32 DisabledUploadSymlinkResolver (ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver)27 Local (ch.cyberduck.core.Local)24 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)24 ConnectionCallback (ch.cyberduck.core.ConnectionCallback)19 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)18 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)17 Session (ch.cyberduck.core.Session)17 VaultCredentials (ch.cyberduck.core.vault.VaultCredentials)17 HashMap (java.util.HashMap)14 LocalAttributes (ch.cyberduck.core.LocalAttributes)13