Search in sources :

Example 11 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project camel by apache.

the class RouteContextProcessorTest method xxxTestForkAndJoin.

public void xxxTestForkAndJoin() throws InterruptedException {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(NUMBER_OF_MESSAGES);
    ProducerTemplate template = context.createProducerTemplate();
    for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
        template.sendBodyAndHeader("seda:fork", "Test Message: " + i, "seqnum", new Long(i));
    }
    long expectedTime = NUMBER_OF_MESSAGES * (RandomSleepProcessor.MAX_PROCESS_TIME + RandomSleepProcessor.MIN_PROCESS_TIME) / 2 / CONCURRENCY + TIMEOUT;
    Thread.sleep(expectedTime);
    assertMockEndpointsSatisfied();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 12 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project camel by apache.

the class SftpPollEnrichConsumeWithDisconnectAndDeleteTest method testSftpSimpleConsume.

@Test
public void testSftpSimpleConsume() throws Exception {
    if (!canTest()) {
        return;
    }
    String expected = "Hello World";
    // create file using regular file
    template.sendBodyAndHeader("file://" + FTP_ROOT_DIR, expected, Exchange.FILE_NAME, "hello.txt");
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.expectedHeaderReceived(Exchange.FILE_NAME, "hello.txt");
    mock.expectedBodiesReceived(expected);
    ProducerTemplate triggerTemplate = context.createProducerTemplate();
    triggerTemplate.sendBody("vm:trigger", "");
    assertMockEndpointsSatisfied();
    long startFileDeletionCheckTime = System.currentTimeMillis();
    boolean fileExists = true;
    while (System.currentTimeMillis() - startFileDeletionCheckTime < 3000) {
        // wait up to 3000ms for file to be deleted
        File file = new File(FTP_ROOT_DIR + "/hello.txt");
        fileExists = file.exists();
        if (fileExists) {
            log.info("Will check that file has been deleted again in 200ms");
            Thread.sleep(200);
        }
    }
    assertFalse("The file should have been deleted", fileExists);
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File) Test(org.junit.Test)

Example 13 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project camel by apache.

the class VmMultipleConsumersKeepRouteTest method testVmMultipleConsumersKeepRoute.

public void testVmMultipleConsumersKeepRoute() throws Exception {
    CamelContext camelContext = new DefaultCamelContext();
    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    RouteBuilder builder = new RouteBuilder(camelContext) {

        @Override
        public void configure() throws Exception {
            from("vm:producer?multipleConsumers=true").routeId("route1").to("mock:route1");
        }
    };
    RouteBuilder builder2 = new RouteBuilder(camelContext) {

        @Override
        public void configure() throws Exception {
            from("vm:producer?multipleConsumers=true").routeId("route2").to("mock:route2");
        }
    };
    camelContext.addRoutes(builder);
    camelContext.addRoutes(builder2);
    camelContext.start();
    MockEndpoint mock1 = (MockEndpoint) camelContext.getEndpoint("mock:route1");
    MockEndpoint mock2 = (MockEndpoint) camelContext.getEndpoint("mock:route2");
    mock1.expectedMessageCount(100);
    mock2.expectedMessageCount(100);
    for (int i = 0; i < 100; i++) {
        producerTemplate.sendBody("vm:producer?multipleConsumers=true", i);
    }
    MockEndpoint.assertIsSatisfied(mock1, mock2);
    camelContext.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 14 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project camel by apache.

the class ProducerTemplateDisableEventNotifierTest method testExchangeSent.

public void testExchangeSent() throws Exception {
    getMockEndpoint("mock:result").expectedMessageCount(1);
    // we dont want events for producer template itself so disable that
    ProducerTemplate other = context.createProducerTemplate();
    other.setEventNotifierEnabled(false);
    other.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    assertEquals(2, notifier.getEvents().size());
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate)

Example 15 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project camel by apache.

the class DefaultProducerTemplateTest method testSendUsingDefaultEndpoint.

public void testSendUsingDefaultEndpoint() throws Exception {
    ProducerTemplate producer = new DefaultProducerTemplate(context, context.getEndpoint("direct:in"));
    producer.start();
    getMockEndpoint("mock:result").expectedMessageCount(3);
    producer.sendBody("Hello");
    producer.sendBodyAndHeader("Hello", "foo", 123);
    Map<String, Object> headers = new HashMap<String, Object>();
    producer.sendBodyAndHeaders("Hello", headers);
    assertMockEndpointsSatisfied();
    producer.stop();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) HashMap(java.util.HashMap)

Aggregations

ProducerTemplate (org.apache.camel.ProducerTemplate)130 Test (org.junit.Test)58 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)53 CamelContext (org.apache.camel.CamelContext)48 Exchange (org.apache.camel.Exchange)36 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)27 Deployment (org.activiti.engine.test.Deployment)16 RouteBuilder (org.apache.camel.builder.RouteBuilder)16 Processor (org.apache.camel.Processor)8 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 HashMap (java.util.HashMap)7 Task (org.activiti.engine.task.Task)7 Endpoint (org.apache.camel.Endpoint)7 File (java.io.File)6 ArrayList (java.util.ArrayList)5 Message (org.apache.camel.Message)4 List (java.util.List)3 ExecutorService (java.util.concurrent.ExecutorService)3 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)3 ConsumerTemplate (org.apache.camel.ConsumerTemplate)3