Search in sources :

Example 46 with ProducerTemplate

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

the class PropertyPlaceholderRouteTest method testCamelContext.

@Test
public void testCamelContext() throws Exception {
    CamelContext context = getCamelContext();
    assertNotNull(context);
    assertEquals("MyCamel", context.getName());
    ProducerTemplate template = context.createProducerTemplate();
    MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedBodiesReceived("Hello World");
    template.sendBody("direct:foo", "World");
    mock.assertIsSatisfied();
    template.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 47 with ProducerTemplate

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

the class SnakeYAMLTestHelper method marshalAndUnmarshal.

public static void marshalAndUnmarshal(CamelContext context, Object body, String mockName, String directIn, String directBack, String expected) throws Exception {
    MockEndpoint mock = context.getEndpoint(mockName, MockEndpoint.class);
    assertNotNull(mock);
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(body.getClass());
    mock.message(0).body().isEqualTo(body);
    ProducerTemplate template = context.createProducerTemplate();
    String result = template.requestBody(directIn, body, String.class);
    assertNotNull(result);
    assertEquals(expected, result.trim());
    template.sendBody(directBack, result);
    mock.assertIsSatisfied();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 48 with ProducerTemplate

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

the class SqlProducerOutputTypeSelectOneTest method testSelectOneWithoutClass.

@Test
public void testSelectOneWithoutClass() throws Exception {
    camel1.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to("sql:select * from projects where id=3?outputType=SelectOne").to("mock:result");
        }
    });
    camel1.start();
    ProducerTemplate template = camel1.createProducerTemplate();
    MockEndpoint mock = (MockEndpoint) camel1.getEndpoint("mock:result");
    mock.expectedMessageCount(1);
    template.sendBody("direct:start", "testmsg");
    mock.assertIsSatisfied(2000);
    List<Exchange> exchanges = mock.getReceivedExchanges();
    Assert.assertThat(exchanges.size(), CoreMatchers.is(1));
    Map<String, Object> result = exchanges.get(0).getIn().getBody(Map.class);
    Assert.assertThat((Integer) result.get("ID"), CoreMatchers.is(3));
    Assert.assertThat((String) result.get("PROJECT"), CoreMatchers.is("Linux"));
    Assert.assertThat((String) result.get("LICENSE"), CoreMatchers.is("XXX"));
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 49 with ProducerTemplate

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

the class SqlProducerOutputTypeSelectOneTest method testSelectOneSingleColumnCount.

@Test
public void testSelectOneSingleColumnCount() throws Exception {
    camel1.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to("sql:select count(*) from projects?outputType=SelectOne").to("mock:result");
        }
    });
    camel1.start();
    ProducerTemplate template = camel1.createProducerTemplate();
    MockEndpoint mock = (MockEndpoint) camel1.getEndpoint("mock:result");
    mock.expectedMessageCount(1);
    template.sendBody("direct:start", "testmsg");
    mock.assertIsSatisfied(2000);
    List<Exchange> exchanges = mock.getReceivedExchanges();
    Assert.assertThat(exchanges.size(), CoreMatchers.is(1));
    Long result = exchanges.get(0).getIn().getBody(Long.class);
    Assert.assertThat(result, CoreMatchers.is(3L));
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 50 with ProducerTemplate

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

the class MainNoReloadTest 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-reload-loadfile.xml");
    // set the configAdmin persistent id
    main.setConfigAdminPid("stuff");
    // set the configAdmin persistent file name
    main.setConfigAdminFileName("src/test/resources/etc/stuff.cfg");
    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", "Bye 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