I have a camel route which polls the files from a ftp server and send files to s3. I have some processors in the route which calculates/manipulates the headers based on file name. I need to test this route, How can i inject my processor and use the file language inside my processor?
@RunWith(MockitoJUnitRunner.class)
public class CamelS3HeadersProcessorTest extends CamelTestSupport {
private String filePath = "src/test/resources/sample.txt";
// @Autowired
// private CamelS3HeadersProcessor camelS3HeadersProcessor;
@Test
public void shouldSetS3HeadersProperly() throws Exception {
File file = new File(filePath);
template.sendBody("direct:start", file);
getMockEndpoint("mock:result").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedHeaderReceived(S3Constants.KEY, file.getName());
assertMockEndpointsSatisfied();
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").process(new CamelS3HeadersProcessor()).to("mock:result");
}
};
}
}
Processor:
@Component
public class CamelS3HeadersProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
SimpleBuilder simpleBuilder = new SimpleBuilder("${file:name}");
String fileName = simpleBuilder.evaluate(exchange, String.class);
//do some logic and set headers
}
}
I don't want to mock my processor. I want to mock my endpoints and test my processor.
Problems:
Cannot Autowire/Inject my processor.
File name was evaluated as null. How to use FileConsumer/FTPConsumer instead of ProducerTemplate?