测试骆驼应用程序时如何模拟Amazon SQS终端节点

我正在编写一个使用Camel侦听SQS队列的Spring Boot应用程序。路线定义:


from("aws-sqs://my-s3-notification-queue" +

    "?amazonSQSClient=#sqsClient" +

    "&deleteAfterRead=false")

    .unmarshal().json(JsonLibrary.Jackson, S3EventNotification.class)

    .bean(s3NotificationHandler);

sqsClient@Bean在@Configuration文件中定义为。


在运行测试时,我想模拟SQS终结点,以便实际上不连接到AWS。我该怎么做呢?我试过像这样写测试


@RunWith(CamelSpringBootRunner.class)

@SpringBootTest

@MockEndpoints

public class ApplicationTests {


    @Test

    public void contextLoads() {

    }


}

如果我正确阅读了文档,这应该可以工作,但是它仍然尝试连接到AWS。我想念什么?


ABOUTYOU
浏览 180回答 3
3回答

慕工程0101907

您可以使用Localstack ,可以在不连接AWS的情况下从本地系统模拟多个AWS服务。

蛊毒传说

由于我不知道阿帕奇骆驼,因此不确定我的回答对您有多大帮助。我在嘲笑HttpServletRequest对象,并假设可以在此处使用相同的概念。所以,在您的测试中@RunWith(CamelSpringBootRunner.class)@SpringBootTest@MockEndpointspublic class ApplicationTests {    @Mock    public MyRoute myRoute;    @Before    public void init() {         when(myRoute.configure()).thenReturn("what you are returning");    }    @Test    public void contextLoads() {    }}而且您的myRoute类看起来类似于,class MyRoute{  public void configure(){    from("aws-sqs://my-s3-notification-queue" +    "?amazonSQSClient=#sqsClient" +    "&deleteAfterRead=false")    .unmarshal().json(JsonLibrary.Jackson, S3EventNotification.class)    .bean(s3NotificationHandler);  }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java