Search in sources :

Example 6 with DefaultProducerTemplate

use of org.apache.camel.impl.DefaultProducerTemplate in project camel by apache.

the class CamelContextAwareTest method testCamelTemplates.

public void testCamelTemplates() throws Exception {
    DefaultProducerTemplate producer1 = getMandatoryBean(DefaultProducerTemplate.class, "producer1");
    assertEquals("Inject a wrong camel context", producer1.getCamelContext().getName(), "camel1");
    DefaultProducerTemplate producer2 = getMandatoryBean(DefaultProducerTemplate.class, "producer2");
    assertEquals("Inject a wrong camel context", producer2.getCamelContext().getName(), "camel2");
    DefaultConsumerTemplate consumer = getMandatoryBean(DefaultConsumerTemplate.class, "consumer");
    assertEquals("Inject a wrong camel context", consumer.getCamelContext().getName(), "camel2");
}
Also used : DefaultConsumerTemplate(org.apache.camel.impl.DefaultConsumerTemplate) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate)

Example 7 with DefaultProducerTemplate

use of org.apache.camel.impl.DefaultProducerTemplate in project camel by apache.

the class RouteboxDirectProducerOnlyTest method testRouteboxDirectProducerOnlyRequests.

@Test
public void testRouteboxDirectProducerOnlyRequests() throws Exception {
    template = new DefaultProducerTemplate(context);
    template.start();
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from("direct:start").to(routeboxUri).to("log:Routes operation performed?showAll=true");
        }
    });
    context.start();
    LOG.debug("Beginning Test ---> testRouteboxDirectSyncRequests()");
    Book book = new Book("Sir Arthur Conan Doyle", "The Adventures of Sherlock Holmes");
    String response = sendAddToCatalogRequest(template, "direct:start", "addToCatalog", book);
    assertEquals("Book with Author " + book.getAuthor() + " and title " + book.getTitle() + " added to Catalog", response);
    //Thread.sleep(2000);
    book = sendFindBookRequest(template, "direct:start", "findBook", "Sir Arthur Conan Doyle");
    LOG.debug("Received book with author {} and title {}", book.getAuthor(), book.getTitle());
    assertEquals("The Adventures of Sherlock Holmes", book.getTitle());
    LOG.debug("Completed Test ---> testRouteboxDirectSyncRequests()");
    context.stop();
}
Also used : SimpleRouteBuilder(org.apache.camel.component.routebox.demo.SimpleRouteBuilder) RouteBuilder(org.apache.camel.builder.RouteBuilder) Book(org.apache.camel.component.routebox.demo.Book) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) Test(org.junit.Test)

Example 8 with DefaultProducerTemplate

use of org.apache.camel.impl.DefaultProducerTemplate in project camel by apache.

the class RouteboxDirectTest method testRouteboxDirectAsyncRequests.

@Test
public void testRouteboxDirectAsyncRequests() throws Exception {
    template = new DefaultProducerTemplate(context);
    template.start();
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from(routeboxUri).to("log:Routes operation performed?showAll=true");
        }
    });
    context.start();
    LOG.debug("Beginning Test ---> testRouteboxDirectAsyncRequests()");
    Book book = new Book("Sir Arthur Conan Doyle", "The Adventures of Sherlock Holmes");
    String response = sendAddToCatalogRequest(template, routeboxUri, "addToCatalog", book);
    assertEquals("Book with Author " + book.getAuthor() + " and title " + book.getTitle() + " added to Catalog", response);
    // Wait for 2 seconds before a follow-on request if the requests are sent in async mode
    // to allow the earlier request to take effect
    //Thread.sleep(2000);
    book = sendFindBookRequest(template, routeboxUri, "findBook", "Sir Arthur Conan Doyle");
    LOG.debug("Received book with author {} and title {}", book.getAuthor(), book.getTitle());
    assertEquals("The Adventures of Sherlock Holmes", book.getTitle());
    LOG.debug("Completed Test ---> testRouteboxDirectAsyncRequests()");
    context.stop();
}
Also used : SimpleRouteBuilder(org.apache.camel.component.routebox.demo.SimpleRouteBuilder) RouteBuilder(org.apache.camel.builder.RouteBuilder) Book(org.apache.camel.component.routebox.demo.Book) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) Test(org.junit.Test)

Example 9 with DefaultProducerTemplate

use of org.apache.camel.impl.DefaultProducerTemplate in project camel by apache.

the class RouteboxDispatchMapTest method testRouteboxUsingDispatchMap.

@Test
public void testRouteboxUsingDispatchMap() throws Exception {
    template = new DefaultProducerTemplate(context);
    template.start();
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from(routeboxUri).to("log:Routes operation performed?showAll=true");
        }
    });
    context.start();
    LOG.debug("Beginning Test ---> testRouteboxUsingDispatchMap()");
    Book book = new Book("Sir Arthur Conan Doyle", "The Adventures of Sherlock Holmes");
    String response = sendAddToCatalogRequest(template, routeboxUri, "addToCatalog", book);
    assertEquals("Book with Author " + book.getAuthor() + " and title " + book.getTitle() + " added to Catalog", response);
    book = sendFindBookRequest(template, routeboxUri, "findBook", "Sir Arthur Conan Doyle");
    LOG.debug("Received book with author {} and title {}", book.getAuthor(), book.getTitle());
    assertEquals("The Adventures of Sherlock Holmes", book.getTitle());
    LOG.debug("Completed Test ---> testRouteboxUsingDispatchMap()");
    context.stop();
}
Also used : SimpleRouteBuilder(org.apache.camel.component.routebox.demo.SimpleRouteBuilder) RouteBuilder(org.apache.camel.builder.RouteBuilder) Book(org.apache.camel.component.routebox.demo.Book) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) Test(org.junit.Test)

Example 10 with DefaultProducerTemplate

use of org.apache.camel.impl.DefaultProducerTemplate in project camel by apache.

the class RouteboxSedaTest method testRouteboxSedaAsyncRequests.

@Test
public void testRouteboxSedaAsyncRequests() throws Exception {
    template = new DefaultProducerTemplate(context);
    template.start();
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from(routeboxUri).to("log:Routes operation performed?showAll=true");
        }
    });
    context.start();
    LOG.debug("Beginning Test ---> testRouteboxSedaAsyncRequests()");
    Book book = new Book("Sir Arthur Conan Doyle", "The Adventures of Sherlock Holmes");
    String response = sendAddToCatalogRequest(template, routeboxUri, "addToCatalog", book);
    assertEquals("Book with Author " + book.getAuthor() + " and title " + book.getTitle() + " added to Catalog", response);
    // Wait for 2 seconds before a follow-on request if the requests are sent in async mode
    // to allow the earlier request to take effect
    //Thread.sleep(2000);
    book = sendFindBookRequest(template, routeboxUri, "findBook", "Sir Arthur Conan Doyle");
    LOG.debug("Received book with author {} and title {}", book.getAuthor(), book.getTitle());
    assertEquals("The Adventures of Sherlock Holmes", book.getTitle());
    LOG.debug("Completed Test ---> testRouteboxSedaAsyncRequests()");
    context.stop();
}
Also used : SimpleRouteBuilder(org.apache.camel.component.routebox.demo.SimpleRouteBuilder) RouteBuilder(org.apache.camel.builder.RouteBuilder) Book(org.apache.camel.component.routebox.demo.Book) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) Test(org.junit.Test)

Aggregations

DefaultProducerTemplate (org.apache.camel.impl.DefaultProducerTemplate)11 Test (org.junit.Test)8 RouteBuilder (org.apache.camel.builder.RouteBuilder)5 Book (org.apache.camel.component.routebox.demo.Book)5 SimpleRouteBuilder (org.apache.camel.component.routebox.demo.SimpleRouteBuilder)5 ArrayList (java.util.ArrayList)2 ExecutorService (java.util.concurrent.ExecutorService)2 Future (java.util.concurrent.Future)2 ProducerTemplate (org.apache.camel.ProducerTemplate)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 CamelContext (org.apache.camel.CamelContext)1 Endpoint (org.apache.camel.Endpoint)1 DefaultConsumerTemplate (org.apache.camel.impl.DefaultConsumerTemplate)1