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))));
}
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());
}
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);
}
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());
}
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());
}
Aggregations