public void testGetSetQueueAttributes() throws PersistenceException, InterruptedException {
String queueUrl = getQueueUrl(1, USR.USER1);
cqs1.setQueueAttributes(new SetQueueAttributesRequest(queueUrl, attributeParams));
GetQueueAttributesRequest getQueueAttributesRequest = new GetQueueAttributesRequest();
getQueueAttributesRequest.setQueueUrl(queueUrl);
getQueueAttributesRequest.setAttributeNames(Arrays.asList("VisibilityTimeout", "MessageRetentionPeriod", "All"));
GetQueueAttributesResult result = cqs1.getQueueAttributes(getQueueAttributesRequest);
assertTrue(result.getAttributes().get("MessageRetentionPeriod").equals("600"));
assertTrue(result.getAttributes().get("VisibilityTimeout").equals("30"));
SetQueueAttributesRequest setQueueAttributesRequest = new SetQueueAttributesRequest();
setQueueAttributesRequest.setQueueUrl(queueUrl);
HashMap<String, String> attributes = new HashMap<String, String>();
attributes.put("MessageRetentionPeriod", "300");
attributes.put("VisibilityTimeout", "80");
attributes.put("MaximumMessageSize", "10240");
attributes.put("DelaySeconds", "100");
String policy = "{\"Version\":\"2008-10-17\",\"Id\":\""+queueUrl+"/SQSDefaultPolicy\",\"Statement\":[{\"Sid\":\"test\",\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\""+user1.getUserId()+"\"},\"Action\":\"CQS:SendMessage\",\"Resource\":\""+com.comcast.cqs.util.Util.getArnForAbsoluteQueueUrl(queueUrl)+"\"}]}";
attributes.put("Policy", policy);
setQueueAttributesRequest.setAttributes(attributes);
cqs1.setQueueAttributes(setQueueAttributesRequest);
result = cqs1.getQueueAttributes(getQueueAttributesRequest);
assertTrue("Expected retention period of 300 sec, instead found " + result.getAttributes().get("MessageRetentionPeriod"), result.getAttributes().get("MessageRetentionPeriod").equals("300"));
assertTrue("Expected visibility timeout to be 80 sec, instead found " + result.getAttributes().get("VisibilityTimeout"), result.getAttributes().get("VisibilityTimeout").equals("80"));
assertTrue("Expected max message size to be 10240, instead found " + result.getAttributes().get("MaximumMessageSize"), result.getAttributes().get("MaximumMessageSize").equals("10240"));
assertTrue("Expected delay seconds to be 100, instead found " + result.getAttributes().get("DelaySeconds"), result.getAttributes().get("DelaySeconds").equals("100"));
attributes = new HashMap<String, String>(){ {put("VisibilityTimeout", "100");}};
setQueueAttributesRequest.setAttributes(attributes);
cqs1.setQueueAttributes(setQueueAttributesRequest);
result = cqs1.getQueueAttributes(getQueueAttributesRequest);
assertTrue("Expected visibility timeout to be 100 sec, instead found " + result.getAttributes().get("VisibilityTimeout"), result.getAttributes().get("VisibilityTimeout").equals("100"));
// try triggering missing parameter error
try {
setQueueAttributesRequest = new SetQueueAttributesRequest();
setQueueAttributesRequest.setQueueUrl(queueUrl);
cqs1.setQueueAttributes(setQueueAttributesRequest);
fail("missing expected exception");
} catch (AmazonServiceException ase) {
assertTrue("Did not receive missing parameter exception", ase.getErrorCode().equals(CQSErrorCodes.MissingParameter.getCMBCode()));
}
// try trigger unknown attribute name error
try {
getQueueAttributesRequest = new GetQueueAttributesRequest();
getQueueAttributesRequest.setQueueUrl(queueUrl);
getQueueAttributesRequest.setAttributeNames(Arrays.asList("all"));
cqs1.getQueueAttributes(getQueueAttributesRequest);
fail("missing expected exception");
} catch (AmazonServiceException ase) {
assertTrue(ase.getErrorCode().equals(CQSErrorCodes.InvalidAttributeName.getCMBCode()));