Search in sources :

Example 1 with SearchFilter

use of ch.cyberduck.ui.browser.SearchFilter 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 2 with SearchFilter

use of ch.cyberduck.ui.browser.SearchFilter in project cyberduck by iterate-ch.

the class DropboxSearchFeatureTest method testSearch.

@Test
public void testSearch() throws Exception {
    final String name = new AlphanumericRandomStringService().random();
    final Path workdir = new DefaultHomeFinderService(session).find();
    final Path file = new Path(workdir, name, EnumSet.of(Path.Type.file));
    new DropboxTouchFeature(session).touch(file, new TransferStatus());
    final DropboxSearchFeature feature = new DropboxSearchFeature(session);
    assertTrue(feature.search(workdir, new SearchFilter(name), new DisabledListProgressListener()).contains(file));
    // Supports prefix matching only
    assertFalse(feature.search(workdir, new SearchFilter(StringUtils.substring(name, 2)), new DisabledListProgressListener()).contains(file));
    assertTrue(feature.search(workdir, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)), new DisabledListProgressListener()).contains(file));
    try {
        assertFalse(feature.search(new Path(workdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new SearchFilter(name), new DisabledListProgressListener()).contains(file));
    // fail();
    } catch (NotfoundException e) {
    // 
    }
    final Path subdir = new Path(workdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    new DropboxDirectoryFeature(session).mkdir(subdir, new TransferStatus());
    assertFalse(feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener()).contains(file));
    final Path filesubdir = new DropboxTouchFeature(session).touch(new Path(subdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
    {
        final AttributedList<Path> result = feature.search(workdir, new SearchFilter(filesubdir.getName()), new DisabledListProgressListener());
        assertTrue(result.contains(filesubdir));
        assertEquals(subdir, result.find(new SimplePathPredicate(filesubdir)).getParent());
    }
    new DropboxDeleteFeature(session).delete(Arrays.asList(file, filesubdir, subdir), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) NotfoundException(ch.cyberduck.core.exception.NotfoundException) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) SearchFilter(ch.cyberduck.ui.browser.SearchFilter) AttributedList(ch.cyberduck.core.AttributedList) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) SimplePathPredicate(ch.cyberduck.core.SimplePathPredicate) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractDropboxTest(ch.cyberduck.core.AbstractDropboxTest)

Example 3 with SearchFilter

use of ch.cyberduck.ui.browser.SearchFilter in project cyberduck by iterate-ch.

the class MantaSearchFeatureTest method testSearchNestedDirectory.

@Test
public void testSearchNestedDirectory() throws Exception {
    Assume.assumeTrue(session.getClient().existsAndIsAccessible(testPathPrefix.getAbsolute()));
    final String newDirectoryName = new AlphanumericRandomStringService().random();
    final String intermediateDirectoryName = new AlphanumericRandomStringService().random();
    final String intermediateFileName = new AlphanumericRandomStringService().random();
    final String nestedFileName = new AlphanumericRandomStringService().random();
    final Path newDirectory = new Path(testPathPrefix, newDirectoryName, TYPE_DIRECTORY);
    final Path intermediateDirectory = new Path(newDirectory, intermediateDirectoryName, TYPE_DIRECTORY);
    new MantaDirectoryFeature(session).mkdir(newDirectory, null);
    new MantaDirectoryFeature(session).mkdir(intermediateDirectory, null);
    new MantaTouchFeature(session).touch(new Path(newDirectory, intermediateFileName, TYPE_FILE), null);
    new MantaTouchFeature(session).touch(new Path(intermediateDirectory, nestedFileName, TYPE_FILE), null);
    final MantaSearchFeature s = new MantaSearchFeature(session);
    final AttributedList<Path> search = s.search(newDirectory, new NullFilter<>(), new DisabledListProgressListener());
    final Path foundIntermediateFile = search.find(f -> f.getName().equals(intermediateFileName) && f.getParent().getName().equals(newDirectoryName));
    final Path foundNestedFile = search.find(f -> f.getName().equals(nestedFileName) && f.getParent().getName().equals(intermediateDirectoryName));
    assertEquals(3, search.size());
    assertNotNull(foundIntermediateFile);
    assertNotNull(foundNestedFile);
    final AttributedList<Path> filteredIntermediateFileSearch = s.search(newDirectory, new SearchFilter(intermediateFileName), new DisabledListProgressListener());
    final Path foundFilteredIntermediateFile = search.find(f -> f.getName().equals(intermediateFileName) && f.getParent().getName().equals(newDirectoryName));
    assertEquals(1, filteredIntermediateFileSearch.size());
    assertNotNull(foundFilteredIntermediateFile);
    final AttributedList<Path> filteredNestedFileSearch = s.search(newDirectory, new Filter<Path>() {

        @Override
        public boolean accept(final Path file) {
            return file.isDirectory() || file.getName().matches(nestedFileName);
        }

        @Override
        public Pattern toPattern() {
            return Pattern.compile(nestedFileName);
        }
    }, new DisabledListProgressListener());
    final Path foundFilteredNestedFile = search.find(f -> f.getName().equals(nestedFileName) && f.getParent().getName().equals(intermediateDirectoryName));
    assertEquals(1, filteredNestedFileSearch.size());
    assertNotNull(foundFilteredNestedFile);
}
Also used : AbstractPath(ch.cyberduck.core.AbstractPath) Path(ch.cyberduck.core.Path) Pattern(java.util.regex.Pattern) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) SearchFilter(ch.cyberduck.ui.browser.SearchFilter) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 4 with SearchFilter

use of ch.cyberduck.ui.browser.SearchFilter in project cyberduck by iterate-ch.

the class B2SearchFeatureTest method testSearchInDirectory.

@Test
public void testSearchInDirectory() throws Exception {
    final String name = new AlphanumericRandomStringService().random();
    final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final B2VersionIdProvider fileid = new B2VersionIdProvider(session);
    final Path workdir = new B2DirectoryFeature(session, fileid).mkdir(new Path(bucket, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus());
    final Path file = new B2TouchFeature(session, fileid).touch(new Path(workdir, name, EnumSet.of(Path.Type.file)), new TransferStatus());
    final B2SearchFeature feature = new B2SearchFeature(session, fileid);
    assertNotNull(feature.search(workdir, new SearchFilter(name), new DisabledListProgressListener()).find(new SimplePathPredicate(file)));
    // Supports prefix matching only
    assertNull(feature.search(workdir, new SearchFilter(StringUtils.substring(name, 2)), new DisabledListProgressListener()).find(new SimplePathPredicate(file)));
    {
        final AttributedList<Path> result = feature.search(workdir, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)), new DisabledListProgressListener());
        assertNotNull(result.find(new SimplePathPredicate(file)));
        assertEquals(workdir, result.get(result.indexOf(file)).getParent());
    }
    final Path subdir = new B2DirectoryFeature(session, fileid).mkdir(new Path(workdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
    assertNull(feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener()).find(new SimplePathPredicate(file)));
    final Path filesubdir = new B2TouchFeature(session, fileid).touch(new Path(subdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
    {
        final AttributedList<Path> result = feature.search(workdir, new SearchFilter(filesubdir.getName()), new DisabledListProgressListener());
        assertNotNull(result.find(new SimplePathPredicate(filesubdir)));
        assertEquals(subdir, result.find(new SimplePathPredicate(filesubdir)).getParent());
    }
    new B2DeleteFeature(session, fileid).delete(Arrays.asList(file, filesubdir, subdir), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) SearchFilter(ch.cyberduck.ui.browser.SearchFilter) AttributedList(ch.cyberduck.core.AttributedList) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) SimplePathPredicate(ch.cyberduck.core.SimplePathPredicate) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 5 with SearchFilter

use of ch.cyberduck.ui.browser.SearchFilter in project cyberduck by iterate-ch.

the class B2SearchFeatureTest method testSearchInBucket.

@Test
public void testSearchInBucket() throws Exception {
    final String name = new AlphanumericRandomStringService().random();
    final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final B2VersionIdProvider fileid = new B2VersionIdProvider(session);
    final Path file = new B2TouchFeature(session, fileid).touch(new Path(bucket, name, EnumSet.of(Path.Type.file)), new TransferStatus());
    final B2SearchFeature feature = new B2SearchFeature(session, fileid);
    assertNotNull(feature.search(bucket, new SearchFilter(name), new DisabledListProgressListener()).find(new SimplePathPredicate(file)));
    // Supports prefix matching only
    assertNull(feature.search(bucket, new SearchFilter(StringUtils.substring(name, 2)), new DisabledListProgressListener()).find(new SimplePathPredicate(file)));
    assertNotNull(feature.search(bucket, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)), new DisabledListProgressListener()).find(new SimplePathPredicate(file)));
    final Path subdir = new Path(bucket, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    assertNull(feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener()).find(new SimplePathPredicate(file)));
    new B2DeleteFeature(session, fileid).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) SearchFilter(ch.cyberduck.ui.browser.SearchFilter) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) SimplePathPredicate(ch.cyberduck.core.SimplePathPredicate) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)15 Path (ch.cyberduck.core.Path)15 SearchFilter (ch.cyberduck.ui.browser.SearchFilter)15 Test (org.junit.Test)15 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)13 IntegrationTest (ch.cyberduck.test.IntegrationTest)13 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)12 Delete (ch.cyberduck.core.features.Delete)12 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)12 SimplePathPredicate (ch.cyberduck.core.SimplePathPredicate)9 AttributedList (ch.cyberduck.core.AttributedList)7 Host (ch.cyberduck.core.Host)2 NullSession (ch.cyberduck.core.NullSession)2 PathCache (ch.cyberduck.core.PathCache)2 TestProtocol (ch.cyberduck.core.TestProtocol)2 NotfoundException (ch.cyberduck.core.exception.NotfoundException)2 AbstractDropboxTest (ch.cyberduck.core.AbstractDropboxTest)1 AbstractPath (ch.cyberduck.core.AbstractPath)1 NullFilter (ch.cyberduck.core.NullFilter)1 Touch (ch.cyberduck.core.features.Touch)1