Spring integration 弹簧积分流量试验
我正在尝试测试Spring integration 弹簧积分流量试验,spring-integration,spring-integration-dsl,Spring Integration,Spring Integration Dsl,我正在尝试测试 @Bean public IntegrationFlow integrationFlow(JobLaunchingGateway jobLaunchingGateway) { return IntegrationFlows.from(inventoryImportInboundChannelAdapter, p -> p.poller(Pollers.fixedRate(inventoryImportJobProperties.getPol
@Bean
public IntegrationFlow integrationFlow(JobLaunchingGateway jobLaunchingGateway) {
return IntegrationFlows.from(inventoryImportInboundChannelAdapter,
p -> p.poller(Pollers.fixedRate(inventoryImportJobProperties.getPollingFrequency()))).
handle(fileMessageToPath()).
handle(fileMessageToJobRequest()).
handle(jobLaunchingGateway).
log(LoggingHandler.Level.INFO, "headers.id + ': ' + payload").
get();
}
库存导入通道适配器是s3适配器,我不想连接到s3进行组件测试。我尝试使用MockIntegrationContext,但没有成功。请告知
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {ImportInventoryJobIntegrationFlow.class})
@SpringIntegrationTest
public class ImportInventoryJobIntegrationFlowTest {
@MockBean
private MessageSource<?> inventoryImportInboundChannelAdapter;
@MockBean
private Job inventoryImportJob;
@MockBean
private JobRepository jobrepository;
@MockBean
private InventoryImportJobProperties inventoryImportJobProperties;
@Autowired
private MockIntegrationContext mockIntegrationContext;
@Test
public void testChannelAdapter(){
File importFile = Mockito.mock(File.class);
BDDMockito.given(importFile.getParent()).willReturn("test.import");
System.out.println(mockIntegrationContext);
this.mockIntegrationContext.substituteMessageSourceFor("inventoryImportInboundChannelAdapter",
MockIntegration.mockMessageSource(importFile));
}
}
@RunWith(SpringRunner.class)
@SpringBootTest(类={ImportInventoryJobIntegrationFlow.class})
@SpringIntegrationTest
公共类ImportInventoryJobIntegrationFlowTest{
@蚕豆
private MessageSource inventoryImportInboundChannelAdapter;
@蚕豆
私人作业目录导入作业;
@蚕豆
私有作业库作业库;
@蚕豆
私有库存ImportJobProperties库存ImportJobProperties;
@自动连线
私有MockIntegrationContext MockIntegrationContext;
@试验
public void testChannelAdapter(){
File importFile=Mockito.mock(File.class);
给定(importFile.getParent())。将返回(“test.import”);
System.out.println(mockIntegrationContext);
this.mockIntegrationContext.substituteMessageSourceFor(“inventoryImportInboundChannelAdapter”,
MockIntegration.mockMessageSource(importFile));
}
}
获取的错误是:
org.springframework.beans.factory.NoSuchBean定义异常:没有名为“inventoryImportInboundChannelAdapter”的bean可用请参阅
mockIntegrationContext.substituteMessageSourceFor()
JavaDocs:
/**
* Replace the real {@link MessageSource} in the {@link SourcePollingChannelAdapter} bean
* with provided {@link MessageSource} instance.
* Can be a mock object.
* @param pollingAdapterId the endpoint bean name
* @param mockMessageSource the {@link MessageSource} to replace in the endpoint bean
* @see org.springframework.integration.test.mock.MockIntegration#mockMessageSource
*/
public void substituteMessageSourceFor(String pollingAdapterId, MessageSource<?> mockMessageSource) {
不幸的是,您没有在此处指定inventoryImportInboundChannelAdapter
,因此生成了它的目标名称
考虑在该端点的轮询器()定义之前或之后添加.id(“inventoryImportInboundChannelAdapter”)
更新
我们有这样的测试配置:
@Bean
public IntegrationFlow myFlow() {
return IntegrationFlows
.from(() -> new GenericMessage<>("myData"),
e -> e.id("mySourceEndpoint"))
.<String, String>transform(String::toUpperCase)
.channel(results())
.get();
}
this.mockIntegrationContext.substituteMessageSourceFor("mySourceEndpoint",
MockIntegration.mockMessageSource("foo", "bar", "baz"));
添加了,p->p.poller(Pollers.fixedRate(inventoryImportJobProperties.getPollingFrequency()).id(“inventoryImportPoller”))。仍然显示org.springframework.beans.factory.NoSuchBean定义异常:没有名为“inventoryImportPoller”的bean可用在我的答案中查看更新。也许问题出在别的地方。请为该NoSuchBeanDefinitionException
显示更多堆栈跟踪。没关系,我使用了一个没有名字的mockbean导致了该问题。感谢您的时间和支持是的,请。另一个注意事项是,@EnableIntegration在主配置类中,而不是在我为这个特定测试加载的配置中,是吗?我在您的测试中看到了@SpringBootTest
,因此我认为您在这方面的配置很好。很高兴知道问题已经解决了!只有你才能接受答案,因为你是请求者。
this.mockIntegrationContext.substituteMessageSourceFor("mySourceEndpoint",
MockIntegration.mockMessageSource("foo", "bar", "baz"));