Search in sources :

Example 81 with Storage

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());
}
Also used : Blob(com.google.cloud.storage.Blob) Storage(com.google.cloud.storage.Storage) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 82 with Storage

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));
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) Blob(com.google.cloud.storage.Blob) Storage(com.google.cloud.storage.Storage) TestRunner(org.apache.nifi.util.TestRunner) Acl(com.google.cloud.storage.Acl) Test(org.junit.Test)

Example 83 with Storage

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));
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) Blob(com.google.cloud.storage.Blob) Storage(com.google.cloud.storage.Storage) TestRunner(org.apache.nifi.util.TestRunner) Acl(com.google.cloud.storage.Acl) Test(org.junit.Test)

Example 84 with Storage

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));
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) Blob(com.google.cloud.storage.Blob) Storage(com.google.cloud.storage.Storage) TestRunner(org.apache.nifi.util.TestRunner) Acl(com.google.cloud.storage.Acl) Test(org.junit.Test)

Example 85 with Storage

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());
}
Also used : Storage(com.google.cloud.storage.Storage) Bucket(com.google.cloud.storage.Bucket)

Aggregations

Storage (com.google.cloud.storage.Storage)140 Bucket (com.google.cloud.storage.Bucket)45 Blob (com.google.cloud.storage.Blob)44 Test (org.junit.Test)30 BlobId (com.google.cloud.storage.BlobId)24 BlobInfo (com.google.cloud.storage.BlobInfo)14 TestRunner (org.apache.nifi.util.TestRunner)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 Policy (com.google.cloud.Policy)9 ArrayList (java.util.ArrayList)8 Acl (com.google.cloud.storage.Acl)7 Date (java.util.Date)7 HashMap (java.util.HashMap)7 BucketInfo (com.google.cloud.storage.BucketInfo)6 HmacKeyMetadata (com.google.cloud.storage.HmacKey.HmacKeyMetadata)6 MockFlowFile (org.apache.nifi.util.MockFlowFile)6 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)5 Binding (com.google.cloud.Binding)5 WriteChannel (com.google.cloud.WriteChannel)4 IOException (java.io.IOException)4