Guest User

Untitled

a guest
Feb 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. @Component
  2. public class TestRoute extends RouteBuilder {
  3.  
  4. private MQServerConfig mqServerConfig;
  5.  
  6. @Autowired
  7. public void setMQ(MQServerConfig config) {
  8. mqServerConfig = config;
  9. }
  10.  
  11. @Override
  12. public void configure() throws Exception {
  13. from("sftp://{{ftp.user}}@{{ftp.host}}//{{req.ftp.directory}}?password={{ftp.password}}")
  14. .routeId("TestRoute")
  15. .convertBodyTo(String.class)
  16. .log("Request XML - ${body}")
  17. .to(mqServerConfig.getRequestQueueUri())
  18. .end();
  19. }
  20. }
  21.  
  22. @ActiveProfiles("test")
  23. @RunWith(CamelSpringBootRunner.class)
  24. @UseAdviceWith
  25. @SpringBootTest(classes = TestRouteTest.class)
  26. @MockEndpoints
  27. @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
  28. @EnableAutoConfiguration
  29. public class TestRouteTest extends CamelTestSupport {
  30.  
  31. private static final String MOCK_QUEUE_ENDPOINT = "mock:hazelcast:queue";
  32.  
  33. @Autowired
  34. private ProducerTemplate producerTemplate;
  35.  
  36. @EndpointInject(uri = MOCK_QUEUE_ENDPOINT)
  37. MockEndpoint mockQueue;
  38.  
  39. @Override
  40. protected RoutesBuilder createRouteBuilder() throws Exception {
  41. return new TestRoute();
  42. }
  43.  
  44. @Before
  45. public void mockEndpoints() throws Exception {
  46. AdviceWithRouteBuilder mockQueue = new AdviceWithRouteBuilder() {
  47. @Override
  48. public void configure() throws Exception {
  49. // mock the for testing
  50. replaceFromWith(MOCK_QUEUE_ENDPOINT);
  51. interceptSendToEndpoint("hazelcast:queue:*")
  52. .skipSendToOriginalEndpoint()
  53. .to(MOCK_QUEUE_ENDPOINT);
  54. }
  55. };
  56. context.getRouteDefinition("TestRoute")
  57. .adviceWith(context, mockQueue);
  58. }
  59.  
  60. @Test
  61. public void test() throws Exception {
  62. mockQueue.expectedMessageCount(1);
  63. producerTemplate.sendBody("mock:hazelcast:queue:requestQueue", "Camel");
  64. mockQueue.assertIsSatisfied();
  65. }
  66. }
Add Comment
Please, Sign In to add comment