addPermissionRequest.setActionNames(Arrays.asList("SetTopicAttributes", "Publish"));
addPermissionRequest.setLabel("P1");
addPermissionRequest.setAWSAccountIds(Arrays.asList(user2.getUserId()));
cns1.addPermission(addPermissionRequest);
SetTopicAttributesRequest setTopicAttributesRequest = new SetTopicAttributesRequest();
setTopicAttributesRequest.setAttributeName("DisplayName");
setTopicAttributesRequest.setAttributeValue("NewDisplayName");
setTopicAttributesRequest.setTopicArn(topicArn);
cns2.setTopicAttributes(setTopicAttributesRequest);
GetTopicAttributesRequest getTopicAttributesRequest = new GetTopicAttributesRequest();
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"));
}