@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()); }
@Override public ListSubscriptionsResult listSubscriptions(ListSubscriptionsRequest listSubscriptionsRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException(); }
@Override public ListSubscriptionsResult listSubscriptions() throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException(); }
@Override public ListSubscriptionsResult listSubscriptions() throws AmazonClientException { return new ListSubscriptionsResult().withSubscriptions(_subscriptionsByArn.values()); }
@Override public ListSubscriptionsResult listSubscriptions(ListSubscriptionsRequest listSubscriptionsRequest) throws AmazonClientException { return listSubscriptions(); }