StorageBucket bucket = createBucketForTest("testNotificationConfig");
String bucketName = bucket.getName();
try {
// Check no existing notification config
NotificationConfig notificationConfig =
s3Service.getNotificationConfig(bucketName);
assertEquals(0, notificationConfig.getTopicConfigs().size());
// Public SNS topic for testing
String topicArn =
"arn:aws:sns:us-east-1:916472402845:"
+ "JetS3t-Test-S3-Bucket-NotificationConfig";
String event = NotificationConfig.EVENT_REDUCED_REDUNDANCY_LOST_OBJECT;
// Set notification config
notificationConfig = new NotificationConfig();
notificationConfig.addTopicConfig(notificationConfig.new TopicConfig(topicArn, event));
s3Service.setNotificationConfig(bucketName, notificationConfig);
Thread.sleep(5000);
// Get notification config
notificationConfig = s3Service.getNotificationConfig(bucketName);
assertEquals(1, notificationConfig.getTopicConfigs().size());
TopicConfig topicConfig = notificationConfig.getTopicConfigs().get(0);
assertEquals(topicArn, topicConfig.getTopic());
assertEquals(event, topicConfig.getEvent());
// Unset/clear notification config
s3Service.unsetNotificationConfig(bucketName);
Thread.sleep(5000);
// Confirm notification config is no longer set
notificationConfig = s3Service.getNotificationConfig(bucketName);
assertEquals(0, notificationConfig.getTopicConfigs().size());
} finally {
cleanupBucketForTest("testNotificationConfig");
}
}