AwsIntegrationTestStackRule.java 文件源码

java
阅读 30 收藏 0 点赞 0 评论 0

项目:spring-cloud-stream-app-starters 作者:
@Override
protected void before() throws Throwable {
    try {
        String awsCredentialsDir = System.getProperty("aws.credentials.path");
        File awsCredentialsFile = new File(awsCredentialsDir, "aws.credentials.properties");
        Properties awsCredentials = new Properties();
        awsCredentials.load(new FileReader(awsCredentialsFile));
        String accessKey = awsCredentials.getProperty("cloud.aws.credentials.accessKey");
        String secretKey = awsCredentials.getProperty("cloud.aws.credentials.secretKey");
        this.cloudFormation = new AmazonCloudFormationClient(new BasicAWSCredentials(accessKey, secretKey));

        YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
        yamlPropertiesFactoryBean.setResources(new ClassPathResource("application.yml"));
        Properties applicationProperties = yamlPropertiesFactoryBean.getObject();

        this.stackName = applicationProperties.getProperty("cloud.aws.stack.name");

        after();

        ClassPathResource stackTemplate = new ClassPathResource("AwsIntegrationTestTemplate.json");
        String templateBody = FileCopyUtils.copyToString(new InputStreamReader(stackTemplate.getInputStream()));

        this.cloudFormation.createStack(
                new CreateStackRequest()
                        .withTemplateBody(templateBody)
                        .withOnFailure(OnFailure.DELETE)
                        .withStackName(this.stackName));

        waitForCompletion();

        System.setProperty("cloud.aws.credentials.accessKey", accessKey);
        System.setProperty("cloud.aws.credentials.secretKey", secretKey);
    }
    catch (Exception e) {
        if (!(e instanceof AssumptionViolatedException)) {
            Assume.assumeTrue("Can't perform AWS integration test because of: " + e.getMessage(), false);
        }
        else {
            throw e;
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号