我使用了与spring-batch捆绑在一起的spring-integration,但在尝试编写集成测试来测试整个流程时遇到了问题,而不仅仅是单个配置。
我已经为这项测试创建了嵌入式Sftp Server,并尝试将消息发送到sftpInboundChannel -消息已发送,但没有任何反应,但当我将此消息发送到下一个通道(在sftpInboundChannel之后)时,消息正常。此外,即使我使用@TestPropertySource注解,我也无法加载测试源属性。
这是我的类注释
@TestPropertySource(properties = {
//here goes all the properties
})
@EnableConfigurationProperties
@RunWith(SpringRunner.class)
@Import({TestConfig.class, SessionConfig.class})
@ActiveProfiles("it")
@SpringIntegrationTest
@EnableIntegration
@SpringBootTest
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)这是我的类体
@Autowired
private PollableChannel sftpInboundChannel;
@Autowired
private SessionFactory<ChannelSftp.LsEntry> defaultSftpSessionFactory;
@Autowired
private EmbeddedSftpServer server;
@Test
public void shouldDoSmth() {
RemoteFileTemplate<ChannelSftp.LsEntry> template;
try {
template = new RemoteFileTemplate<>(defaultSftpSessionFactory);
SftpTestUtils.moveToRemoteFolder(template);
final List<ChannelSftp.LsEntry> movedFiles = SftpTestUtils.listFilesFromDirectory("folder/subfolder", template);
log.info("Moved file {}", movedFiles.size());
final MessageBuilder<String> messageBuilder = MessageBuilder.withPayload("Sample.txt") // path to file
.setHeader("file_Path", "Sample.txt")
boolean wasSent = this.sftpInboundChannel.send(messageBuilder.build());
log.info("Was sent to sftpInboundChannel channel {}", wasSent);
log.info("message {}", messageBuilder.build());
} finally {
SftpTestUtils.cleanUp();
}
}发布于 2019-07-04 00:12:21
对于不读取属性文件的情况,一种解决方案是在Test类中添加如下内容:
@BeforeClass
public static void beforeClass() {
System.setProperty("propertyfile", "nameOfFile.properties");
}第二种方法是创建xml (或类)配置,在其中添加标记:
<context:property-placeholder
location="nameOfFile.properties"
ignore-resource-not-found="true" system-properties-mode="OVERRIDE" />你的文件将被本地化。
属性文件应该在资源文件夹内。
https://stackoverflow.com/questions/56759840
复制相似问题