} catch (Exception e) { }
t = topicHandler.createTopic(topicName, topicName, userId2);
topicArn = t.getArn();
ICNSSubscriptionPersistence subscriptionHandler = new CNSSubscriptionCassandraPersistence();
long beforeSubscribeCount = subscriptionHandler.getCountSubscription(t.getArn(), "subscriptionPending");
CNSSubscription s = subscriptionHandler.subscribe(CMBTestingConstants.HTTP_ENDPOINT_BASE_URL + "recv/1234", CnsSubscriptionProtocol.http, t.getArn(), userId1);
long afterSubscribeCount = subscriptionHandler.getCountSubscription(t.getArn(), "subscriptionPending");
// check default delivery policy on topic1
CNSSubscriptionAttributes attributes = attributeHandler.getSubscriptionAttributes(s.getArn());
assertTrue("Expected 3 retries in healthy policy, instead found " + attributes.getEffectiveDeliveryPolicy().getHealthyRetryPolicy().getNumRetries(), attributes.getEffectiveDeliveryPolicy().getHealthyRetryPolicy().getNumRetries() == 3);
List<CNSSubscription> l = subscriptionHandler.listSubscriptions(null, null, userId1);
assertTrue("Could not verify PendingConfirmation state", l.size() == 1 && l.get(0).getArn().equals("PendingConfirmation"));
s = subscriptionHandler.confirmSubscription(false, s.getToken(), t.getArn());
l = subscriptionHandler.listSubscriptions(null, null, userId1);
assertTrue("Expected 1 subscription, instead found " + l.size(), l.size() == 1);
l = subscriptionHandler.listSubscriptionsByTopic(null, t.getArn(), null);
assertTrue("Expected 1 subscription, instead found " + l.size(), l.size() == 1);
l = subscriptionHandler.listSubscriptionsByTopic(null, t.getArn(), CnsSubscriptionProtocol.http);
assertTrue("Expected 1 subscription, instead found " + l.size(), l.size() == 1);
l = subscriptionHandler.listSubscriptionsByTopic(null, t.getArn(), CnsSubscriptionProtocol.email);
assertTrue("Expected 0 subscription, instead found " + l.size(), l.size() == 0);
assertTrue("Wrong number of subscribers", afterSubscribeCount == beforeSubscribeCount+1);
try {
l = subscriptionHandler.listSubscriptionsByTopic(null, com.comcast.cns.util.Util.generateCnsTopicArn("xyz", "east", userId1), null);
} catch (CMBException ex) {
assertTrue(ex.getCMBCode().equals(CMBErrorCodes.NotFound.getCMBCode()));
}
CNSSubscription sdup = subscriptionHandler.getSubscription(s.getArn());
assertTrue("Subscriptions are not identical: " + s + "; " + sdup, s.equals(sdup));
long beforeUnsubscribeCount = subscriptionHandler.getCountSubscription(t.getArn(), "subscriptionDeleted");
subscriptionHandler.unsubscribe(s.getArn());
long afterUnsubscribeCount = subscriptionHandler.getCountSubscription(t.getArn(), "subscriptionDeleted");
l = subscriptionHandler.listSubscriptions(null, null, userId1);
assertTrue("Expected 0 subscription, instead found " + l.size(), l.size() == 0);
assertTrue("Wrong number of subscribers", afterUnsubscribeCount == beforeUnsubscribeCount + 1);