Search in sources :

Example 1 with ListableStackResourceFactory

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

the class StackResourceRegistryFactoryBeanTest method createInstance_stackWithTwoResources_listsBothResources.

@Test
void createInstance_stackWithTwoResources_listsBothResources() throws Exception {
    // Arrange
    Map<String, String> resourceIdMappings = new HashMap<>();
    resourceIdMappings.put("logicalResourceIdOne", "physicalResourceIdOne");
    resourceIdMappings.put("logicalResourceIdTwo", "physicalResourceIdTwo");
    StackResourceRegistryFactoryBean stackResourceRegistryFactoryBean = makeStackResourceRegistryFactoryBean(STACK_NAME, resourceIdMappings);
    // Act
    ListableStackResourceFactory stackResourceRegistry = stackResourceRegistryFactoryBean.createInstance();
    // Assert
    assertThat(stackResourceRegistry.getAllResources().size()).isEqualTo(2);
    for (StackResource stackResource : stackResourceRegistry.getAllResources()) {
        assertThat(stackResource.getLogicalId()).isIn("logicalResourceIdOne", "logicalResourceIdTwo");
        assertThat(stackResource.getPhysicalId()).isIn("physicalResourceIdOne", "physicalResourceIdTwo");
        assertThat(stackResource.getType()).isEqualTo("Amazon::SES::Test");
    }
}
Also used : HashMap(java.util.HashMap) ListableStackResourceFactory(io.awspring.cloud.core.env.stack.ListableStackResourceFactory) StackResource(io.awspring.cloud.core.env.stack.StackResource) Test(org.junit.jupiter.api.Test)

Example 2 with ListableStackResourceFactory

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

the class StackResourceRegistryFactoryBeanTest method createInstance_stackWithNestedStack.

@Test
void createInstance_stackWithNestedStack() throws Exception {
    // Arrange
    Map<String, String> resourceIdMappings = new HashMap<>();
    resourceIdMappings.put("logicalResourceIdOne", "physicalResourceIdOne");
    resourceIdMappings.put("logicalNestedStack", "physicalStackId");
    resourceIdMappings.put("logicalNestedStack.logicalResourceIdTwo", "physicalResourceIdTwo");
    StackResourceRegistryFactoryBean stackResourceRegistryFactoryBean = makeStackResourceRegistryFactoryBean(STACK_NAME, resourceIdMappings);
    // Act
    ListableStackResourceFactory stackResourceRegistry = stackResourceRegistryFactoryBean.createInstance();
    // Assert
    assertThat(stackResourceRegistry.getAllResources().size()).isEqualTo(3);
    for (StackResource stackResource : stackResourceRegistry.getAllResources()) {
        assertThat(stackResource.getLogicalId()).isIn("logicalResourceIdOne", "logicalNestedStack", "logicalNestedStack.logicalResourceIdTwo");
        assertThat(stackResource.getPhysicalId()).isIn("physicalResourceIdOne", "physicalStackId", "physicalResourceIdTwo");
        assertThat(stackResource.getType()).isIn("AWS::CloudFormation::Stack", "Amazon::SES::Test");
    }
    assertThat(stackResourceRegistry.lookupPhysicalResourceId("logicalNestedStack.logicalResourceIdTwo")).isNotNull();
    assertThat(stackResourceRegistry.lookupPhysicalResourceId("logicalResourceIdTwo")).isNotNull();
}
Also used : HashMap(java.util.HashMap) ListableStackResourceFactory(io.awspring.cloud.core.env.stack.ListableStackResourceFactory) StackResource(io.awspring.cloud.core.env.stack.StackResource) Test(org.junit.jupiter.api.Test)

Example 3 with ListableStackResourceFactory

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

the class StackResourceRegistryFactoryBeanTest method createInstance_stackWithNextTag_returnsStackResourceRegistryBuildWithTwoPages.

@Test
void createInstance_stackWithNextTag_returnsStackResourceRegistryBuildWithTwoPages() throws Exception {
    // Arrange
    AmazonCloudFormation cloudFormationClient = mock(AmazonCloudFormation.class);
    StackResourceRegistryFactoryBean stackResourceRegistryFactoryBean = new StackResourceRegistryFactoryBean(cloudFormationClient, new StaticStackNameProvider(STACK_NAME));
    when(cloudFormationClient.listStackResources(new ListStackResourcesRequest().withStackName(STACK_NAME))).thenReturn(new ListStackResourcesResult().withNextToken("2").withStackResourceSummaries(new StackResourceSummary().withLogicalResourceId("log1")));
    when(cloudFormationClient.listStackResources(new ListStackResourcesRequest().withStackName(STACK_NAME).withNextToken("2"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary().withLogicalResourceId("log2")));
    // Act
    ListableStackResourceFactory stackResourceFactory = stackResourceRegistryFactoryBean.createInstance();
    // Assert
    verify(cloudFormationClient, times(2)).listStackResources(isA(ListStackResourcesRequest.class));
    assertThat(stackResourceFactory.getAllResources().size()).isEqualTo(2);
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) ListableStackResourceFactory(io.awspring.cloud.core.env.stack.ListableStackResourceFactory) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) Test(org.junit.jupiter.api.Test)

Example 4 with ListableStackResourceFactory

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

the class StackResourceRegistryFactoryBeanTest method createInstance_stackWithNestedStack_dontReturnDuplicateResourceId.

@Test
void createInstance_stackWithNestedStack_dontReturnDuplicateResourceId() throws Exception {
    // Arrange
    Map<String, String> resourceIdMappings = new HashMap<>();
    resourceIdMappings.put("logicalNested1Stack", "physicalStackId");
    resourceIdMappings.put("logicalNested1Stack.logicalResource", "physicalResourceIdOne");
    resourceIdMappings.put("logicalNested2Stack", "physicalStackId");
    resourceIdMappings.put("logicalNested2Stack.logicalResource", "physicalResourceIdTwo");
    StackResourceRegistryFactoryBean stackResourceRegistryFactoryBean = makeStackResourceRegistryFactoryBean(STACK_NAME, resourceIdMappings);
    // Act
    ListableStackResourceFactory stackResourceRegistry = stackResourceRegistryFactoryBean.createInstance();
    // Assert
    assertThat(stackResourceRegistry.getAllResources().size()).isEqualTo(4);
    assertThat(stackResourceRegistry.lookupPhysicalResourceId("logicalNested1Stack.logicalResource")).isNotNull();
    assertThat(stackResourceRegistry.lookupPhysicalResourceId("logicalNested2Stack.logicalResource")).isNotNull();
    assertThat(stackResourceRegistry.lookupPhysicalResourceId("logicalResource")).isNull();
}
Also used : HashMap(java.util.HashMap) ListableStackResourceFactory(io.awspring.cloud.core.env.stack.ListableStackResourceFactory) Test(org.junit.jupiter.api.Test)

Aggregations

ListableStackResourceFactory (io.awspring.cloud.core.env.stack.ListableStackResourceFactory)4 Test (org.junit.jupiter.api.Test)4 HashMap (java.util.HashMap)3 StackResource (io.awspring.cloud.core.env.stack.StackResource)2 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)1 ListStackResourcesRequest (com.amazonaws.services.cloudformation.model.ListStackResourcesRequest)1 ListStackResourcesResult (com.amazonaws.services.cloudformation.model.ListStackResourcesResult)1 StackResourceSummary (com.amazonaws.services.cloudformation.model.StackResourceSummary)1