Java 类com.amazonaws.services.cloudformation.model.StackResource 实例源码

项目:aem-orchestrator    文件:AwsHelperServiceTest.java   
@Test
public void testGetStackPhysicalResourceId() {
    final StackResource stackResource1 = new StackResource();
    stackResource1.setLogicalResourceId("logical1");
    stackResource1.setPhysicalResourceId("physical1");

    final StackResource stackResource2 = new StackResource();
    stackResource2.setLogicalResourceId("logical2");
    stackResource2.setPhysicalResourceId("physical2");

    final List<StackResource> stackResources = new ArrayList<>();
    stackResources.add(stackResource1);
    stackResources.add(stackResource2);

    final DescribeStackResourcesResult result = mock(DescribeStackResourcesResult.class);
    when(result.getStackResources()).thenReturn(stackResources);

    when(amazonCloudFormationClient.describeStackResources(any(DescribeStackResourcesRequest.class))).thenReturn(result);

    assertThat(awsHelperService.getStackPhysicalResourceId("testStackName", "logical2"), equalTo("physical2"));

    final ArgumentCaptor<DescribeStackResourcesRequest> argumentCaptor = ArgumentCaptor.forClass(DescribeStackResourcesRequest.class);
    verify(amazonCloudFormationClient).describeStackResources(argumentCaptor.capture());
    assertThat(argumentCaptor.getValue().getStackName(), equalTo("testStackName"));
}
项目:spring-cloud-aws    文件:StackConfigurationBeanDefinitionParserTest.java   
@Test
public void stackResourceRegistry_stackConfigurationWithoutStaticName_stackResourceRegistryBeanExposedUnderGeneratedName() throws Exception {
    // 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("org.springframework.cloud.aws.core.env.stack.config.StackResourceRegistryFactoryBean#0", StackResourceRegistry.class);

    // Assert
    assertThat(autoDetectingStackNameProviderBasedStackResourceRegistry, is(not(nullValue())));

    server.removeContext(httpContext);
}
项目:spring-cloud-aws    文件:StackConfigurationBeanDefinitionParserTest.java   
@Test
public void resourceIdResolverResolveToPhysicalResourceId_stackConfigurationWithoutStaticNameAndLogicalResourceIdOfExistingResourceProvided_returnsPhysicalResourceId() throws Exception {
    // 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().withLogicalResourceId("EmptyBucket").withPhysicalResourceId("integrationteststack-emptybucket-foo")));


    applicationContext.load(new ClassPathResource(getClass().getSimpleName() + "-autoDetectStackName.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-"));

    server.removeContext(httpContext);
}
项目:spring-cloud-aws    文件:TestStackEnvironment.java   
protected String getByLogicalId(String id) {
    for (StackResource stackResource : this.stackResources.getStackResources()) {
        if (stackResource.getLogicalResourceId().equals(id)) {
            return stackResource.getPhysicalResourceId();
        }
    }
    return null;
}
项目:cfnassist    文件:StackCache.java   
public List<StackResource> getResourcesForStack(String stackName) {

        List<StackResource> resources;
        if (stackResources.containsStack(stackName)) {
            logger.info("Cache hit on stack resources for stack " + stackName);
            resources = stackResources.getStackResources(stackName);
        } else {
            logger.info("Cache miss, loading resources for stack " + stackName);
            resources = formationClient.describeStackResources(stackName);

            stackResources.addStackResources(stackName, resources);
        }
        return resources;
    }
项目:cfnassist    文件:StackResources.java   
public List<StackResource> getStackResources(String stackName) {
    List<StackResource> resource = theResources.get(stackName);
    return resource;
}
项目:cfnassist    文件:StackResources.java   
public void addStackResources(String stackName,
        List<StackResource> resources) {
    logger.info("Adding resources for stack: " + stackName);
    theResources.put(stackName, resources);     
}