use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.
the class AmazonRdsDataSourceUserTagsFactoryBeanTest method getObject_instanceWithOutTags_emptyMapReturned.
@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();
}
use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.
the class AmazonRdsReadReplicaAwareDataSourceFactoryBeanTest method afterPropertiesSet_instanceWithoutReadReplica_createsNoDataSourceRouter.
@Test
void afterPropertiesSet_instanceWithoutReadReplica_createsNoDataSourceRouter() throws Exception {
// Arrange
AmazonRDS amazonRDS = mock(AmazonRDS.class);
DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class);
when(amazonRDS.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).thenReturn(new DescribeDBInstancesResult().withDBInstances(new DBInstance().withDBInstanceStatus("available").withDBName("test").withDBInstanceIdentifier("test").withEngine("mysql").withMasterUsername("admin").withEndpoint(new Endpoint().withAddress("localhost").withPort(3306))));
AmazonRdsReadReplicaAwareDataSourceFactoryBean factoryBean = new AmazonRdsReadReplicaAwareDataSourceFactoryBean(amazonRDS, "test", "secret");
factoryBean.setDataSourceFactory(dataSourceFactory);
when(dataSourceFactory.createDataSource(new DataSourceInformation(DatabaseType.MYSQL, "localhost", 3306, "test", "admin", "secret"))).thenReturn(mock(DataSource.class));
// Act
factoryBean.afterPropertiesSet();
// Assert
DataSource datasource = factoryBean.getObject();
assertThat(datasource).isNotNull();
verify(dataSourceFactory, times(1)).createDataSource(new DataSourceInformation(DatabaseType.MYSQL, "localhost", 3306, "test", "admin", "secret"));
}
use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.
the class DatabaseInstanceStatusRetryPolicyTest method canRetry_noExceptionRegistered_returnsTrue.
@Test
void canRetry_noExceptionRegistered_returnsTrue() throws Exception {
// Arrange
AmazonRDS amazonRDS = mock(AmazonRDS.class);
DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy(amazonRDS, "test");
RetryContext retryContext = new RetryContextSupport(null);
// Act
policy.open(retryContext);
// Assert
assertThat(policy.canRetry(retryContext)).isTrue();
}
use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.
the class DatabaseInstanceStatusRetryPolicyTest method canRetry_retryPossibleDueToAvailableDatabase_returnsTrue.
@Test
void canRetry_retryPossibleDueToAvailableDatabase_returnsTrue() throws Exception {
// Arrange
AmazonRDS amazonRDS = mock(AmazonRDS.class);
DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy(amazonRDS, "test");
when(amazonRDS.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).thenReturn(new DescribeDBInstancesResult().withDBInstances(new DBInstance().withDBInstanceStatus("available")));
RetryContext retryContext = policy.open(new RetryContextSupport(null));
// Act
policy.registerThrowable(retryContext, new TransientDataAccessResourceException("not available"));
// Assert
assertThat(policy.canRetry(retryContext)).isTrue();
policy.close(retryContext);
}
use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.
the class AmazonRdsRetryInterceptorBeanDefinitionParserTest method parseInternal_customRegionConfigured_createsAmazonRdsClientWithCustomRegionConfigured.
@Test
void parseInternal_customRegionConfigured_createsAmazonRdsClientWithCustomRegionConfigured() throws Exception {
// Arrange
ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-customRegion.xml", getClass());
// Act
AmazonRDS amazonRDS = classPathXmlApplicationContext.getBean(AmazonRDS.class);
// Assert
assertThat(ReflectionTestUtils.getField(amazonRDS, "endpoint").toString()).isEqualTo("https://rds.eu-west-1.amazonaws.com");
}
Aggregations