use of com.google.cloud.storage.Storage in project nifi by apache.
the class ListGCSBucketTest method testEmptyList.
@Test
public void testEmptyList() throws Exception {
reset(storage, mockBlobPages);
final ListGCSBucket processor = getProcessor();
final TestRunner runner = buildNewRunner(processor);
addRequiredPropertiesToRunner(runner);
runner.assertValid();
final Iterable<Blob> mockList = ImmutableList.of();
when(mockBlobPages.getValues()).thenReturn(mockList);
when(mockBlobPages.getNextPage()).thenReturn(null);
when(storage.list(anyString(), any(Storage.BlobListOption[].class))).thenReturn(mockBlobPages);
runner.enqueue("test");
runner.run();
runner.assertTransferCount(ListGCSBucket.REL_SUCCESS, 0);
assertEquals("No state should be persisted on an empty return", -1L, runner.getStateManager().getState(Scope.CLUSTER).getVersion());
}
use of com.google.cloud.storage.Storage in project nifi by apache.
the class ListGCSBucketTest method testAclOwnerProject.
@Test
public void testAclOwnerProject() throws Exception {
reset(storage, mockBlobPages);
final ListGCSBucket processor = getProcessor();
final TestRunner runner = buildNewRunner(processor);
addRequiredPropertiesToRunner(runner);
runner.assertValid();
final Blob blob = buildMockBlob("test-bucket-1", "test-key-1", 2L);
final Acl.Project mockProject = mock(Acl.Project.class);
when(mockProject.getProjectId()).thenReturn(OWNER_PROJECT_ID);
when(blob.getOwner()).thenReturn(mockProject);
final Iterable<Blob> mockList = ImmutableList.of(blob);
when(mockBlobPages.getValues()).thenReturn(mockList);
when(mockBlobPages.getNextPage()).thenReturn(null);
when(storage.list(anyString(), any(Storage.BlobListOption[].class))).thenReturn(mockBlobPages);
runner.enqueue("test");
runner.run();
runner.assertAllFlowFilesTransferred(FetchGCSObject.REL_SUCCESS);
runner.assertTransferCount(FetchGCSObject.REL_SUCCESS, 1);
final MockFlowFile flowFile = runner.getFlowFilesForRelationship(FetchGCSObject.REL_SUCCESS).get(0);
assertEquals(OWNER_PROJECT_ID, flowFile.getAttribute(OWNER_ATTR));
assertEquals("project", flowFile.getAttribute(OWNER_TYPE_ATTR));
}
use of com.google.cloud.storage.Storage in project nifi by apache.
the class ListGCSBucketTest method testAclOwnerUser.
@Test
public void testAclOwnerUser() throws Exception {
reset(storage, mockBlobPages);
final ListGCSBucket processor = getProcessor();
final TestRunner runner = buildNewRunner(processor);
addRequiredPropertiesToRunner(runner);
runner.assertValid();
final Blob blob = buildMockBlob("test-bucket-1", "test-key-1", 2L);
final Acl.User mockUser = mock(Acl.User.class);
when(mockUser.getEmail()).thenReturn(OWNER_USER_EMAIL);
when(blob.getOwner()).thenReturn(mockUser);
final Iterable<Blob> mockList = ImmutableList.of(blob);
when(mockBlobPages.getValues()).thenReturn(mockList);
when(mockBlobPages.getNextPage()).thenReturn(null);
when(storage.list(anyString(), any(Storage.BlobListOption[].class))).thenReturn(mockBlobPages);
runner.enqueue("test");
runner.run();
runner.assertAllFlowFilesTransferred(FetchGCSObject.REL_SUCCESS);
runner.assertTransferCount(FetchGCSObject.REL_SUCCESS, 1);
final MockFlowFile flowFile = runner.getFlowFilesForRelationship(FetchGCSObject.REL_SUCCESS).get(0);
assertEquals(OWNER_USER_EMAIL, flowFile.getAttribute(OWNER_ATTR));
assertEquals("user", flowFile.getAttribute(OWNER_TYPE_ATTR));
}
use of com.google.cloud.storage.Storage in project nifi by apache.
the class ListGCSBucketTest method testAclOwnerDomain.
@Test
public void testAclOwnerDomain() throws Exception {
reset(storage, mockBlobPages);
final ListGCSBucket processor = getProcessor();
final TestRunner runner = buildNewRunner(processor);
addRequiredPropertiesToRunner(runner);
runner.assertValid();
final Blob blob = buildMockBlob("test-bucket-1", "test-key-1", 2L);
final Acl.Domain mockDomain = mock(Acl.Domain.class);
when(mockDomain.getDomain()).thenReturn(OWNER_DOMAIN);
when(blob.getOwner()).thenReturn(mockDomain);
final Iterable<Blob> mockList = ImmutableList.of(blob);
when(mockBlobPages.getValues()).thenReturn(mockList);
when(mockBlobPages.getNextPage()).thenReturn(null);
when(storage.list(anyString(), any(Storage.BlobListOption[].class))).thenReturn(mockBlobPages);
runner.enqueue("test");
runner.run();
runner.assertAllFlowFilesTransferred(FetchGCSObject.REL_SUCCESS);
runner.assertTransferCount(FetchGCSObject.REL_SUCCESS, 1);
final MockFlowFile flowFile = runner.getFlowFilesForRelationship(FetchGCSObject.REL_SUCCESS).get(0);
assertEquals(OWNER_DOMAIN, flowFile.getAttribute(OWNER_ATTR));
assertEquals("domain", flowFile.getAttribute(OWNER_TYPE_ATTR));
}
use of com.google.cloud.storage.Storage in project java-docs-samples by GoogleCloudPlatform.
the class QuickstartSample method main.
public static void main(String... args) throws Exception {
// Instantiates a client
Storage storage = StorageOptions.getDefaultInstance().getService();
// The name for the new bucket
// "my-new-bucket";
String bucketName = args[0];
// Creates the new bucket
Bucket bucket = storage.create(BucketInfo.of(bucketName));
System.out.printf("Bucket %s created.%n", bucket.getName());
}
Aggregations