private void addPermissions() { if (permissions != null && permissions.isEmpty() == false) { GetTopicAttributesResult result = client .getTopicAttributes(topicArn); AwsUtil.addPermissions(result.getAttributes(), permissions, new AwsUtil.AddPermissionHandler() { @Override public void execute(Permission p) { client.addPermission(new AddPermissionRequest() .withTopicArn(topicArn) .withLabel(p.getLabel()) .withAWSAccountIds(p.getAwsAccountIds()) .withActionNames(p.getActions())); } }); } }
@Test public void testAddPermission_withSuccessMock_shouldWork() { mockSns(new MockParameters()); AddPermissionRequest addPermissionRequest = new AddPermissionRequest() .withActionNames(ImmutableList.of("READ", "WRITE")) .withAWSAccountIds(ImmutableList.of("1", "2")).withLabel("unsecure-topic").withTopicArn( "arn:aws:sns:us-east-1:123456789012:my_corporate_topic:02034b43-fefa-4e07-a5eb-3be56f8c54ce"); AddPermissionResult result = sns.addPermission(addPermissionRequest); assertNotNull("verify adding permission returns ok", result); }
@Test(expected = AmazonSNSException.class) public void testAddPermission_withInvalidParameterMock_shouldThrowException() { mockSns(new MockParameters(InvalidParameterException.class)); AddPermissionRequest addPermissionRequest = new AddPermissionRequest() .withActionNames(ImmutableList.of("READ", "WRITE")) .withAWSAccountIds(ImmutableList.of("1", "2")).withLabel("unsecure-topic").withTopicArn( "arn:aws:sns:us-east-1:123456789012:my_corporate_topic:02034b43-fefa-4e07-a5eb-3be56f8c54ce"); sns.addPermission(addPermissionRequest); }
@Test public void testAddPermissionAsync_shouldWork() throws InterruptedException, ExecutionException { mockSns(new MockParameters()); AddPermissionRequest addPermissionRequest = new AddPermissionRequest() .withActionNames(ImmutableList.of("READ", "WRITE")) .withAWSAccountIds(ImmutableList.of("1", "2")).withLabel("unsecure-topic").withTopicArn( "arn:aws:sns:us-east-1:123456789012:my_corporate_topic:02034b43-fefa-4e07-a5eb-3be56f8c54ce"); Future<AddPermissionResult> result = sns.addPermissionAsync(addPermissionRequest); assertNotNull("verify also async call works fine", result.get()); }
@Override public void addPermission(String label, List<String> aWSAccountIds, List<String> actionNames, ResultCapture<Void> extractor) { AddPermissionRequest request = new AddPermissionRequest() .withLabel(label) .withAWSAccountIds(aWSAccountIds) .withActionNames(actionNames); addPermission(request, extractor); }
@Test public void testAddPermissionAsync_withNoRequestParams_shouldWork() throws InterruptedException, ExecutionException { mockSns(new MockParameters()); Future<AddPermissionResult> result = sns.addPermissionAsync(new AddPermissionRequest()); assertNotNull(result.get()); }
@Override public AddPermissionResult addPermission(AddPermissionRequest addPermissionRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException(); }
@Override public void addPermission(AddPermissionRequest request) { addPermission(request, null); }
@Override public void addPermission(AddPermissionRequest request, ResultCapture<Void> extractor) { resource.performAction("AddPermission", request, extractor); }
/** * Performs the <code>AddPermission</code> action. * * <p> * The following request parameters will be populated from the data of this * <code>Topic</code> resource, and any conflicting parameter value set in * the request will be overridden: * <ul> * <li> * <b><code>TopicArn</code></b> * - mapped from the <code>Arn</code> identifier. * </li> * </ul> * * <p> * * @see AddPermissionRequest */ void addPermission(AddPermissionRequest request);
/** * Performs the <code>AddPermission</code> action and use a ResultCapture to * retrieve the low-level client response. * * <p> * The following request parameters will be populated from the data of this * <code>Topic</code> resource, and any conflicting parameter value set in * the request will be overridden: * <ul> * <li> * <b><code>TopicArn</code></b> * - mapped from the <code>Arn</code> identifier. * </li> * </ul> * * <p> * * @see AddPermissionRequest */ void addPermission(AddPermissionRequest request, ResultCapture<Void> extractor);