gpt4 book ai didi

spring-integration - Spring IntegrationFlow 的集成测试

转载 作者:行者123 更新时间:2023-12-04 15:54:31 31 4
gpt4 key购买 nike

我在为使用 Spring Integration DSL 的 IntegrationFlow 编写测试用例时遇到了麻烦。下面是我的代码片段,我想测试“转换”部分。请提供一些模拟 handle 部分的帮助,或者是否有其他方法可以测试这一点 -

public class DmwConfig {
@Value("${dmw.url.hostname}")
public String hostName;

@Bean
public MessageChannel dmwGetProductDetailsByEanChannel() {
return MessageChannels.direct().get();
}

@Bean
public IntegrationFlow dmwGetProductDetailsByEan() {
return IntegrationFlows
.from("input")
.channel("dmwGetProductDetailsByEanChannel")
.handle(httpMessageHandlerSpec())
.<JsonNode, ProductModel>transform(
node -> new ProductModel(
node.findValue("name").asText(null),
node.findValue("inventory").findValue("orderable").asBoolean(false),
node.findValue("stock_level").asInt(0),
node.findValue("price").asDouble(0),
"", // this url field will be enriched in the controller because the url doesn't contain any data from the response
node.findValue("image_groups").findValue("link").asText(null)
)
)
.get();
}

@Bean
public HttpRequestExecutingMessageHandler httpMessageHandlerSpec() {
return Http
.outboundGateway((Message<DmwPayload> p) -> "foobar url")
.charset("UTF-8")
.httpMethod(HttpMethod.GET)
.expectedResponseType(JsonNode.class).get();
}
}

最佳答案

我们没有 mocking framework然而,但这确实是在不久的将来的意图。

您可以考虑使用@MockBean来自最新 Spring Boot为您 HttpRequestExecutingMessageHandler httpMessageHandlerSpec用所需的模拟替换该 bean。

另一方面,您可以直接向 input channel 发送消息。为此,您的 .transform .请从短语中阅读该手册:

By default endpoints are wired via DirectChannel where the bean name is based on the pattern: [IntegrationFlow.beanName].channel#[channelNameIndex].



因此,流中所需的 channel 具有 bean 名称,例如: dmwGetProductDetailsByEan.channel#0 ,因为这是 IntegrationFlow 定义中的第一个未命名 channel 。

关于spring-integration - Spring IntegrationFlow 的集成测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39033644/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com