Search in sources :

Example 66 with ProducerTemplate

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

the class ProducerTemplateAlreadyExistTest method testHasExistingTemplate.

@Test
public void testHasExistingTemplate() {
    assertNotNull("Should have injected a producer template", template);
    ProducerTemplate lookup = context.getRegistry().lookupByNameAndType("myTemplate", ProducerTemplate.class);
    assertNotNull("Should lookup producer template", lookup);
    ProducerTemplate lookup2 = context.getRegistry().lookupByNameAndType("template", ProducerTemplate.class);
    assertNull("Should not be able to lookup producer template", lookup2);
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) Test(org.junit.Test)

Example 67 with ProducerTemplate

use of org.apache.camel.ProducerTemplate 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 68 with ProducerTemplate

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

the class UserProducerInOutTest method testPostStatusUpdateRequestResponse.

@Test
public void testPostStatusUpdateRequestResponse() throws Exception {
    Date now = new Date();
    String tweet = "UserProducerInOutTest: 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(Status.class);
    // Message headers should be preserved
    resultEndpoint.expectedHeaderReceived("customHeader", 12312);
    resultEndpoint.assertIsSatisfied();
    List<Exchange> tweets = resultEndpoint.getExchanges();
    assertNotNull(tweets);
    assertThat(tweets.size(), is(1));
    Status receivedTweet = tweets.get(0).getIn().getBody(Status.class);
    assertNotNull(receivedTweet);
    // The identifier for the published tweet should be there
    assertNotNull(receivedTweet.getId());
}
Also used : Exchange(org.apache.camel.Exchange) Status(twitter4j.Status) ProducerTemplate(org.apache.camel.ProducerTemplate) Date(java.util.Date) Test(org.junit.Test)

Example 69 with ProducerTemplate

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

the class CafeRouteBuilder method runCafeRouteDemo.

public void runCafeRouteDemo() throws Exception {
    // create CamelContext
    DefaultCamelContext camelContext = new DefaultCamelContext();
    camelContext.setRegistry(createRegistry());
    camelContext.addRoutes(this);
    camelContext.start();
    ProducerTemplate template = camelContext.createProducerTemplate();
    Order order = new Order(2);
    order.addItem(DrinkType.ESPRESSO, 2, true);
    order.addItem(DrinkType.CAPPUCCINO, 4, false);
    order.addItem(DrinkType.LATTE, 4, false);
    order.addItem(DrinkType.MOCHA, 2, false);
    template.sendBody("direct:cafe", order);
    Thread.sleep(6000);
    camelContext.stop();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 70 with ProducerTemplate

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

the class MainNoPidTest method testMyMain.

@Test
public void testMyMain() throws Exception {
    Main main = new Main();
    main.setBundleName("MyMainBundle");
    // as we run this test without packing ourselves as bundle, then include ourselves
    main.setIncludeSelfAsBundle(true);
    // setup the blueprint file here
    main.setDescriptors("org/apache/camel/test/blueprint/main-no-pid-loadfile.xml");
    main.start();
    ProducerTemplate template = main.getCamelTemplate();
    assertNotNull("We should get the template here", template);
    String result = template.requestBody("direct:start", "hello", String.class);
    assertEquals("Get a wrong response", "Good morning hello", result);
    main.stop();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) 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