getTopicAttributesRequest.setTopicArn(topicArn);
GetTopicAttributesResult result = cns1.getTopicAttributes(getTopicAttributesRequest);
assertTrue("Expected display name NewDisplayName, instead found " + result.getAttributes().get("DisplayName"), result.getAttributes().get("DisplayName").equals("NewDisplayName"));
RemovePermissionRequest removePermissionRequest = new RemovePermissionRequest();
removePermissionRequest.setTopicArn(topicArn);
removePermissionRequest.setLabel("P1");
cns1.removePermission(removePermissionRequest);
logger.info("Now trying to do things without permission");
try {
setTopicAttributesRequest = new SetTopicAttributesRequest();
setTopicAttributesRequest.setAttributeName("DisplayName");
setTopicAttributesRequest.setAttributeValue("NewDisplayName2");
setTopicAttributesRequest.setTopicArn(topicArn);
cns2.setTopicAttributes(setTopicAttributesRequest);
fail("missing expected exception");
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("don't have permission"));
}
// test publish permission
try {
PublishRequest publishRequest = new PublishRequest();
publishRequest.setMessage("hello world!!!");
publishRequest.setTopicArn(topicArn);
cns2.publish(publishRequest);
fail("missing expected exception");
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("don't have permission"));
}
addPermissionRequest = new AddPermissionRequest();
addPermissionRequest.setTopicArn(topicArn);
addPermissionRequest.setActionNames(Arrays.asList("Publish"));
addPermissionRequest.setLabel("P2");
addPermissionRequest.setAWSAccountIds(Arrays.asList(user2.getUserId()));
cns1.addPermission(addPermissionRequest);
PublishRequest publishRequest = new PublishRequest();
publishRequest.setMessage("hello world!!!");
publishRequest.setTopicArn(topicArn);
cns2.publish(publishRequest);
removePermissionRequest = new RemovePermissionRequest();
removePermissionRequest.setTopicArn(topicArn);
removePermissionRequest.setLabel("P2");
cns1.removePermission(removePermissionRequest);
try {
publishRequest = new PublishRequest();
publishRequest.setMessage("hello world!!!");