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");
}
}
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();
}
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);
}
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();
}
Aggregations