Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Component
- public class TestRoute extends RouteBuilder {
- private MQServerConfig mqServerConfig;
- @Autowired
- public void setMQ(MQServerConfig config) {
- mqServerConfig = config;
- }
- @Override
- public void configure() throws Exception {
- from("sftp://{{ftp.user}}@{{ftp.host}}//{{req.ftp.directory}}?password={{ftp.password}}")
- .routeId("TestRoute")
- .convertBodyTo(String.class)
- .log("Request XML - ${body}")
- .to(mqServerConfig.getRequestQueueUri())
- .end();
- }
- }
- @ActiveProfiles("test")
- @RunWith(CamelSpringBootRunner.class)
- @UseAdviceWith
- @SpringBootTest(classes = TestRouteTest.class)
- @MockEndpoints
- @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
- @EnableAutoConfiguration
- public class TestRouteTest extends CamelTestSupport {
- private static final String MOCK_QUEUE_ENDPOINT = "mock:hazelcast:queue";
- @Autowired
- private ProducerTemplate producerTemplate;
- @EndpointInject(uri = MOCK_QUEUE_ENDPOINT)
- MockEndpoint mockQueue;
- @Override
- protected RoutesBuilder createRouteBuilder() throws Exception {
- return new TestRoute();
- }
- @Before
- public void mockEndpoints() throws Exception {
- AdviceWithRouteBuilder mockQueue = new AdviceWithRouteBuilder() {
- @Override
- public void configure() throws Exception {
- // mock the for testing
- replaceFromWith(MOCK_QUEUE_ENDPOINT);
- interceptSendToEndpoint("hazelcast:queue:*")
- .skipSendToOriginalEndpoint()
- .to(MOCK_QUEUE_ENDPOINT);
- }
- };
- context.getRouteDefinition("TestRoute")
- .adviceWith(context, mockQueue);
- }
- @Test
- public void test() throws Exception {
- mockQueue.expectedMessageCount(1);
- producerTemplate.sendBody("mock:hazelcast:queue:requestQueue", "Camel");
- mockQueue.assertIsSatisfied();
- }
- }
Add Comment
Please, Sign In to add comment