Search in sources :

Example 1 with MyProcessor

use of org.apache.camel.spring.example.MyProcessor in project camel by apache.

the class MainTest method testMain.

public void testMain() throws Exception {
    // lets make a simple route
    Main main = new Main();
    main.addRouteBuilder(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("file://src/test/data?noop=true").process(new MyProcessor()).to("mock:results");
        }
    });
    main.start();
    List<CamelContext> contextList = main.getCamelContexts();
    assertNotNull(contextList);
    assertEquals("size", 1, contextList.size());
    CamelContext camelContext = contextList.get(0);
    MockEndpoint endpoint = camelContext.getEndpoint("mock:results", MockEndpoint.class);
    // in case we add more files in src/test/data
    endpoint.expectedMinimumMessageCount(2);
    endpoint.assertIsSatisfied();
    List<Exchange> list = endpoint.getReceivedExchanges();
    LOG.debug("Received: " + list);
    main.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MyProcessor(org.apache.camel.spring.example.MyProcessor)

Example 2 with MyProcessor

use of org.apache.camel.spring.example.MyProcessor in project camel by apache.

the class CustomProcessorWithNamespacesTest method testXMLRouteLoading.

public void testXMLRouteLoading() throws Exception {
    applicationContext = createApplicationContext();
    SpringCamelContext context = applicationContext.getBeansOfType(SpringCamelContext.class).values().iterator().next();
    assertValidContext(context);
    // now lets send a message
    ProducerTemplate template = context.createProducerTemplate();
    template.start();
    template.send("direct:start", new Processor() {

        public void process(Exchange exchange) {
            Message in = exchange.getIn();
            in.setHeader("name", "James");
            in.setBody(body);
        }
    });
    template.stop();
    MyProcessor myProcessor = applicationContext.getBean("myProcessor", MyProcessor.class);
    List<Exchange> list = myProcessor.getExchanges();
    assertEquals("Should have received a single exchange: " + list, 1, list.size());
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Processor(org.apache.camel.Processor) MyProcessor(org.apache.camel.spring.example.MyProcessor) Message(org.apache.camel.Message) MyProcessor(org.apache.camel.spring.example.MyProcessor)

Example 3 with MyProcessor

use of org.apache.camel.spring.example.MyProcessor in project camel by apache.

the class MainExampleTest method testMain.

public void testMain() throws Exception {
    Main main = new Main();
    main.addRouteBuilder(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("file://src/test/data?noop=true").process(new MyProcessor()).to("file://target/mainTest");
        }
    });
    main.start();
    // then some time later
    Thread.sleep(1000);
    main.stop();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MyProcessor(org.apache.camel.spring.example.MyProcessor)

Aggregations

MyProcessor (org.apache.camel.spring.example.MyProcessor)3 Exchange (org.apache.camel.Exchange)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 CamelContext (org.apache.camel.CamelContext)1 Message (org.apache.camel.Message)1 Processor (org.apache.camel.Processor)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1