}
// 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!!!");
publishRequest.setTopicArn(topicArn);
cns2.publish(publishRequest);
fail("missing expected exception");
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("don't have permission"));
}
// test add permission
addPermissionRequest = new AddPermissionRequest();
addPermissionRequest.setTopicArn(topicArn);
addPermissionRequest.setActionNames(Arrays.asList("AddPermission"));
addPermissionRequest.setLabel("P3");
addPermissionRequest.setAWSAccountIds(Arrays.asList(user2.getUserId()));
cns1.addPermission(addPermissionRequest);
addPermissionRequest = new AddPermissionRequest();
addPermissionRequest.setTopicArn(topicArn);
addPermissionRequest.setActionNames(Arrays.asList("Publish"));
addPermissionRequest.setLabel("P4");
addPermissionRequest.setAWSAccountIds(Arrays.asList(user3.getUserId()));
cns2.addPermission(addPermissionRequest);
publishRequest = new PublishRequest();
publishRequest.setMessage("hello world!!!");
publishRequest.setTopicArn(topicArn);
cns3.publish(publishRequest);
// try some invalid stuff
try {