use of com.amazonaws.services.sns.model.Subscription in project Synapse-Stack-Builder by Sage-Bionetworks.
the class NotificationUtils method findSubscription.
/**
* This is a pain-in-the-butt way to determine if a subscription already exists
* @param topicArn
* @param protocol
* @param endpoint
* @return
*/
public static Subscription findSubscription(AmazonSNSClient client, String topicArn, String protocol, String endpoint) {
// Fill this list with all of the pages
List<Subscription> fullList = new LinkedList<Subscription>();
ListSubscriptionsByTopicResult subList = client.listSubscriptionsByTopic(new ListSubscriptionsByTopicRequest().withTopicArn(topicArn));
fullList.addAll(subList.getSubscriptions());
while (subList.getNextToken() != null) {
subList = client.listSubscriptionsByTopic(new ListSubscriptionsByTopicRequest().withTopicArn(topicArn));
fullList.addAll(subList.getSubscriptions());
}
// Scan the full list for this results
for (Subscription sub : fullList) {
if (protocol.equals(sub.getProtocol()) && endpoint.equals(sub.getEndpoint())) {
return sub;
}
}
// Did not find it
return null;
}
use of com.amazonaws.services.sns.model.Subscription in project Synapse-Stack-Builder by Sage-Bionetworks.
the class EnvironmentInstancesNotificationSetupTest method setupExpectedRes.
private CreateTopicResult setupExpectedRes(StackEnvironmentType env, CreateTopicRequest req) {
String topicArn = "arn:" + req.getName();
String protocol = Constants.TOPIC_SUBSCRIBE_PROTOCOL_EMAIL;
String endpoint = config.getEnvironmentInstanceNotificationEndpoint(env);
CreateTopicResult expectedRes = new CreateTopicResult().withTopicArn(topicArn);
when(mockClient.createTopic(req)).thenReturn(expectedRes);
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);
return expectedRes;
}
use of com.amazonaws.services.sns.model.Subscription 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);
}
use of com.amazonaws.services.sns.model.Subscription in project Synapse-Stack-Builder by Sage-Bionetworks.
the class NotificationUtilsTest method testfindSubscriptionDoesNotExist.
@Test
public void testfindSubscriptionDoesNotExist() {
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);
// For this case it should not be found
Subscription sub = NotificationUtils.findSubscription(mockClient, topicArn, protocol, endpoint);
assertNull(sub);
}
use of com.amazonaws.services.sns.model.Subscription in project Synapse-Stack-Builder by Sage-Bionetworks.
the class NotificationUtils method setupNotificationTopicAndSubscription.
public static CreateTopicResult setupNotificationTopicAndSubscription(AmazonSNSClient client, String topicName, String endpoint) {
// Create the topic
CreateTopicRequest request = new CreateTopicRequest();
request.setName(topicName);
CreateTopicResult result = client.createTopic(request);
// Create the subscription
Subscription sub = NotificationUtils.createSubScription(client, result.getTopicArn(), Constants.TOPIC_SUBSCRIBE_PROTOCOL_EMAIL, endpoint);
return result;
}
Aggregations