use of com.amazonaws.services.cloudformation.model.ListStackResourcesRequest 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-");
}
use of com.amazonaws.services.cloudformation.model.ListStackResourcesRequest in project spring-cloud-aws by awspring.
the class StackConfigurationBeanDefinitionParserTest method parseInternal_stackConfigurationWithExternallyConfiguredCloudFormationClient_returnsConfiguredStackWithExternallyConfiguredClient.
// @checkstyle:off
@Test
void parseInternal_stackConfigurationWithExternallyConfiguredCloudFormationClient_returnsConfiguredStackWithExternallyConfiguredClient() throws Exception {
// @checkstyle:on
// Arrange
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-withCustomCloudFormationClient.xml", getClass()));
AmazonCloudFormation amazonCloudFormationMock = beanFactory.getBean(AmazonCloudFormation.class);
when(amazonCloudFormationMock.listStackResources(new ListStackResourcesRequest().withStackName("test"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary()));
when(amazonCloudFormationMock.describeStacks(new DescribeStacksRequest().withStackName("test"))).thenReturn(new DescribeStacksResult().withStacks(new Stack()));
// Act
StackResourceRegistry stackResourceRegistry = beanFactory.getBean(StackResourceRegistry.class);
// Assert
assertThat(stackResourceRegistry).isNotNull();
assertThat(beanFactory.containsBeanDefinition(getBeanName(AmazonCloudFormationClient.class.getName()))).isFalse();
verify(amazonCloudFormationMock, times(1)).listStackResources(new ListStackResourcesRequest().withStackName("test"));
beanFactory.getBean("customStackTags");
verify(amazonCloudFormationMock, times(1)).describeStacks(new DescribeStacksRequest().withStackName("test"));
}
use of com.amazonaws.services.cloudformation.model.ListStackResourcesRequest in project spring-cloud-aws by awspring.
the class StackConfigurationBeanDefinitionParserTest method stackResourceRegistry_stackConfigurationWithoutStaticName_stackResourceRegistryBeanExposedUnderGeneratedName.
// @checkstyle:off
@Test
void stackResourceRegistry_stackConfigurationWithoutStaticName_stackResourceRegistryBeanExposedUnderGeneratedName() throws Exception {
// @checkstyle:on
// Arrange
HttpServer server = MetaDataServer.setupHttpServer();
HttpContext httpContext = server.createContext("/latest/meta-data/instance-id", new MetaDataServer.HttpResponseWriterHandler("foo"));
GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
AmazonCloudFormation amazonCloudFormation = Mockito.mock(AmazonCloudFormation.class);
when(amazonCloudFormation.describeStackResources(new DescribeStackResourcesRequest().withPhysicalResourceId("foo"))).thenReturn(new DescribeStackResourcesResult().withStackResources(new StackResource().withStackName("test")));
when(amazonCloudFormation.listStackResources(new ListStackResourcesRequest().withStackName("test"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary()));
applicationContext.load(new ClassPathResource(getClass().getSimpleName() + "-autoDetectStackName.xml", getClass()));
applicationContext.getBeanFactory().registerSingleton(getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation);
applicationContext.refresh();
// Act
StackResourceRegistry autoDetectingStackNameProviderBasedStackResourceRegistry = applicationContext.getBean("io.awspring.cloud.core.env.stack.config.StackResourceRegistryFactoryBean#0", StackResourceRegistry.class);
// Assert
assertThat(autoDetectingStackNameProviderBasedStackResourceRegistry).isNotNull();
server.removeContext(httpContext);
}
use of com.amazonaws.services.cloudformation.model.ListStackResourcesRequest 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");
}
use of com.amazonaws.services.cloudformation.model.ListStackResourcesRequest 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();
}
Aggregations