Search in sources :

Example 1 with ListStackResourcesResult

use of com.amazonaws.services.cloudformation.model.ListStackResourcesResult 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 ListStackResourcesResult

use of com.amazonaws.services.cloudformation.model.ListStackResourcesResult 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"));
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) StackResourceRegistry(io.awspring.cloud.core.env.stack.StackResourceRegistry) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) ClassPathResource(org.springframework.core.io.ClassPathResource) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) DescribeStacksResult(com.amazonaws.services.cloudformation.model.DescribeStacksResult) Stack(com.amazonaws.services.cloudformation.model.Stack) Test(org.junit.jupiter.api.Test)

Example 3 with ListStackResourcesResult

use of com.amazonaws.services.cloudformation.model.ListStackResourcesResult 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);
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) HttpContext(com.sun.net.httpserver.HttpContext) DescribeStackResourcesRequest(com.amazonaws.services.cloudformation.model.DescribeStackResourcesRequest) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) ClassPathResource(org.springframework.core.io.ClassPathResource) DescribeStackResourcesResult(com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult) StackResourceRegistry(io.awspring.cloud.core.env.stack.StackResourceRegistry) HttpServer(com.sun.net.httpserver.HttpServer) MetaDataServer(io.awspring.cloud.context.MetaDataServer) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) StackResource(com.amazonaws.services.cloudformation.model.StackResource) Test(org.junit.jupiter.api.Test)

Example 4 with ListStackResourcesResult

use of com.amazonaws.services.cloudformation.model.ListStackResourcesResult 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 5 with ListStackResourcesResult

use of com.amazonaws.services.cloudformation.model.ListStackResourcesResult 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)

Aggregations

ListStackResourcesResult (com.amazonaws.services.cloudformation.model.ListStackResourcesResult)19 StackResourceSummary (com.amazonaws.services.cloudformation.model.StackResourceSummary)17 ListStackResourcesRequest (com.amazonaws.services.cloudformation.model.ListStackResourcesRequest)14 Test (org.junit.jupiter.api.Test)12 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)9 AwsLoadBalancer (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer)7 ClassPathResource (org.springframework.core.io.ClassPathResource)6 GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)5 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)4 ResourceIdResolver (io.awspring.cloud.core.env.ResourceIdResolver)4 StackResourceRegistry (io.awspring.cloud.core.env.stack.StackResourceRegistry)4 ArrayList (java.util.ArrayList)4 LoadBalancer (com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 AmazonCloudFormationClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient)3 AwsListener (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener)3 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)3 List (java.util.List)3 DescribeStackResourcesRequest (com.amazonaws.services.cloudformation.model.DescribeStackResourcesRequest)2 DescribeStackResourcesResult (com.amazonaws.services.cloudformation.model.DescribeStackResourcesResult)2