0

I'm using spring-integration bundled with spring-batch and got stuck trying to write integration tests to test the whole flow, not just single config.

I've created Embedded Sftp Server for this tests and trying to send message to sftpInboundChannel - the message is sent, but nothing happens, but when i send this message to the next channel (after sftpInboundChannel) it goes ok. Also i'm not able to load test source properties, even though i'm using @TestPropertySource annotation.

This are my class annotations


@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)

This is my class body

    @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();
        }
    }

1 Answers1

0

To the case of not read the property file one solution is add in your Test class something like this:

@BeforeClass
    public static void beforeClass() {
        System.setProperty("propertyfile",  "nameOfFile.properties");
     }

A second way is to create a xml (or class) config where you add the tag:

<context:property-placeholder
    location="nameOfFile.properties"
    ignore-resource-not-found="true" system-properties-mode="OVERRIDE" />

and your file will be localized.

The property file should be inside of resources folder.