如何在 spring 集成测试中调用通道
How to invoke a channel in spring integration tests
我有一个接受字符串输入的 Flow
@Bean
public IntegrationFlow myFlow() {
// @formatter:off
return IntegrationFlows.from("some.input.channel")
.handle(someService)
.get();
如何从我的集成测试中调用它,如何在 "some.input.channel"
上放置一个字符串消息
阅读您使用的 API 的 Java 文档:
/**
* Populate the {@link MessageChannel} name to the new {@link IntegrationFlowBuilder} chain.
* The {@link org.springframework.integration.dsl.IntegrationFlow} {@code inputChannel}.
* @param messageChannelName the name of existing {@link MessageChannel} bean.
* The new {@link DirectChannel} bean will be created on context startup
* if there is no bean with this name.
* @return new {@link IntegrationFlowBuilder}.
*/
public static IntegrationFlowBuilder from(String messageChannelName) {
然后打开您使用的框架的参考手册:
因此,由 Java DSL 创建的通道成为应用程序上下文中的一个 bean。
自动连接 到测试 class 并从测试方法中调用它的 send()
就足够了:
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = MyFlowConfiguration.class)
public class IntegrationFlowTests {
@Autowired
@Qualifier("some.input.channel")
private MessageChannel someInputChannel;
@Test
public void myTest() {
this.someInputChannel.send(new GenericMessage<>("foo"));
}
}
我有一个接受字符串输入的 Flow
@Bean
public IntegrationFlow myFlow() {
// @formatter:off
return IntegrationFlows.from("some.input.channel")
.handle(someService)
.get();
如何从我的集成测试中调用它,如何在 "some.input.channel"
上放置一个字符串消息阅读您使用的 API 的 Java 文档:
/**
* Populate the {@link MessageChannel} name to the new {@link IntegrationFlowBuilder} chain.
* The {@link org.springframework.integration.dsl.IntegrationFlow} {@code inputChannel}.
* @param messageChannelName the name of existing {@link MessageChannel} bean.
* The new {@link DirectChannel} bean will be created on context startup
* if there is no bean with this name.
* @return new {@link IntegrationFlowBuilder}.
*/
public static IntegrationFlowBuilder from(String messageChannelName) {
然后打开您使用的框架的参考手册:
因此,由 Java DSL 创建的通道成为应用程序上下文中的一个 bean。
自动连接 到测试 class 并从测试方法中调用它的 send()
就足够了:
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = MyFlowConfiguration.class)
public class IntegrationFlowTests {
@Autowired
@Qualifier("some.input.channel")
private MessageChannel someInputChannel;
@Test
public void myTest() {
this.someInputChannel.send(new GenericMessage<>("foo"));
}
}