Search in sources :

Example 1 with ResourceIdResolver

use of io.awspring.cloud.core.env.ResourceIdResolver in project spring-cloud-aws by awspring.

the class StackConfigurationBeanDefinitionParserTest method resourceIdResolverResolveToPhysicalResourceId_stackConfigurationWithStaticNameAndLogicalResourceIdOfExistingResourceProvided_returnsPhysicalResourceId.

// @checkstyle:off
@Test
void resourceIdResolverResolveToPhysicalResourceId_stackConfigurationWithStaticNameAndLogicalResourceIdOfExistingResourceProvided_returnsPhysicalResourceId() {
    // @checkstyle:on
    // Arrange
    GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
    AmazonCloudFormation amazonCloudFormation = Mockito.mock(AmazonCloudFormation.class);
    when(amazonCloudFormation.listStackResources(new ListStackResourcesRequest().withStackName("IntegrationTestStack"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary().withLogicalResourceId("EmptyBucket").withPhysicalResourceId("integrationteststack-emptybucket-foo")));
    applicationContext.load(new ClassPathResource(getClass().getSimpleName() + "-staticStackName.xml", getClass()));
    applicationContext.getBeanFactory().registerSingleton(getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation);
    applicationContext.refresh();
    ResourceIdResolver resourceIdResolver = applicationContext.getBean(ResourceIdResolver.class);
    // Act
    String physicalResourceId = resourceIdResolver.resolveToPhysicalResourceId("EmptyBucket");
    // Assert
    assertThat(physicalResourceId).startsWith("integrationteststack-emptybucket-");
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) ResourceIdResolver(io.awspring.cloud.core.env.ResourceIdResolver) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 2 with ResourceIdResolver

use of io.awspring.cloud.core.env.ResourceIdResolver in project spring-cloud-aws by awspring.

the class StackConfigurationBeanDefinitionParserTest method resourceIdResolverResolveToPhysicalResourceId_logicalResourceIdOfNonExistingResourceProvided_returnsLogicalResourceIdAsPhysicalResourceId.

// @checkstyle:off
@Test
void resourceIdResolverResolveToPhysicalResourceId_logicalResourceIdOfNonExistingResourceProvided_returnsLogicalResourceIdAsPhysicalResourceId() {
    // @checkstyle:on
    // Arrange
    GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
    AmazonCloudFormation amazonCloudFormation = Mockito.mock(AmazonCloudFormation.class);
    when(amazonCloudFormation.listStackResources(new ListStackResourcesRequest().withStackName("IntegrationTestStack"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary()));
    applicationContext.load(new ClassPathResource(getClass().getSimpleName() + "-staticStackName.xml", getClass()));
    applicationContext.getBeanFactory().registerSingleton(getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation);
    applicationContext.refresh();
    ResourceIdResolver resourceIdResolver = applicationContext.getBean(ResourceIdResolver.class);
    // Act
    String physicalResourceId = resourceIdResolver.resolveToPhysicalResourceId("nonExistingLogicalResourceId");
    // Assert
    assertThat(physicalResourceId).isEqualTo("nonExistingLogicalResourceId");
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) ResourceIdResolver(io.awspring.cloud.core.env.ResourceIdResolver) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 3 with ResourceIdResolver

use of io.awspring.cloud.core.env.ResourceIdResolver in project spring-cloud-aws by awspring.

the class CacheBeanDefinitionParserTest method parseInternal_clusterCacheConfigurationWithLogicalName_returnsConfiguredClusterCacheWithPhysicalName.

@Test
void parseInternal_clusterCacheConfigurationWithLogicalName_returnsConfiguredClusterCacheWithPhysicalName() throws Exception {
    // Arrange
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    // Register a mock object which will be used to replay service calls
    BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(Mockito.class);
    beanDefinitionBuilder.setFactoryMethod("mock");
    beanDefinitionBuilder.addConstructorArgValue(AmazonElastiCache.class);
    beanFactory.registerBeanDefinition(AmazonWebserviceClientConfigurationUtils.getBeanName(AmazonElastiCacheClient.class.getName()), beanDefinitionBuilder.getBeanDefinition());
    BeanDefinitionBuilder resourceIdBuilder = BeanDefinitionBuilder.rootBeanDefinition(Mockito.class);
    resourceIdBuilder.setFactoryMethod("mock");
    resourceIdBuilder.addConstructorArgValue(ResourceIdResolver.class);
    beanFactory.registerBeanDefinition(GlobalBeanDefinitionUtils.RESOURCE_ID_RESOLVER_BEAN_NAME, resourceIdBuilder.getBeanDefinition());
    // Load xml file
    XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
    xmlBeanDefinitionReader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-elastiCacheConfigStackConfigured.xml", getClass()));
    AmazonElastiCache client = beanFactory.getBean(AmazonWebserviceClientConfigurationUtils.getBeanName(AmazonElastiCacheClient.class.getName()), AmazonElastiCache.class);
    ResourceIdResolver resourceIdResolver = beanFactory.getBean(GlobalBeanDefinitionUtils.RESOURCE_ID_RESOLVER_BEAN_NAME, ResourceIdResolver.class);
    when(resourceIdResolver.resolveToPhysicalResourceId("testMemcached")).thenReturn("memcached");
    // Replay invocation that will be called
    DescribeCacheClustersRequest memcached = new DescribeCacheClustersRequest().withCacheClusterId("memcached");
    memcached.setShowCacheNodeInfo(true);
    when(client.describeCacheClusters(memcached)).thenReturn(new DescribeCacheClustersResult().withCacheClusters(new CacheCluster().withCacheClusterId("memcached").withConfigurationEndpoint(new Endpoint().withAddress("localhost").withPort(Integer.parseInt(System.getProperty("memcachedPort")))).withCacheClusterStatus("available").withEngine("memcached")));
    // Act
    CacheManager cacheManager = beanFactory.getBean(CacheManager.class);
    Cache cache = cacheManager.getCache("testMemcached");
    cache.put("foo", "bar");
    cache.evict("foo");
    // Assert
    assertThat(cacheManager).isNotNull();
    assertThat(cache).isNotNull();
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) ResourceIdResolver(io.awspring.cloud.core.env.ResourceIdResolver) Endpoint(com.amazonaws.services.elasticache.model.Endpoint) DescribeCacheClustersResult(com.amazonaws.services.elasticache.model.DescribeCacheClustersResult) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) AmazonElastiCache(com.amazonaws.services.elasticache.AmazonElastiCache) DescribeCacheClustersRequest(com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest) CacheManager(org.springframework.cache.CacheManager) CacheCluster(com.amazonaws.services.elasticache.model.CacheCluster) ClassPathResource(org.springframework.core.io.ClassPathResource) Cache(org.springframework.cache.Cache) AmazonElastiCache(com.amazonaws.services.elasticache.AmazonElastiCache) Test(org.junit.jupiter.api.Test)

Example 4 with ResourceIdResolver

use of io.awspring.cloud.core.env.ResourceIdResolver in project spring-cloud-aws by awspring.

the class StackConfigurationBeanDefinitionParserTest method resourceIdResolver_stackConfiguration_resourceIdResolverBeanExposed.

@Test
void resourceIdResolver_stackConfiguration_resourceIdResolverBeanExposed() {
    // Arrange
    GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
    AmazonCloudFormation amazonCloudFormation = Mockito.mock(AmazonCloudFormation.class);
    when(amazonCloudFormation.listStackResources(new ListStackResourcesRequest().withStackName("IntegrationTestStack"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary()));
    applicationContext.load(new ClassPathResource(getClass().getSimpleName() + "-staticStackName.xml", getClass()));
    applicationContext.getBeanFactory().registerSingleton(getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation);
    applicationContext.refresh();
    // Act
    ResourceIdResolver resourceIdResolver = applicationContext.getBean(ResourceIdResolver.class);
    // Assert
    assertThat(resourceIdResolver).isNotNull();
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) ResourceIdResolver(io.awspring.cloud.core.env.ResourceIdResolver) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 5 with ResourceIdResolver

use of io.awspring.cloud.core.env.ResourceIdResolver in project spring-cloud-aws by awspring.

the class ElastiCacheFactoryBeanTest method getObject_availableClusterWithLogicalName_returnsConfigurationMemcachedClientWithPhysicalName.

@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();
}
Also used : Endpoint(com.amazonaws.services.elasticache.model.Endpoint) ResourceIdResolver(io.awspring.cloud.core.env.ResourceIdResolver) DescribeCacheClustersResult(com.amazonaws.services.elasticache.model.DescribeCacheClustersResult) AmazonElastiCache(com.amazonaws.services.elasticache.AmazonElastiCache) DescribeCacheClustersRequest(com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest) CacheCluster(com.amazonaws.services.elasticache.model.CacheCluster) Cache(org.springframework.cache.Cache) AmazonElastiCache(com.amazonaws.services.elasticache.AmazonElastiCache) Test(org.junit.jupiter.api.Test)

Aggregations

ResourceIdResolver (io.awspring.cloud.core.env.ResourceIdResolver)13 Test (org.junit.jupiter.api.Test)13 ClassPathResource (org.springframework.core.io.ClassPathResource)5 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)4 ListStackResourcesRequest (com.amazonaws.services.cloudformation.model.ListStackResourcesRequest)4 ListStackResourcesResult (com.amazonaws.services.cloudformation.model.ListStackResourcesResult)4 StackResourceSummary (com.amazonaws.services.cloudformation.model.StackResourceSummary)4 AmazonRDS (com.amazonaws.services.rds.AmazonRDS)4 GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)4 AmazonElastiCache (com.amazonaws.services.elasticache.AmazonElastiCache)2 CacheCluster (com.amazonaws.services.elasticache.model.CacheCluster)2 DescribeCacheClustersRequest (com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest)2 DescribeCacheClustersResult (com.amazonaws.services.elasticache.model.DescribeCacheClustersResult)2 Endpoint (com.amazonaws.services.elasticache.model.Endpoint)2 AmazonIdentityManagement (com.amazonaws.services.identitymanagement.AmazonIdentityManagement)2 GetUserResult (com.amazonaws.services.identitymanagement.model.GetUserResult)2 User (com.amazonaws.services.identitymanagement.model.User)2 DBInstance (com.amazonaws.services.rds.model.DBInstance)2 DescribeDBInstancesRequest (com.amazonaws.services.rds.model.DescribeDBInstancesRequest)2 DescribeDBInstancesResult (com.amazonaws.services.rds.model.DescribeDBInstancesResult)2