Localstack为Java集成测试创建SNS主题

问题描述 投票:0回答:1

我正在编写一个集成测试,其中我使用堆栈来启动模拟AWS服务的localstack docker容器。

此代码将启动docker容器

@RunWith(LocalstackTestRunner.class)
@LocalstackDockerProperties(services = {"dynamodb", "sns"})

然后,我从自己的一项测试中,根据自己的意愿致电发布商。但我得到一个找不到主题的话题

com.amazonaws.services.sns.model.NotFoundException: Topic does not exist (Service: AmazonSNS; Status Code: 404; Error Code: NotFound; Request ID: 06c6a626)

我似乎找不到在Java在线单元测试中创建SNS主题的好例子。我可以找到aws CLI的命令,该命令将创建如下所示的命令

$ aws --endpoint-url=http://localhost:4575 sns create-topic --name my_topic

但是我正在寻找可以在Spring Boot单元测试中使用的东西。

java spring amazon-web-services spring-integration localstack
1个回答
0
投票
AmazonSNS amazonSNS = DockerTestUtils.getClientSNS();
amazonSNS.createTopic("testTopic");

@Before或测试开始时。

© www.soinside.com 2019 - 2024. All rights reserved.