diff --git a/README.md b/README.md index 65b0f49823..b4f0930dd3 100644 --- a/README.md +++ b/README.md @@ -240,9 +240,11 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-storage/tree/ | Change Default Storage Class | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/ChangeDefaultStorageClass.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/ChangeDefaultStorageClass.java) | | Configure Bucket Cors | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/ConfigureBucketCors.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/ConfigureBucketCors.java) | | Create Bucket | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucket.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/CreateBucket.java) | +| Create Bucket Pub Sub Notification | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketPubSubNotification.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketPubSubNotification.java) | | Create Bucket With Storage Class And Location | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithStorageClassAndLocation.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithStorageClassAndLocation.java) | | Create Bucket With Turbo Replication | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithTurboReplication.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithTurboReplication.java) | | Delete Bucket | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucket.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucket.java) | +| Delete Bucket Pub Sub Notification | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucketPubSubNotification.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucketPubSubNotification.java) | | Disable Bucket Versioning | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/DisableBucketVersioning.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/DisableBucketVersioning.java) | | Disable Default Event Based Hold | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/DisableDefaultEventBasedHold.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/DisableDefaultEventBasedHold.java) | | Disable Lifecycle Management | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/DisableLifecycleManagement.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/DisableLifecycleManagement.java) | @@ -262,10 +264,12 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-storage/tree/ | Get Uniform Bucket Level Access | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/GetUniformBucketLevelAccess.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/GetUniformBucketLevelAccess.java) | | List Bucket Iam Members | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/ListBucketIamMembers.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/ListBucketIamMembers.java) | | List Buckets | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/ListBuckets.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/ListBuckets.java) | +| List Pub Sub Notifications | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/ListPubSubNotifications.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/ListPubSubNotifications.java) | | Lock Retention Policy | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/LockRetentionPolicy.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/LockRetentionPolicy.java) | | Make Bucket Public | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/MakeBucketPublic.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/MakeBucketPublic.java) | | Print Bucket Acl | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/PrintBucketAcl.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/PrintBucketAcl.java) | | Print Bucket Acl Filter By User | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/PrintBucketAclFilterByUser.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/PrintBucketAclFilterByUser.java) | +| Print Pub Sub Notification | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/PrintPubSubNotification.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/PrintPubSubNotification.java) | | Remove Bucket Cors | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/RemoveBucketCors.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/RemoveBucketCors.java) | | Remove Bucket Default Kms Key | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/RemoveBucketDefaultKmsKey.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/RemoveBucketDefaultKmsKey.java) | | Remove Bucket Default Owner | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/RemoveBucketDefaultOwner.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/RemoveBucketDefaultOwner.java) | diff --git a/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketPubSubNotification.java b/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketPubSubNotification.java index f79fff8a00..020eaa306a 100644 --- a/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketPubSubNotification.java +++ b/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketPubSubNotification.java @@ -18,23 +18,23 @@ // [START storage_create_bucket_notifications] -import com.google.cloud.storage.Bucket; -import com.google.cloud.storage.Storage; -import com.google.cloud.storage.StorageOptions; import com.google.cloud.storage.Notification; import com.google.cloud.storage.NotificationInfo; - +import com.google.cloud.storage.Storage; +import com.google.cloud.storage.StorageOptions; public class CreateBucketPubSubNotification { - public static void createBucketPubSubNotification(String bucketName, NotificationInfo notificationInfo) { + public static void createBucketPubSubNotification( + String bucketName, NotificationInfo notificationInfo) { // The ID to give your GCS bucket // String bucketName = "your-unique-bucket-name"; // The NotificationInfo for the notification you would like to create - // See: https://cloud.google.com/java/docs/reference/google-cloud-notification/latest/com.google.cloud.notification.NotificationInfo + // See: + // https://cloud.google.com/java/docs/reference/google-cloud-notification/latest/com.google.cloud.notification.NotificationInfo Storage storage = StorageOptions.newBuilder().build().getService(); Notification notification = storage.createNotification(bucketName, notificationInfo); System.out.println("Successfully created notification for topic " + notification.getTopic()); } } -// [END storage_create_bucket_notifications] \ No newline at end of file +// [END storage_create_bucket_notifications] diff --git a/samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucketPubSubNotification.java b/samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucketPubSubNotification.java index c392d0266d..9787fc8e2d 100644 --- a/samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucketPubSubNotification.java +++ b/samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucketPubSubNotification.java @@ -18,11 +18,9 @@ // [START storage_delete_bucket_notification] -import com.google.cloud.storage.Bucket; import com.google.cloud.storage.Storage; import com.google.cloud.storage.StorageOptions; - public class DeleteBucketPubSubNotification { public static void deleteBucketPubSubNotification(String bucketName, String notificationId) { @@ -32,11 +30,11 @@ public static void deleteBucketPubSubNotification(String bucketName, String noti // String notificationId = "your-unique-notification-id" Storage storage = StorageOptions.newBuilder().build().getService(); boolean success = storage.deleteNotification(bucketName, notificationId); - if(success) { + if (success) { System.out.println("Successfully deleted notification"); } else { System.out.println("Failed to find notification"); } } } -// [END storage_delete_bucket_notification] \ No newline at end of file +// [END storage_delete_bucket_notification] diff --git a/samples/snippets/src/main/java/com/example/storage/bucket/ListPubSubNotifications.java b/samples/snippets/src/main/java/com/example/storage/bucket/ListPubSubNotifications.java index 7bfb662a80..e359793f96 100644 --- a/samples/snippets/src/main/java/com/example/storage/bucket/ListPubSubNotifications.java +++ b/samples/snippets/src/main/java/com/example/storage/bucket/ListPubSubNotifications.java @@ -18,13 +18,11 @@ // [START storage_list_bucket_notifications] -import com.google.cloud.storage.Bucket; +import com.google.cloud.storage.Notification; import com.google.cloud.storage.Storage; import com.google.cloud.storage.StorageOptions; -import com.google.cloud.storage.Notification; import java.util.List; - public class ListPubSubNotifications { public static void listPubSubNotifications(String bucketName) { @@ -32,9 +30,10 @@ public static void listPubSubNotifications(String bucketName) { // String bucketName = "your-unique-bucket-name"; Storage storage = StorageOptions.newBuilder().build().getService(); List notificationList = storage.listNotifications(bucketName); - for(Notification notification : notificationList) { - System.out.println("Found notification " + notification.getTopic() + " for bucket "+ bucketName); + for (Notification notification : notificationList) { + System.out.println( + "Found notification " + notification.getTopic() + " for bucket " + bucketName); } } } -// [END storage_list_bucket_notifications] \ No newline at end of file +// [END storage_list_bucket_notifications] diff --git a/samples/snippets/src/main/java/com/example/storage/bucket/PrintPubSubNotification.java b/samples/snippets/src/main/java/com/example/storage/bucket/PrintPubSubNotification.java index 402767767c..bac131bec7 100644 --- a/samples/snippets/src/main/java/com/example/storage/bucket/PrintPubSubNotification.java +++ b/samples/snippets/src/main/java/com/example/storage/bucket/PrintPubSubNotification.java @@ -18,12 +18,9 @@ // [START storage_print_pubsub_bucket_notification] -import com.google.cloud.storage.Bucket; +import com.google.cloud.storage.Notification; import com.google.cloud.storage.Storage; import com.google.cloud.storage.StorageOptions; -import com.google.cloud.storage.Notification; -import java.util.List; - public class PrintPubSubNotification { @@ -35,7 +32,8 @@ public static void printPubSubNotification(String bucketName, String notificatio Storage storage = StorageOptions.newBuilder().build().getService(); Notification notification = storage.getNotification(bucketName, notificationId); - System.out.println("Found notification " + notification.getTopic() + " for bucket "+ bucketName); + System.out.println( + "Found notification " + notification.getTopic() + " for bucket " + bucketName); } } -// [END storage_print_pubsub_bucket_notification] \ No newline at end of file +// [END storage_print_pubsub_bucket_notification] diff --git a/samples/snippets/src/test/java/com/example/storage/bucket/CreateBucketPubSubNotificationTest.java b/samples/snippets/src/test/java/com/example/storage/bucket/CreateBucketPubSubNotificationTest.java index c3e4804337..1b1d144843 100644 --- a/samples/snippets/src/test/java/com/example/storage/bucket/CreateBucketPubSubNotificationTest.java +++ b/samples/snippets/src/test/java/com/example/storage/bucket/CreateBucketPubSubNotificationTest.java @@ -19,8 +19,8 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertNotNull; -import com.google.cloud.pubsub.v1.TopicAdminClient; import com.example.storage.TestBase; +import com.google.cloud.pubsub.v1.TopicAdminClient; import com.google.cloud.storage.Notification; import com.google.cloud.storage.NotificationInfo; import com.google.common.collect.ImmutableMap; @@ -43,7 +43,7 @@ public class CreateBucketPubSubNotificationTest extends TestBase { @BeforeClass public static void configureTopicAdminClient() throws IOException { - if(PROJECT != null) { + if (PROJECT != null) { topicAdminClient = TopicAdminClient.create(); topicAdminClient.createTopic(TOPIC); GetIamPolicyRequest getIamPolicyRequest = @@ -83,5 +83,4 @@ public void testCreateBucketPubSubNotification() { CreateBucketPubSubNotification.createBucketPubSubNotification(bucketName, notificationInfo); assertThat(stdOut.getCapturedOutputAsUtf8String()).contains(TOPIC); } - -} \ No newline at end of file +} diff --git a/samples/snippets/src/test/java/com/example/storage/bucket/DeleteBucketPubSubNotificationTest.java b/samples/snippets/src/test/java/com/example/storage/bucket/DeleteBucketPubSubNotificationTest.java index 8adb542ca6..29cda10082 100644 --- a/samples/snippets/src/test/java/com/example/storage/bucket/DeleteBucketPubSubNotificationTest.java +++ b/samples/snippets/src/test/java/com/example/storage/bucket/DeleteBucketPubSubNotificationTest.java @@ -19,8 +19,8 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertNotNull; -import com.google.cloud.pubsub.v1.TopicAdminClient; import com.example.storage.TestBase; +import com.google.cloud.pubsub.v1.TopicAdminClient; import com.google.cloud.storage.Notification; import com.google.cloud.storage.NotificationInfo; import com.google.common.collect.ImmutableMap; @@ -41,10 +41,11 @@ public class DeleteBucketPubSubNotificationTest extends TestBase { private static final String PROJECT = System.getenv("GOOGLE_CLOUD_PROJECT"); private static final String TOPIC = String.format("projects/%s/topics/new-topic", PROJECT); private static TopicAdminClient topicAdminClient; - private static final NotificationInfo notificationInfo = NotificationInfo.newBuilder(TOPIC) - .setCustomAttributes(CUSTOM_ATTRIBUTES) - .setPayloadFormat(PAYLOAD_FORMAT) - .build(); + private static final NotificationInfo notificationInfo = + NotificationInfo.newBuilder(TOPIC) + .setCustomAttributes(CUSTOM_ATTRIBUTES) + .setPayloadFormat(PAYLOAD_FORMAT) + .build(); @BeforeClass public static void configureTopicAdminClient() throws IOException { @@ -81,10 +82,10 @@ public void testDeleteBucketPubSubNotification() { assertNotNull("Topic Admin Client did not start up", topicAdminClient); Notification notification = storage.createNotification(bucketName, notificationInfo); - DeleteBucketPubSubNotification.deleteBucketPubSubNotification(bucketName, - notification.getNotificationId()); - assertThat(stdOut.getCapturedOutputAsUtf8String()).contains( - "Successfully deleted notification"); + DeleteBucketPubSubNotification.deleteBucketPubSubNotification( + bucketName, notification.getNotificationId()); + assertThat(stdOut.getCapturedOutputAsUtf8String()) + .contains("Successfully deleted notification"); } @Test @@ -96,9 +97,8 @@ public void testNotificationNotFound() { // Do a delete first. storage.deleteNotification(bucketName, notification.getNotificationId()); // Now try to delete again. - DeleteBucketPubSubNotification.deleteBucketPubSubNotification(bucketName, - notification.getNotificationId()); + DeleteBucketPubSubNotification.deleteBucketPubSubNotification( + bucketName, notification.getNotificationId()); assertThat(stdOut.getCapturedOutputAsUtf8String()).contains("Failed to find notification"); } - -} \ No newline at end of file +} diff --git a/samples/snippets/src/test/java/com/example/storage/bucket/ListPubSubNotificationsTest.java b/samples/snippets/src/test/java/com/example/storage/bucket/ListPubSubNotificationsTest.java index 45d8dbfbfe..e7622748b4 100644 --- a/samples/snippets/src/test/java/com/example/storage/bucket/ListPubSubNotificationsTest.java +++ b/samples/snippets/src/test/java/com/example/storage/bucket/ListPubSubNotificationsTest.java @@ -19,8 +19,8 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertNotNull; -import com.google.cloud.pubsub.v1.TopicAdminClient; import com.example.storage.TestBase; +import com.google.cloud.pubsub.v1.TopicAdminClient; import com.google.cloud.storage.Notification; import com.google.cloud.storage.NotificationInfo; import com.google.common.collect.ImmutableMap; @@ -43,7 +43,7 @@ public class ListPubSubNotificationsTest extends TestBase { @BeforeClass public static void configureTopicAdminClient() throws IOException { - if(PROJECT != null) { + if (PROJECT != null) { topicAdminClient = TopicAdminClient.create(); topicAdminClient.createTopic(TOPIC); GetIamPolicyRequest getIamPolicyRequest = @@ -84,5 +84,4 @@ public void testListBucketPubSubNotification() { ListPubSubNotifications.listPubSubNotifications(bucketName); assertThat(stdOut.getCapturedOutputAsUtf8String()).contains(TOPIC); } - -} \ No newline at end of file +} diff --git a/samples/snippets/src/test/java/com/example/storage/bucket/PrintPubSubNotificationTest.java b/samples/snippets/src/test/java/com/example/storage/bucket/PrintPubSubNotificationTest.java index e71492b60e..1d7a951980 100644 --- a/samples/snippets/src/test/java/com/example/storage/bucket/PrintPubSubNotificationTest.java +++ b/samples/snippets/src/test/java/com/example/storage/bucket/PrintPubSubNotificationTest.java @@ -19,8 +19,8 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertNotNull; -import com.google.cloud.pubsub.v1.TopicAdminClient; import com.example.storage.TestBase; +import com.google.cloud.pubsub.v1.TopicAdminClient; import com.google.cloud.storage.Notification; import com.google.cloud.storage.NotificationInfo; import com.google.common.collect.ImmutableMap; @@ -43,7 +43,7 @@ public class PrintPubSubNotificationTest extends TestBase { @BeforeClass public static void configureTopicAdminClient() throws IOException { - if(PROJECT != null) { + if (PROJECT != null) { topicAdminClient = TopicAdminClient.create(); topicAdminClient.createTopic(TOPIC); GetIamPolicyRequest getIamPolicyRequest = @@ -84,5 +84,4 @@ public void testPrintBucketPubSubNotification() { PrintPubSubNotification.printPubSubNotification(bucketName, notification.getNotificationId()); assertThat(stdOut.getCapturedOutputAsUtf8String()).contains(TOPIC); } - -} \ No newline at end of file +}