Java Code Examples for com.google.cloud.storage.Storage#BlobListOption

The following examples show how to use com.google.cloud.storage.Storage#BlobListOption . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListGCSBucketTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testListOptionsVersions() throws Exception {
    reset(storage, mockBlobPage);
    final ListGCSBucket processor = getProcessor();
    final TestRunner runner = buildNewRunner(processor);
    addRequiredPropertiesToRunner(runner);

    runner.setProperty(ListGCSBucket.USE_GENERATIONS, String.valueOf(USE_GENERATIONS));
    runner.assertValid();

    final Iterable<Blob> mockList = ImmutableList.of();

    when(mockBlobPage.getValues()).thenReturn(mockList);
    when(mockBlobPage.getNextPage()).thenReturn(null);
    when(storage.list(anyString(), argumentCaptor.capture())).thenReturn(mockBlobPage);

    runner.enqueue("test");
    runner.run();

    Storage.BlobListOption option = argumentCaptor.getValue();
    assertEquals(Storage.BlobListOption.versions(true), option);
}
 
Example 2
Source File: BucketAccessor.java    From aiven-kafka-connect-gcs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Get blob names with the prefix.
 *
 * <p>Doesn't support caching.
 */
public final List<String> getBlobNames(final String prefix) {
    Objects.requireNonNull(prefix, "prefix cannot be null");

    final Storage.BlobListOption blobListOption = Storage.BlobListOption.prefix(prefix);
    return StreamSupport.stream(storage.list(bucketName, blobListOption).iterateAll().spliterator(), false)
        .map(BlobInfo::getName)
        .sorted()
        .collect(Collectors.toList());
}
 
Example 3
Source File: ListGCSBucketTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testListOptionsVersions() throws Exception {
    reset(storage, mockBlobPages);
    final ListGCSBucket processor = getProcessor();
    final TestRunner runner = buildNewRunner(processor);
    addRequiredPropertiesToRunner(runner);

    runner.setProperty(
            ListGCSBucket.USE_GENERATIONS,
            String.valueOf(USE_GENERATIONS)
    );
    runner.assertValid();

    final Iterable<Blob> mockList = ImmutableList.of();

    when(mockBlobPages.getValues())
            .thenReturn(mockList);

    when(mockBlobPages.getNextPage()).thenReturn(null);

    when(storage.list(anyString(), argumentCaptor.capture()))
            .thenReturn(mockBlobPages);

    runner.enqueue("test");
    runner.run();

    Storage.BlobListOption option = argumentCaptor.getValue();

    assertEquals(
            Storage.BlobListOption.versions(true),
            option
    );
}