com.amazonaws.services.sns.model.ListTopicsRequest Java Examples

The following examples show how to use com.amazonaws.services.sns.model.ListTopicsRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamicTopicDestinationResolver.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
private String getTopicResourceName(String marker, String topicName) {
	ListTopicsResult listTopicsResult = this.amazonSns
			.listTopics(new ListTopicsRequest(marker));
	for (Topic topic : listTopicsResult.getTopics()) {
		AmazonResourceName resourceName = AmazonResourceName
				.fromString(topic.getTopicArn());
		if (resourceName.getResourceType().equals(topicName)) {
			return topic.getTopicArn();
		}
	}

	if (StringUtils.hasText(listTopicsResult.getNextToken())) {
		return getTopicResourceName(listTopicsResult.getNextToken(), topicName);
	}
	else {
		throw new IllegalArgumentException(
				"No topic found for name :'" + topicName + "'");
	}
}
 
Example #2
Source File: DynamicTopicDestinationResolverTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void resolveDestination_withNonExistentTopicAndWithoutMarkerReturnedOnListTopics_shouldThrowIllegalArgumentException()
		throws Exception {
	// @checkstyle:on
	// Arrange
	AmazonSNS sns = mock(AmazonSNS.class);
	when(sns.listTopics(new ListTopicsRequest(null)))
			.thenReturn(new ListTopicsResult());

	DynamicTopicDestinationResolver resolver = new DynamicTopicDestinationResolver(
			sns);

	// Assert
	assertThatThrownBy(() -> resolver.resolveDestination("test"))
			.isInstanceOf(IllegalArgumentException.class)
			.hasMessageContaining("No topic found for name :'test'");
}
 
Example #3
Source File: DynamicTopicDestinationResolverTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void resolveDestination_withNonExistentTopicAndWithMarkerReturnedOnListTopics_shouldCallListMultipleTimeWithMarkerAndThrowIllegalArgumentException()
		// @checkstyle:on
		throws Exception {
	// Arrange
	AmazonSNS sns = mock(AmazonSNS.class);
	when(sns.listTopics(new ListTopicsRequest(null)))
			.thenReturn(new ListTopicsResult().withNextToken("foo"));
	when(sns.listTopics(new ListTopicsRequest("foo")))
			.thenReturn(new ListTopicsResult());

	DynamicTopicDestinationResolver resolver = new DynamicTopicDestinationResolver(
			sns);

	// Assert
	assertThatThrownBy(() -> resolver.resolveDestination("test"))
			.isInstanceOf(IllegalArgumentException.class)
			.hasMessageContaining("No topic found for name :'test'");
}
 
Example #4
Source File: DynamicTopicDestinationResolverTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void resolveDestination_withExistentTopic_returnsTopicArnFoundWhileListingTopic()
		throws Exception {
	// Arrange
	String topicArn = "arn:aws:sns:eu-west:123456789012:test";

	AmazonSNS sns = mock(AmazonSNS.class);
	when(sns.listTopics(new ListTopicsRequest(null))).thenReturn(
			new ListTopicsResult().withTopics(new Topic().withTopicArn(topicArn)));

	DynamicTopicDestinationResolver resolver = new DynamicTopicDestinationResolver(
			sns);

	// Act
	String resolvedDestinationName = resolver.resolveDestination("test");

	// Assert
	assertThat(resolvedDestinationName).isEqualTo(topicArn);
}
 
Example #5
Source File: DynamicTopicDestinationResolverTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void resolveDestination_withExistentTopicAndMarker_returnsTopicArnFoundWhileListingTopic()
		throws Exception {
	// Arrange

	AmazonSNS sns = mock(AmazonSNS.class);
	when(sns.listTopics(new ListTopicsRequest(null)))
			.thenReturn(new ListTopicsResult().withNextToken("mark"));

	String topicArn = "arn:aws:sns:eu-west:123456789012:test";
	when(sns.listTopics(new ListTopicsRequest("mark"))).thenReturn(
			new ListTopicsResult().withTopics(new Topic().withTopicArn(topicArn)));

	DynamicTopicDestinationResolver resolver = new DynamicTopicDestinationResolver(
			sns);

	// Act
	String resolvedDestinationName = resolver.resolveDestination("test");

	// Assert
	assertThat(resolvedDestinationName).isEqualTo(topicArn);
}
 
Example #6
Source File: DynamicTopicDestinationResolverTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void resolveDestination_withResourceIdResolver_shouldCallIt() throws Exception {
	// Arrange
	String physicalTopicName = "arn:aws:sns:eu-west:123456789012:myTopic";
	String logicalTopicName = "myTopic";

	ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);
	when(resourceIdResolver.resolveToPhysicalResourceId(logicalTopicName))
			.thenReturn(physicalTopicName);

	AmazonSNS sns = mock(AmazonSNS.class);
	when(sns.listTopics(new ListTopicsRequest(null)))
			.thenReturn(new ListTopicsResult()
					.withTopics(new Topic().withTopicArn(physicalTopicName)));

	DynamicTopicDestinationResolver resolver = new DynamicTopicDestinationResolver(
			sns, resourceIdResolver);

	// Assert
	String resolvedDestinationName = resolver.resolveDestination(logicalTopicName);

	// Assert
	assertThat(resolvedDestinationName).isEqualTo(physicalTopicName);
}
 
Example #7
Source File: NotificationMessagingTemplateTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void send_validTextMessage_usesTopicChannel() throws Exception {
	// Arrange
	AmazonSNS amazonSns = mock(AmazonSNS.class);
	NotificationMessagingTemplate notificationMessagingTemplate = new NotificationMessagingTemplate(
			amazonSns);
	String physicalTopicName = "arn:aws:sns:eu-west:123456789012:test";
	when(amazonSns.listTopics(new ListTopicsRequest(null)))
			.thenReturn(new ListTopicsResult()
					.withTopics(new Topic().withTopicArn(physicalTopicName)));
	notificationMessagingTemplate.setDefaultDestinationName(physicalTopicName);

	// Act
	notificationMessagingTemplate
			.send(MessageBuilder.withPayload("Message content").build());

	// Assert
	verify(amazonSns)
			.publish(new PublishRequest(physicalTopicName, "Message content", null)
					.withMessageAttributes(isNotNull()));
}
 
Example #8
Source File: NotificationMessagingTemplateTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void convertAndSend_withDestinationPayloadAndSubject_shouldSetSubject()
		throws Exception {
	// Arrange
	AmazonSNS amazonSns = mock(AmazonSNS.class);
	NotificationMessagingTemplate notificationMessagingTemplate = new NotificationMessagingTemplate(
			amazonSns);
	String physicalTopicName = "arn:aws:sns:eu-west:123456789012:test";
	when(amazonSns.listTopics(new ListTopicsRequest(null)))
			.thenReturn(new ListTopicsResult()
					.withTopics(new Topic().withTopicArn(physicalTopicName)));

	// Act
	notificationMessagingTemplate.sendNotification(physicalTopicName, "My message",
			"My subject");

	// Assert
	verify(amazonSns)
			.publish(new PublishRequest(physicalTopicName, "My message", "My subject")
					.withMessageAttributes(isNotNull()));
}
 
Example #9
Source File: NotificationMessagingTemplateTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void convertAndSend_withPayloadAndSubject_shouldSetSubject() throws Exception {
	// Arrange
	AmazonSNS amazonSns = mock(AmazonSNS.class);
	NotificationMessagingTemplate notificationMessagingTemplate = new NotificationMessagingTemplate(
			amazonSns);
	String physicalTopicName = "arn:aws:sns:eu-west:123456789012:test";
	when(amazonSns.listTopics(new ListTopicsRequest(null)))
			.thenReturn(new ListTopicsResult()
					.withTopics(new Topic().withTopicArn(physicalTopicName)));
	notificationMessagingTemplate.setDefaultDestinationName(physicalTopicName);

	// Act
	notificationMessagingTemplate.sendNotification("My message", "My subject");

	// Assert
	verify(amazonSns)
			.publish(new PublishRequest(physicalTopicName, "My message", "My subject")
					.withMessageAttributes(isNotNull()));
}
 
Example #10
Source File: SNSImpl.java    From aws-sdk-java-resources with Apache License 2.0 5 votes vote down vote up
@Override
public TopicCollection getTopics(ListTopicsRequest request) {
    ResourceCollectionImpl result = service.getCollection("Topics",
            request);

    if (result == null) return null;
    return new TopicCollectionImpl(result);
}
 
Example #11
Source File: SNSImpl.java    From aws-sdk-java-resources with Apache License 2.0 4 votes vote down vote up
@Override
public TopicCollection getTopics() {
    return getTopics((ListTopicsRequest)null);
}
 
Example #12
Source File: SNS.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieves the Topics collection referenced by this resource.
 */
TopicCollection getTopics(ListTopicsRequest request);