Search in sources :

Example 31 with ProducerTemplate

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

the class RoutingUsingCamelContextFactoryTest method testXMLRouteLoading.

public void testXMLRouteLoading() throws Exception {
    applicationContext = createApplicationContext();
    SpringCamelContext context = applicationContext.getBean("camel-A", SpringCamelContext.class);
    assertValidContext(context);
    MockEndpoint resultEndpoint = (MockEndpoint) resolveMandatoryEndpoint(context, "mock:result");
    resultEndpoint.expectedBodiesReceived(body);
    // now lets send a message
    ProducerTemplate template = context.createProducerTemplate();
    template.start();
    template.send("seda:start", new Processor() {

        public void process(Exchange exchange) {
            Message in = exchange.getIn();
            in.setHeader("name", "James");
            in.setBody(body);
        }
    });
    template.stop();
    resultEndpoint.assertIsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Processor(org.apache.camel.Processor) Message(org.apache.camel.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 32 with ProducerTemplate

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

the class PojoDualCamelContextConsumerTest method testCamel1.

public void testCamel1() throws Exception {
    String body = "<hello>world!</hello>";
    MockEndpoint result = camel1.getEndpoint("mock:result", MockEndpoint.class);
    result.expectedBodiesReceived(body);
    ProducerTemplate template = camel1.createProducerTemplate();
    template.start();
    template.sendBody("direct:start", body);
    template.stop();
    result.assertIsSatisfied();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 33 with ProducerTemplate

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

the class DependencyInjectCamelTemplateTest method testBeanHasCamelTemplateInjected.

@Test
public void testBeanHasCamelTemplateInjected() throws Exception {
    assertNotNull("Bean should be injected", bean);
    ProducerTemplate template = bean.getTemplate();
    assertNotNull("Bean should have a CamelTemplate", template);
    endpoint.expectedBodiesReceived(body);
    template.sendBody(body);
    endpoint.assertIsSatisfied();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) Test(org.junit.Test)

Example 34 with ProducerTemplate

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

the class DualCamelContextEndpointOutsideTest method testDualCamelContextEndpoint.

public void testDualCamelContextEndpoint() throws Exception {
    CamelContext camelA = applicationContext.getBean("camel-A", CamelContext.class);
    assertNotNull(camelA);
    CamelContext camelB = applicationContext.getBean("camel-B", CamelContext.class);
    assertNotNull(camelB);
    MockEndpoint mockA = camelA.getEndpoint("mock:mock1", MockEndpoint.class);
    mockA.expectedBodiesReceived("Hello A");
    MockEndpoint mockB = camelB.getEndpoint("mock:mock2", MockEndpoint.class);
    mockB.expectedBodiesReceived("Hello B");
    ProducerTemplate producer1 = camelA.createProducerTemplate();
    producer1.sendBody("direct:start1", "Hello A");
    ProducerTemplate producer2 = camelB.createProducerTemplate();
    producer2.sendBody("direct:start2", "Hello B");
    // make sure we properly stop the services we created
    ServiceHelper.stopServices(producer1, producer2);
    mockA.assertIsSatisfied();
    mockB.assertIsSatisfied();
}
Also used : CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 35 with ProducerTemplate

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

the class UserProducerInOnlyTest method testPostStatusUpdateRequestResponse.

@Test
public void testPostStatusUpdateRequestResponse() throws Exception {
    Date now = new Date();
    String tweet = "UserProducerInOnlyTest: This is a tweet posted on " + now.toString();
    LOG.info("Tweet: " + tweet);
    ProducerTemplate producerTemplate = context.createProducerTemplate();
    // send tweet to the twitter endpoint
    producerTemplate.sendBodyAndHeader("direct:tweets", tweet, "customHeader", 12312);
    resultEndpoint.expectedMessageCount(1);
    resultEndpoint.expectedBodyReceived().body(String.class);
    // Message headers should be preserved
    resultEndpoint.expectedHeaderReceived("customHeader", 12312);
    resultEndpoint.assertIsSatisfied();
    List<Exchange> tweets = resultEndpoint.getExchanges();
    assertNotNull(tweets);
    assertThat(tweets.size(), is(1));
    String receivedTweet = tweets.get(0).getIn().getBody(String.class);
    assertThat(receivedTweet, is(tweet));
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Date(java.util.Date) Test(org.junit.Test)

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