Search in sources :

Example 1 with SubscribeRequest

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);
}
Also used : SubscribeRequest(com.amazonaws.services.sns.model.SubscribeRequest) ListSubscriptionsByTopicResult(com.amazonaws.services.sns.model.ListSubscriptionsByTopicResult) ListSubscriptionsByTopicRequest(com.amazonaws.services.sns.model.ListSubscriptionsByTopicRequest) Subscription(com.amazonaws.services.sns.model.Subscription) Test(org.junit.Test)

Example 2 with SubscribeRequest

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);
}
Also used : SubscribeRequest(com.amazonaws.services.sns.model.SubscribeRequest) Subscription(com.amazonaws.services.sns.model.Subscription) SubscribeResult(com.amazonaws.services.sns.model.SubscribeResult)

Example 3 with SubscribeRequest

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;
}
Also used : CreateTopicResult(com.amazonaws.services.sns.model.CreateTopicResult) SubscribeRequest(com.amazonaws.services.sns.model.SubscribeRequest) CreateTopicRequest(com.amazonaws.services.sns.model.CreateTopicRequest) SubscribeResult(com.amazonaws.services.sns.model.SubscribeResult)

Example 4 with SubscribeRequest

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);
}
Also used : SubscribeRequest(com.amazonaws.services.sns.model.SubscribeRequest) ListSubscriptionsByTopicResult(com.amazonaws.services.sns.model.ListSubscriptionsByTopicResult) ListSubscriptionsByTopicRequest(com.amazonaws.services.sns.model.ListSubscriptionsByTopicRequest) Subscription(com.amazonaws.services.sns.model.Subscription) Test(org.junit.Test)

Aggregations

SubscribeRequest (com.amazonaws.services.sns.model.SubscribeRequest)4 Subscription (com.amazonaws.services.sns.model.Subscription)3 ListSubscriptionsByTopicRequest (com.amazonaws.services.sns.model.ListSubscriptionsByTopicRequest)2 ListSubscriptionsByTopicResult (com.amazonaws.services.sns.model.ListSubscriptionsByTopicResult)2 SubscribeResult (com.amazonaws.services.sns.model.SubscribeResult)2 Test (org.junit.Test)2 CreateTopicRequest (com.amazonaws.services.sns.model.CreateTopicRequest)1 CreateTopicResult (com.amazonaws.services.sns.model.CreateTopicResult)1