org.springframework.cloud.aws.core.env.ResourceIdResolver Java Examples

The following examples show how to use org.springframework.cloud.aws.core.env.ResourceIdResolver. 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: AmazonS3SinkConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
@Bean
@ServiceActivator(inputChannel = Sink.INPUT)
public MessageHandler amazonS3MessageHandler(AmazonS3 amazonS3, ResourceIdResolver resourceIdResolver,
		AmazonS3SinkProperties s3SinkProperties) {
	S3MessageHandler s3MessageHandler;
	if (s3SinkProperties.getBucket() != null) {
		s3MessageHandler = new S3MessageHandler(amazonS3, s3SinkProperties.getBucket());
	}
	else {
		s3MessageHandler = new S3MessageHandler(amazonS3, s3SinkProperties.getBucketExpression());
	}
	s3MessageHandler.setResourceIdResolver(resourceIdResolver);
	s3MessageHandler.setKeyExpression(s3SinkProperties.getKeyExpression());
	if (s3SinkProperties.getAcl() != null) {
		s3MessageHandler.setObjectAclExpression(new ValueExpression<>(s3SinkProperties.getAcl()));
	}
	else {
		s3MessageHandler.setObjectAclExpression(s3SinkProperties.getAclExpression());
	}
	s3MessageHandler.setUploadMetadataProvider(this.uploadMetadataProvider);
	s3MessageHandler.setProgressListener(this.s3ProgressListener);
	return s3MessageHandler;
}
 
Example #2
Source File: QueueMessagingTemplateTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void instantiation_withConverter_shouldAddItToTheCompositeConverter() {
	// Arrange
	SimpleMessageConverter simpleMessageConverter = new SimpleMessageConverter();

	// Act
	QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(
			createAmazonSqs(), (ResourceIdResolver) null, simpleMessageConverter);

	// Assert
	assertThat(
			((CompositeMessageConverter) queueMessagingTemplate.getMessageConverter())
					.getConverters()).hasSize(2);
	assertThat(
			((CompositeMessageConverter) queueMessagingTemplate.getMessageConverter())
					.getConverters().get(1)).isEqualTo(simpleMessageConverter);
}
 
Example #3
Source File: DynamicQueueUrlDestinationResolverTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void resolveDestination_withResourceIdResolver_nonUrlId_shouldGetUrlByResolvedName()
		throws Exception {
	String queueUrl = "http://queue.com";
	String resolvedQueueName = "some-queue-name";
	AmazonSQS amazonSqs = mock(AmazonSQS.class);
	when(amazonSqs.getQueueUrl(new GetQueueUrlRequest(resolvedQueueName)))
			.thenReturn(new GetQueueUrlResult().withQueueUrl(queueUrl));
	ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);
	when(resourceIdResolver.resolveToPhysicalResourceId(anyString()))
			.thenReturn(resolvedQueueName);
	DynamicQueueUrlDestinationResolver dynamicQueueUrlDestinationResolver = new DynamicQueueUrlDestinationResolver(
			amazonSqs, resourceIdResolver);

	String physicalResourceId = dynamicQueueUrlDestinationResolver
			.resolveDestination("testQueue");

	assertThat(physicalResourceId).isEqualTo("http://queue.com");
}
 
Example #4
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 #5
Source File: SqsConfiguration.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
public SqsConfiguration(
		ObjectProvider<SimpleMessageListenerContainerFactory> simpleMessageListenerContainerFactory,
		ObjectProvider<QueueMessageHandlerFactory> queueMessageHandlerFactory,
		BeanFactory beanFactory,
		ObjectProvider<ResourceIdResolver> resourceIdResolver,
		ObjectProvider<MappingJackson2MessageConverter> mappingJackson2MessageConverter,
		ObjectProvider<ObjectMapper> objectMapper) {
	this.simpleMessageListenerContainerFactory = simpleMessageListenerContainerFactory
			.getIfAvailable(SimpleMessageListenerContainerFactory::new);
	this.queueMessageHandlerFactory = queueMessageHandlerFactory
			.getIfAvailable(QueueMessageHandlerFactory::new);
	this.beanFactory = beanFactory;
	this.resourceIdResolver = resourceIdResolver.getIfAvailable();
	this.mappingJackson2MessageConverter = mappingJackson2MessageConverter
			.getIfAvailable();
	this.objectMapper = objectMapper.getIfAvailable();
}
 
Example #6
Source File: AmazonS3SourceConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
@Bean
public S3InboundFileSynchronizer s3InboundFileSynchronizer(AmazonS3 amazonS3,
		ResourceIdResolver resourceIdResolver) {
	S3SessionFactory s3SessionFactory = new S3SessionFactory(amazonS3, resourceIdResolver);
	S3InboundFileSynchronizer synchronizer = new S3InboundFileSynchronizer(s3SessionFactory);
	synchronizer.setDeleteRemoteFiles(this.s3SourceProperties.isDeleteRemoteFiles());
	synchronizer.setPreserveTimestamp(this.s3SourceProperties.isPreserveTimestamp());
	String remoteDir = this.s3SourceProperties.getRemoteDir();
	synchronizer.setRemoteDirectory(remoteDir);
	synchronizer.setRemoteFileSeparator(this.s3SourceProperties.getRemoteFileSeparator());
	synchronizer.setTemporaryFileSuffix(this.s3SourceProperties.getTmpFileSuffix());

	if (StringUtils.hasText(this.s3SourceProperties.getFilenamePattern())) {
		synchronizer.setFilter(new S3SimplePatternFileListFilter(this.s3SourceProperties.getFilenamePattern()));
	}
	else if (this.s3SourceProperties.getFilenameRegex() != null) {
		synchronizer.setFilter(new S3RegexPatternFileListFilter(this.s3SourceProperties.getFilenameRegex()));
	}

	return synchronizer;
}
 
Example #7
Source File: JavaQueueMessagingTemplateIntegrationTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Bean
public QueueMessagingTemplate queueMessagingTemplateWithCustomConverter(
		AmazonSQSAsync amazonSqs, ResourceIdResolver resourceIdResolver) {
	QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(
			amazonSqs, resourceIdResolver);
	queueMessagingTemplate.setDefaultDestinationName("StreamQueue");
	queueMessagingTemplate.setMessageConverter(new ObjectMessageConverter());

	return queueMessagingTemplate;
}
 
Example #8
Source File: QueueMessagingTemplateTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void instantiation_withoutConverter_shouldAddDefaultJacksonConverterToTheCompositeConverter() {
	// Act
	QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(
			createAmazonSqs(), (ResourceIdResolver) null, null);

	// Assert
	assertThat(
			((CompositeMessageConverter) queueMessagingTemplate.getMessageConverter())
					.getConverters()).hasSize(2);
	assertThat(
			((CompositeMessageConverter) queueMessagingTemplate.getMessageConverter())
					.getConverters().get(1))
							.isInstanceOf(MappingJackson2MessageConverter.class);
}
 
Example #9
Source File: DynamicQueueUrlDestinationResolverTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void resolveDestination_withResourceIdResolver_shouldUseIt() throws Exception {
	AmazonSQS amazonSqs = mock(AmazonSQS.class);
	ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);
	when(resourceIdResolver.resolveToPhysicalResourceId(anyString()))
			.thenReturn("http://queue.com");
	DynamicQueueUrlDestinationResolver dynamicQueueUrlDestinationResolver = new DynamicQueueUrlDestinationResolver(
			amazonSqs, resourceIdResolver);

	String physicalResourceId = dynamicQueueUrlDestinationResolver
			.resolveDestination("testQueue");

	assertThat(physicalResourceId).isEqualTo("http://queue.com");

}
 
Example #10
Source File: DynamicQueueUrlDestinationResolver.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
public DynamicQueueUrlDestinationResolver(AmazonSQS amazonSqs,
		ResourceIdResolver resourceIdResolver) {
	Assert.notNull(amazonSqs, "amazonSqs must not be null");

	this.amazonSqs = amazonSqs;
	this.resourceIdResolver = resourceIdResolver;
}
 
Example #11
Source File: JavaQueueMessagingTemplateIntegrationTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Bean
public QueueMessagingTemplate defaultQueueMessagingTemplate(
		AmazonSQSAsync amazonSqs, ResourceIdResolver resourceIdResolver) {
	QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(
			amazonSqs, resourceIdResolver);
	queueMessagingTemplate.setDefaultDestinationName("JsonQueue");

	return queueMessagingTemplate;
}
 
Example #12
Source File: BootQueueMessagingTemplateIntegrationTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Bean
public QueueMessagingTemplate queueMessagingTemplateWithCustomConverter(
		AmazonSQSAsync amazonSqs, ResourceIdResolver resourceIdResolver) {
	QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(
			amazonSqs, resourceIdResolver);
	queueMessagingTemplate.setDefaultDestinationName("StreamQueue");
	queueMessagingTemplate.setMessageConverter(new ObjectMessageConverter());

	return queueMessagingTemplate;
}
 
Example #13
Source File: BootQueueMessagingTemplateIntegrationTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Bean
public QueueMessagingTemplate defaultQueueMessagingTemplate(
		AmazonSQSAsync amazonSqs, ResourceIdResolver resourceIdResolver) {
	QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(
			amazonSqs, resourceIdResolver);
	queueMessagingTemplate.setDefaultDestinationName("JsonQueue");

	return queueMessagingTemplate;
}
 
Example #14
Source File: ElastiCacheFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void getObject_availableClusterWithLogicalName_returnsConfigurationMemcachedClientWithPhysicalName()
		throws Exception {
	// Arrange
	AmazonElastiCache amazonElastiCache = mock(AmazonElastiCacheClient.class);
	DescribeCacheClustersRequest testCache = new DescribeCacheClustersRequest()
			.withCacheClusterId("testCache");
	testCache.setShowCacheNodeInfo(true);

	when(amazonElastiCache.describeCacheClusters(testCache)).thenReturn(
			new DescribeCacheClustersResult().withCacheClusters(new CacheCluster()
					.withConfigurationEndpoint(
							new Endpoint().withAddress("localhost").withPort(45678))
					.withCacheClusterStatus("available").withEngine("memcached")));

	ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);
	when(resourceIdResolver.resolveToPhysicalResourceId("test"))
			.thenReturn("testCache");

	ElastiCacheFactoryBean elastiCacheFactoryBean = new ElastiCacheFactoryBean(
			amazonElastiCache, "test", resourceIdResolver,
			Collections.<CacheFactory>singletonList(
					new TestCacheFactory("test", "localhost", 45678)));

	// Act
	elastiCacheFactoryBean.afterPropertiesSet();
	Cache cache = elastiCacheFactoryBean.getObject();

	// Assert
	assertThat(cache).isNotNull();
}
 
Example #15
Source File: GlobalBeanDefinitionUtilsTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void retrieveResourceIdResolverBeanName_resourceIdResolverBeanNotYetRegistered_resourceIdResolverBeanIsRegistered() {
	// @checkstyle:on
	// Arrange
	DefaultListableBeanFactory registry = new DefaultListableBeanFactory();

	// Act
	GlobalBeanDefinitionUtils.retrieveResourceIdResolverBeanName(registry);

	// Assert
	assertThat(registry.getBeanNamesForType(ResourceIdResolver.class).length)
			.isEqualTo(1);
}
 
Example #16
Source File: ElastiCacheCacheConfigurer.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
public ElastiCacheCacheConfigurer(AmazonElastiCache amazonElastiCache,
		ResourceIdResolver resourceIdResolver, List<String> cacheNames,
		List<CacheFactory> cacheFactories) {
	this.cacheNames = cacheNames;
	this.amazonElastiCache = amazonElastiCache;
	this.resourceIdResolver = resourceIdResolver;
	this.cacheFactories = cacheFactories;
}
 
Example #17
Source File: ElastiCacheCachingConfiguration.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Bean
public CachingConfigurer cachingConfigurer(AmazonElastiCache amazonElastiCache,
		ResourceIdResolver resourceIdResolver, List<CacheFactory> cacheFactories) {
	if (this.annotationAttributes != null
			&& this.annotationAttributes.getAnnotationArray("value").length > 0) {
		return new ElastiCacheCacheConfigurer(amazonElastiCache, resourceIdResolver,
				getCacheNamesFromCacheClusterConfigs(
						this.annotationAttributes.getAnnotationArray("value")),
				cacheFactories);
	}
	else {
		return new ElastiCacheCacheConfigurer(amazonElastiCache, resourceIdResolver,
				getConfiguredCachesInStack(), cacheFactories);
	}
}
 
Example #18
Source File: ElastiCacheFactoryBean.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
public ElastiCacheFactoryBean(AmazonElastiCache amazonElastiCache,
		String cacheClusterId, ResourceIdResolver resourceIdResolver,
		List<? extends CacheFactory> cacheFactories) {
	this.amazonElastiCache = amazonElastiCache;
	this.resourceIdResolver = resourceIdResolver;
	this.cacheClusterId = cacheClusterId;
	this.cacheFactories = cacheFactories;
}
 
Example #19
Source File: ContextStackAutoConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void resourceIdResolver_withoutAnyStackConfiguration_availableAsConfiguredBean() {
	this.contextRunner.withPropertyValues("cloud.aws.stack.auto:false")
			.run(context -> {
				assertThat(context.getBean(ResourceIdResolver.class)).isNotNull();
				assertThat(
						context.getBeansOfType(StackResourceRegistry.class).isEmpty())
								.isTrue();
			});
}
 
Example #20
Source File: ElastiCacheAutoConfiguration.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(CachingConfigurer.class)
public CachingConfigurer cachingConfigurer(AmazonElastiCache amazonElastiCache,
		ResourceIdResolver resourceIdResolver, List<CacheFactory> cacheFactories) {
	if (!this.properties.getClusters().isEmpty()) {
		return new ElastiCacheCacheConfigurer(amazonElastiCache, resourceIdResolver,
				this.properties.getCacheNames(), cacheFactories);
	}
	else {
		return new ElastiCacheCacheConfigurer(amazonElastiCache, resourceIdResolver,
				getConfiguredCachesInStack(), cacheFactories);
	}
}
 
Example #21
Source File: DatabaseInstanceStatusRetryPolicyTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void canRetry_withResourceIdResolver_returnsTrue() throws Exception {
	// Arrange
	AmazonRDS amazonRDS = mock(AmazonRDS.class);
	ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);

	DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy(
			amazonRDS, "foo");
	when(amazonRDS.describeDBInstances(
			new DescribeDBInstancesRequest().withDBInstanceIdentifier("test")))
					.thenReturn(new DescribeDBInstancesResult().withDBInstances(
							new DBInstance().withDBInstanceStatus("available")));

	when(resourceIdResolver.resolveToPhysicalResourceId("foo")).thenReturn("test");

	policy.setResourceIdResolver(resourceIdResolver);

	RetryContext retryContext = policy.open(new RetryContextSupport(null));

	// Act
	policy.registerThrowable(retryContext,
			new TransientDataAccessResourceException("not available"));

	// Assert
	assertThat(policy.canRetry(retryContext)).isTrue();
	policy.close(retryContext);
}
 
Example #22
Source File: SpringCloudStreamAwsApplicationsITCase.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Test
public void testS3Source() throws IOException, InterruptedException {
	String bucket = "TestBucket";
	String key = "foo";
	String content = "Spring Cloud Stream AWS S3 Source test";

	this.applicationContext = SpringApplication.run(S3SourceBootConfiguration.class,
			"--s3.remoteDir=" + bucket, "--file.consumer.mode=lines", "--file.consumer.with-markers=false");

	ResourceIdResolver resourceIdResolver = this.applicationContext.getBean(ResourceIdResolver.class);

	AmazonS3 amazonS3 = this.applicationContext.getBean(AmazonS3.class);
	ObjectMetadata objectMetadata = new ObjectMetadata();
	objectMetadata.setContentLength(content.length());
	String bucketName = resourceIdResolver.resolveToPhysicalResourceId(bucket);
	amazonS3.putObject(bucketName, key, new ByteArrayInputStream(content.getBytes("UTF-8")), objectMetadata);

	try {
		Source source = this.applicationContext.getBean(Source.class);
		MessageCollector messageCollector = this.applicationContext.getBean(MessageCollector.class);
		Message<?> received = messageCollector.forChannel(source.output()).poll(10, TimeUnit.SECONDS);
		assertNotNull(received);
		assertThat(received, hasHeader(FileHeaders.FILENAME, key));
		assertThat(received, hasPayload("Spring Cloud Stream AWS S3 Source test"));
	}
	finally {
		amazonS3.deleteObject(bucketName, key);
	}
}
 
Example #23
Source File: AmazonRdsDataSourceFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void newInstance_withResourceIdResolver_createsInstanceWithResolvedName()
		throws Exception {
	// Arrange
	AmazonRDS amazonRDS = mock(AmazonRDS.class);
	DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class);
	ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);
	DataSource dataSource = mock(DataSource.class);

	when(resourceIdResolver.resolveToPhysicalResourceId("test")).thenReturn("bar");

	when(amazonRDS.describeDBInstances(new DescribeDBInstancesRequest()
			.withDBInstanceIdentifier("bar"))).thenReturn(
					new DescribeDBInstancesResult().withDBInstances(new DBInstance()
							.withDBInstanceStatus("available").withDBName("test")
							.withDBInstanceIdentifier("bar").withEngine("mysql")
							.withMasterUsername("admin").withEndpoint(new Endpoint()
									.withAddress("localhost").withPort(3306))));

	when(dataSourceFactory.createDataSource(new DataSourceInformation(
			DatabaseType.MYSQL, "localhost", 3306, "test", "admin", "secret")))
					.thenReturn(dataSource);

	AmazonRdsDataSourceFactoryBean amazonRdsDataSourceFactoryBean = new AmazonRdsDataSourceFactoryBean(
			amazonRDS, "test", "secret");
	amazonRdsDataSourceFactoryBean.setDataSourceFactory(dataSourceFactory);
	amazonRdsDataSourceFactoryBean.setResourceIdResolver(resourceIdResolver);

	// Act
	amazonRdsDataSourceFactoryBean.afterPropertiesSet();

	// Assert
	assertThat(amazonRdsDataSourceFactoryBean.getObject()).isNotNull();

	verify(dataSourceFactory, times(1)).createDataSource(new DataSourceInformation(
			DatabaseType.MYSQL, "localhost", 3306, "test", "admin", "secret"));
}
 
Example #24
Source File: AmazonRdsDataSourceUserTagsFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void getObject_instanceWithOutTags_emptyMapReturned() throws Exception {
	// Arrange
	AmazonRDS amazonRds = mock(AmazonRDS.class);
	ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);
	AmazonIdentityManagement amazonIdentityManagement = mock(
			AmazonIdentityManagement.class);
	AmazonRdsDataSourceUserTagsFactoryBean factoryBean = new AmazonRdsDataSourceUserTagsFactoryBean(
			amazonRds, "test", amazonIdentityManagement);
	factoryBean.setResourceIdResolver(resourceIdResolver);
	factoryBean.setResourceIdResolver(resourceIdResolver);
	factoryBean.setRegion(Region.getRegion(Regions.EU_WEST_1));

	when(resourceIdResolver.resolveToPhysicalResourceId("test"))
			.thenReturn("stack-test");
	when(amazonIdentityManagement.getUser()).thenReturn(
			new GetUserResult().withUser(new User("/", "aemruli", "123456789012",
					"arn:aws:iam::1234567890:user/aemruli", new Date())));
	when(amazonRds.listTagsForResource(new ListTagsForResourceRequest()
			.withResourceName("arn:aws:rds:eu-west-1:1234567890:db:stack-test")))
					.thenReturn(new ListTagsForResourceResult());

	// Act
	factoryBean.afterPropertiesSet();
	Map<String, String> userTagMap = factoryBean.getObject();

	// Assert
	assertThat(userTagMap.isEmpty()).isTrue();
}
 
Example #25
Source File: AmazonRdsDataSourceUserTagsFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void getObject_instanceWithTagsConfiguredWithCustomResourceResolverAndCustomRegion_mapWithTagsReturned()
		throws Exception {
	// Arrange
	AmazonRDS amazonRds = mock(AmazonRDS.class);
	ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);
	AmazonIdentityManagement amazonIdentityManagement = mock(
			AmazonIdentityManagement.class);
	AmazonRdsDataSourceUserTagsFactoryBean factoryBean = new AmazonRdsDataSourceUserTagsFactoryBean(
			amazonRds, "test", amazonIdentityManagement);
	factoryBean.setResourceIdResolver(resourceIdResolver);
	factoryBean.setRegion(Region.getRegion(Regions.EU_WEST_1));

	when(resourceIdResolver.resolveToPhysicalResourceId("test"))
			.thenReturn("stack-test");
	when(amazonIdentityManagement.getUser()).thenReturn(
			new GetUserResult().withUser(new User("/", "aemruli", "123456789012",
					"arn:aws:iam::1234567890:user/aemruli", new Date())));
	when(amazonRds.listTagsForResource(new ListTagsForResourceRequest()
			.withResourceName("arn:aws:rds:eu-west-1:1234567890:db:stack-test")))
					.thenReturn(new ListTagsForResourceResult().withTagList(
							new Tag().withKey("key1").withValue("value1"),
							new Tag().withKey("key2").withValue("value2")));

	// Act
	factoryBean.afterPropertiesSet();
	Map<String, String> userTagMap = factoryBean.getObject();

	// Assert
	assertThat(userTagMap.get("key1")).isEqualTo("value1");
	assertThat(userTagMap.get("key2")).isEqualTo("value2");
}
 
Example #26
Source File: ReferenceApplication.java    From aws-refapp with Apache License 2.0 4 votes vote down vote up
@Bean
public NotificationMessagingTemplate notificationMessagingTemplate(AmazonSNS amazonSNS, ResourceIdResolver resourceIdResolver) {
    return new NotificationMessagingTemplate(amazonSNS, resourceIdResolver);
}
 
Example #27
Source File: ReferenceApplication.java    From aws-refapp with Apache License 2.0 4 votes vote down vote up
@Bean
public QueueMessagingTemplate queueMessagingTemplate(AmazonSQS amazonSqs, ResourceIdResolver resourceIdResolver) {
    return new QueueMessagingTemplate(amazonSqs, resourceIdResolver);
}
 
Example #28
Source File: AmazonRdsDataSourceUserTagsFactoryBean.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
public void setResourceIdResolver(ResourceIdResolver resourceIdResolver) {
	this.resourceIdResolver = resourceIdResolver;
}
 
Example #29
Source File: NotificationMessagingTemplate.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
public NotificationMessagingTemplate(AmazonSNS amazonSns,
		ResourceIdResolver resourceIdResolver, MessageConverter messageConverter) {
	super(new DynamicTopicDestinationResolver(amazonSns, resourceIdResolver));
	this.amazonSns = amazonSns;
	initMessageConverter(messageConverter);
}
 
Example #30
Source File: NotificationMessagingTemplate.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
public NotificationMessagingTemplate(AmazonSNS amazonSns,
		ResourceIdResolver resourceIdResolver) {
	this(amazonSns, resourceIdResolver, null);
}