Java 类com.amazonaws.services.sns.model.ListSubscriptionsByTopicResult 实例源码

项目:izettle-toolbox    文件:AmazonSNSSubscriptionSetup.java   
private static boolean isSQSQueueSubscribingToSNSTopic(
    AmazonSNS amazonSNS,
    String queueARN,
    String topicARN
) {
    // This statement will throw if the topic does not exist.
    ListSubscriptionsByTopicResult subscriptions = amazonSNS.listSubscriptionsByTopic(
        new ListSubscriptionsByTopicRequest()
            .withTopicArn(topicARN)
    );
    for (Subscription subscription : subscriptions.getSubscriptions()) {
        if (subscription.getEndpoint().equals(queueARN)) {
            return true;
        }
    }
    return false;
}
项目:awslocal    文件:InMemorySNS.java   
@Override
public ListSubscriptionsByTopicResult listSubscriptionsByTopic(ListSubscriptionsByTopicRequest listSubscriptionsByTopicRequest) throws AmazonClientException {
    return new ListSubscriptionsByTopicResult().
            withSubscriptions(FluentIterable.
                    from(_subscriptionsForTopic.get(listSubscriptionsByTopicRequest.getTopicArn())).
                    filter(Predicates.in(_subscriptionsByArn.keySet())).
                    transform(Functions.forMap(_subscriptionsByArn)).
                    toList());
}
项目:unitstack    文件:MockSnsTest.java   
@Test
public void testSubscribeConfirmListUnsubscribe_shouldCreateVerifyListAndRemoveSubscription() {
  mockSns(new MockParameters());
  // create topic
  CreateTopicResult topicResult = sns.createTopic(new CreateTopicRequest().withName("important-topic"));

  // subscribe to first topic
  SubscribeResult subscribeResult = sns.subscribe(new SubscribeRequest().withTopicArn(topicResult.getTopicArn())
      .withProtocol("sqs").withEndpoint("arn:aws:sqs:us-east-1:123456789012:queue1"));
  assertNotNull("verify subscription ARN is created", subscribeResult.getSubscriptionArn());

  // create second topic and subscribe to that one
  CreateTopicResult secondTopicResult = sns.createTopic(new CreateTopicRequest().withName("someOther-topic"));
  sns.subscribe(new SubscribeRequest().withTopicArn(secondTopicResult.getTopicArn())
      .withProtocol("sqs").withEndpoint("arn:aws:sqs:us-east-1:564654654:queue7"));

  // confirm first subscription
  ConfirmSubscriptionResult confirmResultAuth = sns.confirmSubscription(new ConfirmSubscriptionRequest()
      .withAuthenticateOnUnsubscribe("true").withToken("gold-token").withTopicArn(topicResult.getTopicArn()));
  assertNotNull("verify auth confirmation with responded topic arn", confirmResultAuth.getSubscriptionArn());
  ConfirmSubscriptionResult confirmResultNoAuth = sns.confirmSubscription(new ConfirmSubscriptionRequest()
      .withAuthenticateOnUnsubscribe("false").withToken("gold-token").withTopicArn(topicResult.getTopicArn()));
  assertNotNull("verify no auth confirmation with responded topic arn", confirmResultNoAuth.getSubscriptionArn());

  // list all subscriptions
  ListSubscriptionsResult allSubs = sns.listSubscriptions();
  assertEquals("verify correct total subscription count", 2, allSubs.getSubscriptions().size());
  com.amazonaws.services.sns.model.Subscription firstSub = allSubs.getSubscriptions().stream().filter(sub -> sub.getTopicArn().equals(topicResult.getTopicArn())).findFirst().get();
  assertEquals("verify the correct subscription arn", subscribeResult.getSubscriptionArn(), firstSub.getSubscriptionArn());
  assertEquals("verify the correct subscription topic", topicResult.getTopicArn(), firstSub.getTopicArn());
  assertEquals("verify the correct subscription protocol", "sqs", firstSub.getProtocol());
  assertEquals("verify the correct subscription endpoint", "arn:aws:sqs:us-east-1:123456789012:queue1", firstSub.getEndpoint());
  assertNotNull("verify the correct subscription owner", firstSub.getOwner());

  // list subscriptions of first topic
  ListSubscriptionsByTopicResult topicsSubscriptions = sns.listSubscriptionsByTopic(new ListSubscriptionsByTopicRequest(topicResult.getTopicArn()));
  assertEquals("verify that the one subscription is contained in list", 1, topicsSubscriptions.getSubscriptions().size());
  assertEquals("verify the correct subscription arn", subscribeResult.getSubscriptionArn(), topicsSubscriptions.getSubscriptions().get(0).getSubscriptionArn());
  assertEquals("verify the correct subscription topic", topicResult.getTopicArn(), topicsSubscriptions.getSubscriptions().get(0).getTopicArn());
  assertEquals("verify the correct subscription protocol", "sqs", topicsSubscriptions.getSubscriptions().get(0).getProtocol());
  assertEquals("verify the correct subscription endpoint", "arn:aws:sqs:us-east-1:123456789012:queue1", topicsSubscriptions.getSubscriptions().get(0).getEndpoint());
  assertNotNull("verify the correct subscription owner", topicsSubscriptions.getSubscriptions().get(0).getOwner());

  // unsubscribe first topic
  assertNotNull(sns.unsubscribe(subscribeResult.getSubscriptionArn()));

  // check if really unsubscribed
  ListSubscriptionsByTopicResult subsToFirstTopicAfterUnsubscribe = sns.listSubscriptionsByTopic(new ListSubscriptionsByTopicRequest(topicResult.getTopicArn()));
  assertEquals("topic should be gone", 0, subsToFirstTopicAfterUnsubscribe.getSubscriptions().size());

  // cleanup
  sns.deleteTopic(topicResult.getTopicArn());
  sns.deleteTopic(secondTopicResult.getTopicArn());
}
项目:Camel    文件:AmazonSNSClientMock.java   
@Override
public ListSubscriptionsByTopicResult listSubscriptionsByTopic(ListSubscriptionsByTopicRequest listSubscriptionsByTopicRequest) throws AmazonServiceException, AmazonClientException {
    throw new UnsupportedOperationException();
}