use of com.amazonaws.services.sns.model.SubscribeRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class NotificationUtilsTest method testCreateSubscriptionAlreadyExists.
@Test
public void testCreateSubscriptionAlreadyExists() {
String topicArn = "arn:123";
String protocol = "email";
String endpoint = "testing@domain.com";
ListSubscriptionsByTopicRequest tRequest = new ListSubscriptionsByTopicRequest().withTopicArn(topicArn);
Subscription expected = new Subscription().withEndpoint(endpoint).withProtocol(protocol);
ListSubscriptionsByTopicResult result = new ListSubscriptionsByTopicResult().withSubscriptions(expected);
when(mockClient.listSubscriptionsByTopic(tRequest)).thenReturn(result);
// This should not call create because it already exists
SubscribeRequest expectedRequest = new SubscribeRequest();
expectedRequest.setTopicArn(topicArn);
expectedRequest.setProtocol(protocol);
expectedRequest.setEndpoint(endpoint);
Subscription sub = NotificationUtils.createSubScription(mockClient, topicArn, protocol, endpoint);
assertEquals(expected, sub);
// Subscribe should not have been called!
verify(mockClient, times(0)).subscribe(expectedRequest);
}
use of com.amazonaws.services.sns.model.SubscribeRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class NotificationUtils method createSubScription.
/**
* Create the subscription if it does not exist.
*/
public static Subscription createSubScription(AmazonSNSClient client, String topicArn, String protocol, String endpoint) {
// first determine if the subscription exists
Subscription result = findSubscription(client, topicArn, protocol, endpoint);
if (result == null) {
// Subscribe to this topic
SubscribeRequest subscribeRequest = new SubscribeRequest();
subscribeRequest.setTopicArn(topicArn);
subscribeRequest.setProtocol(protocol);
subscribeRequest.setEndpoint(endpoint);
SubscribeResult subResults = client.subscribe(subscribeRequest);
logger.debug("Subscription did not exist so created it: " + subResults);
} else {
logger.debug("Subscription already exists: " + result);
}
// Search again to find it.
return findSubscription(client, topicArn, protocol, endpoint);
}
use of com.amazonaws.services.sns.model.SubscribeRequest in project glacier-cli by carlossg.
the class Glacier method setupSNS.
private QueueConfig setupSNS(QueueConfig config, String snsTopicName) {
CreateTopicRequest request = new CreateTopicRequest().withName(snsTopicName);
CreateTopicResult result = snsClient.createTopic(request);
config.snsTopicARN = result.getTopicArn();
SubscribeRequest request2 = new SubscribeRequest().withTopicArn(config.snsTopicARN).withEndpoint(config.sqsQueueARN).withProtocol("sqs");
SubscribeResult result2 = snsClient.subscribe(request2);
config.snsSubscriptionARN = result2.getSubscriptionArn();
return config;
}
use of com.amazonaws.services.sns.model.SubscribeRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class NotificationUtilsTest method testCreateSubscriptionDoesNotExist.
@Test
public void testCreateSubscriptionDoesNotExist() {
String topicArn = "arn:123";
String protocol = "email";
String endpoint = "testing@domain.com";
ListSubscriptionsByTopicRequest tRequest = new ListSubscriptionsByTopicRequest().withTopicArn(topicArn);
ListSubscriptionsByTopicResult result = new ListSubscriptionsByTopicResult().withSubscriptions(new Subscription().withEndpoint("nomatch").withProtocol("noMatch"));
when(mockClient.listSubscriptionsByTopic(tRequest)).thenReturn(result);
// This should call create
SubscribeRequest expectedRequest = new SubscribeRequest();
expectedRequest.setTopicArn(topicArn);
expectedRequest.setProtocol(protocol);
expectedRequest.setEndpoint(endpoint);
Subscription sub = NotificationUtils.createSubScription(mockClient, topicArn, protocol, endpoint);
assertNull(sub);
verify(mockClient, times(1)).subscribe(expectedRequest);
}
Aggregations