software.amazon.awssdk.services.s3.paginators.ListObjectsV2Iterable Java Examples

The following examples show how to use software.amazon.awssdk.services.s3.paginators.ListObjectsV2Iterable. 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: S3Helper.java    From realworld-serverless-application with Apache License 2.0 7 votes vote down vote up
public void emptyBucket(String bucketName){
  log.info("Emptying bucket {}", bucketName);

  ListObjectsV2Iterable listObjectsV2Responses = s3Client.listObjectsV2Paginator(ListObjectsV2Request.builder()
      .bucket(bucketName)
      .build());

  listObjectsV2Responses.stream()
      .flatMap(r -> r.contents().stream())
      .forEach(s3Object -> {
        log.info("deleting {}", s3Object.key());
        s3Client.deleteObject(DeleteObjectRequest.builder()
            .bucket(bucketName)
            .key(s3Object.key())
            .build());
      });
}
 
Example #2
Source File: AmazonWebServicesClientProxyTest.java    From cloudformation-cli-java-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public <ResultT extends AwsResponse, IterableT extends SdkIterable<ResultT>> void testInjectCredentialsAndInvokeV2Iterable() {

    final LoggerProxy loggerProxy = mock(LoggerProxy.class);
    final Credentials credentials = new Credentials("accessKeyId", "secretAccessKey", "sessionToken");
    final ListObjectsV2Iterable response = mock(ListObjectsV2Iterable.class);

    final AmazonWebServicesClientProxy proxy = new AmazonWebServicesClientProxy(loggerProxy, credentials, () -> 1000L);

    final software.amazon.awssdk.services.s3.model.ListObjectsV2Request wrappedRequest = mock(
        software.amazon.awssdk.services.s3.model.ListObjectsV2Request.class);

    final software.amazon.awssdk.services.s3.model.ListObjectsV2Request.Builder builder = mock(
        software.amazon.awssdk.services.s3.model.ListObjectsV2Request.Builder.class);
    when(builder.overrideConfiguration(any(AwsRequestOverrideConfiguration.class))).thenReturn(builder);
    when(builder.build()).thenReturn(wrappedRequest);
    final software.amazon.awssdk.services.s3.model.ListObjectsV2Request request = mock(
        software.amazon.awssdk.services.s3.model.ListObjectsV2Request.class);
    when(request.toBuilder()).thenReturn(builder);

    final S3Client client = mock(S3Client.class);

    when(client.listObjectsV2Paginator(any(software.amazon.awssdk.services.s3.model.ListObjectsV2Request.class)))
        .thenReturn(response);

    final ListObjectsV2Iterable result = proxy.injectCredentialsAndInvokeIterableV2(request, client::listObjectsV2Paginator);

    // verify request is rebuilt for injection
    verify(request).toBuilder();

    // verify the wrapped request is sent over the initiate
    verify(client).listObjectsV2Paginator(wrappedRequest);

    // ensure the return type matches
    assertThat(result).isEqualTo(response);
}
 
Example #3
Source File: ListObjectsV2PaginatorsIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void test_SyncResponse_onEmptyBucket() {
    ListObjectsV2Iterable iterable = s3.listObjectsV2Paginator(requestBuilder.bucket(emptyBucketName).build());

    assertThat(iterable.contents().stream().count(), equalTo(0L));

    assertThat(iterable.stream()
                       .flatMap(r -> r.contents() != null ? r.contents().stream() : Stream.empty())
                       .count(),
               equalTo(0L));
}
 
Example #4
Source File: ListObjectsV2PaginatorsIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void test_SyncResponse_onNonEmptyBucket() {
    ListObjectsV2Iterable iterable = s3.listObjectsV2Paginator(requestBuilder.bucket(bucketName).build());

    assertThat(iterable.contents().stream().count(), equalTo(OBJECT_COUNT));

    assertThat(iterable.stream().flatMap(r -> r.contents().stream()).count(), equalTo(OBJECT_COUNT));
}