"}";
try {
JSONObject json = new JSONObject(jsonStr);
CNSSubscriptionDeliveryPolicy subpolicy = new CNSSubscriptionDeliveryPolicy(json);
CNSRetryPolicy hRetryPolicy = subpolicy.getHealthyRetryPolicy();
assertTrue(hRetryPolicy.getMinDelayTarget() == 1);
assertTrue(hRetryPolicy.getMaxDelayTarget() == 2);
assertTrue(hRetryPolicy.getNumRetries() == 10);
assertTrue(hRetryPolicy.getNumMaxDelayRetries() == 4);
assertTrue(hRetryPolicy.getNumMinDelayRetries() == 6);
assertTrue(hRetryPolicy.getBackOffFunction() == CnsBackoffFunction.linear);
CNSThrottlePolicy tPolicy = subpolicy.getThrottlePolicy();
assertTrue(tPolicy.getMaxReceivesPerSecond() == 5);
assertTrue(subpolicy.getSicklyRetryPolicy() == null);
//Test 2nd Json constructor
JSONObject json2 = new JSONObject(jsonStr2);
CNSSubscriptionDeliveryPolicy subpolicy3 = new CNSSubscriptionDeliveryPolicy(json2);
hRetryPolicy = subpolicy3.getHealthyRetryPolicy();
assertTrue(hRetryPolicy.getMinDelayTarget() == 20);
assertTrue(hRetryPolicy.getMaxDelayTarget() == 20);
assertTrue(hRetryPolicy.getNumRetries() == 3);
assertTrue(hRetryPolicy.getNumMaxDelayRetries() == 0);
assertTrue(hRetryPolicy.getNumMinDelayRetries() == 0);
assertTrue(hRetryPolicy.getBackOffFunction() == CnsBackoffFunction.linear);
CNSThrottlePolicy tPolicy2 = subpolicy3.getThrottlePolicy();
assertTrue(tPolicy2.getMaxReceivesPerSecond() == null);
CNSRetryPolicy sRetryPolicy = subpolicy3.getSicklyRetryPolicy();
assertTrue(sRetryPolicy.getMinDelayTarget() == 1);
assertTrue(sRetryPolicy.getMaxDelayTarget() == 2);
assertTrue(sRetryPolicy.getNumRetries() == 10);
assertTrue(sRetryPolicy.getNumMaxDelayRetries() == 4);
assertTrue(sRetryPolicy.getNumMinDelayRetries() == 6);
assertTrue(sRetryPolicy.getBackOffFunction() == CnsBackoffFunction.exponential);
//Test default constructor
CNSSubscriptionDeliveryPolicy subpolicy2 = new CNSSubscriptionDeliveryPolicy();
hRetryPolicy = subpolicy2.getHealthyRetryPolicy();
assertTrue(hRetryPolicy.getMinDelayTarget() == 20);
assertTrue(hRetryPolicy.getMaxDelayTarget() == 20);
assertTrue(hRetryPolicy.getNumRetries() == 3);
assertTrue(hRetryPolicy.getNumMaxDelayRetries() == 0);
assertTrue(hRetryPolicy.getNumMinDelayRetries() == 0);
assertTrue(hRetryPolicy.getBackOffFunction() == CnsBackoffFunction.linear);
tPolicy = subpolicy2.getThrottlePolicy();
logger.debug("tPolicy: " + tPolicy.toString());
assertTrue(tPolicy.getMaxReceivesPerSecond() == null);
assertTrue(subpolicy.getSicklyRetryPolicy() == null);
JSONObject json3 = new JSONObject(jsonStr3);
CNSSubscriptionDeliveryPolicy subpolicy4 = new CNSSubscriptionDeliveryPolicy(json3);
hRetryPolicy = subpolicy4.getHealthyRetryPolicy();
assertTrue(hRetryPolicy.getMinDelayTarget() == 20);
assertTrue(hRetryPolicy.getMaxDelayTarget() == 20);
assertTrue(hRetryPolicy.getNumRetries() == 3);
assertTrue(hRetryPolicy.getNumMaxDelayRetries() == 0);
assertTrue(hRetryPolicy.getNumMinDelayRetries() == 0);
assertTrue(hRetryPolicy.getBackOffFunction() == CnsBackoffFunction.linear);
tPolicy = subpolicy2.getThrottlePolicy();
logger.debug("tPolicy: " + tPolicy.toString());
assertTrue(tPolicy.getMaxReceivesPerSecond() == null);
assertTrue(subpolicy.getSicklyRetryPolicy() == null);
boolean exceptionOccured = false;
json = new JSONObject(jsonStr4);
try {
new CNSSubscriptionDeliveryPolicy(json);
} catch (Exception e) {
if(e instanceof CMBException) {
assertTrue(true);
exceptionOccured = true;
logger.debug("Exception 1:");
logger.debug(e.getMessage());
} else {
assertFalse(true);
}
}
assertTrue(exceptionOccured);
exceptionOccured = false;
json = new JSONObject(jsonStr5);
try {
new CNSSubscriptionDeliveryPolicy(json);
} catch (Exception e) {
if(e instanceof CMBException) {
assertTrue(true);
exceptionOccured = true;
logger.debug("Exception 2:");
logger.debug(e.getMessage());
} else {
assertFalse(true);
}
}
assertTrue(exceptionOccured);
exceptionOccured = false;
json = new JSONObject(jsonStr6);
try {
new CNSSubscriptionDeliveryPolicy(json);
} catch (Exception e) {
if(e instanceof CMBException) {
assertTrue(true);
exceptionOccured = true;
logger.debug("Exception 3:");
logger.debug(e.getMessage());
} else {
assertFalse(true);
}
}
assertTrue(exceptionOccured);
exceptionOccured = false;
json = new JSONObject(jsonStr7);
try {
new CNSSubscriptionDeliveryPolicy(json);
} catch (Exception e) {
if(e instanceof CMBException) {
assertTrue(true);
exceptionOccured = true;
logger.debug("Exception 4:");
logger.debug(e.getMessage());
} else {
assertFalse(true);
}
}
assertTrue(exceptionOccured);
exceptionOccured = false;
json = new JSONObject(jsonStr8);
try {
new CNSSubscriptionDeliveryPolicy(json);
} catch (Exception e) {
if(e instanceof CMBException) {
assertTrue(true);
exceptionOccured = true;
logger.debug("Exception 4:");