Search in sources :

Example 71 with MockEndpoint

use of org.apache.camel.component.mock.MockEndpoint in project camel by apache.

the class ElSqlConsumerDeleteTest method testConsume.

@Test
public void testConsume() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(3);
    assertMockEndpointsSatisfied();
    List<Exchange> exchanges = mock.getReceivedExchanges();
    assertEquals(3, exchanges.size());
    assertEquals(1, exchanges.get(0).getIn().getBody(Map.class).get("ID"));
    assertEquals("Camel", exchanges.get(0).getIn().getBody(Map.class).get("PROJECT"));
    assertEquals(2, exchanges.get(1).getIn().getBody(Map.class).get("ID"));
    assertEquals("AMQ", exchanges.get(1).getIn().getBody(Map.class).get("PROJECT"));
    assertEquals(3, exchanges.get(2).getIn().getBody(Map.class).get("ID"));
    assertEquals("Linux", exchanges.get(2).getIn().getBody(Map.class).get("PROJECT"));
    // some servers may be a bit slow for this
    for (int i = 0; i < 5; i++) {
        // give it a little tine to delete
        Thread.sleep(1000);
        int rows = jdbcTemplate.queryForObject("select count(*) from projects", Integer.class);
        if (rows == 0) {
            break;
        }
    }
    assertEquals("Should have deleted all 3 rows", new Integer(0), jdbcTemplate.queryForObject("select count(*) from projects", Integer.class));
}
Also used : Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 72 with MockEndpoint

use of org.apache.camel.component.mock.MockEndpoint in project camel by apache.

the class ElSqlProducerBatchTest method testBatchMode.

@Test
public void testBatchMode() throws InterruptedException {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.message(0).header(SqlConstants.SQL_UPDATE_COUNT).isEqualTo(1);
    Map<String, Object> batchParams = new HashMap<>();
    batchParams.put("id", "4");
    batchParams.put("license", "GNU");
    batchParams.put("project", "Batch");
    template.sendBody("direct:batch", batchParams);
    mock.assertIsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 73 with MockEndpoint

use of org.apache.camel.component.mock.MockEndpoint in project camel by apache.

the class ElSqlProducerStreamListTest method testSplitWithModel.

@Test
public void testSplitWithModel() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(3);
    template.sendBody("direct:withSplitModel", "testmsg");
    mock.assertIsSatisfied();
    assertThat(resultBodyAt(mock, 0), instanceOf(Project.class));
    assertThat(resultBodyAt(mock, 1), instanceOf(Project.class));
    assertThat(resultBodyAt(mock, 2), instanceOf(Project.class));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 74 with MockEndpoint

use of org.apache.camel.component.mock.MockEndpoint in project camel by apache.

the class DropboxProducerGetSingleTest method testCamelDropbox.

@Test
public void testCamelDropbox() throws Exception {
    template.send("direct:start", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader("test", "test");
        }
    });
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(1);
    assertMockEndpointsSatisfied();
    List<Exchange> exchanges = mock.getReceivedExchanges();
    Exchange exchange = exchanges.get(0);
    Object header = exchange.getIn().getHeader(DropboxResultHeader.DOWNLOADED_FILE.name());
    Object body = exchange.getIn().getBody();
    assertNotNull(header);
    assertNotNull(body);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 75 with MockEndpoint

use of org.apache.camel.component.mock.MockEndpoint in project camel by apache.

the class DropboxProducerPutSingleFileTest method testCamelDropbox.

@Test
public void testCamelDropbox() throws Exception {
    template.send("direct:start", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader("test", "test");
        }
    });
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(1);
    assertMockEndpointsSatisfied();
    List<Exchange> exchanges = mock.getReceivedExchanges();
    Exchange exchange = exchanges.get(0);
    Object header = exchange.getIn().getHeader(DropboxResultHeader.UPLOADED_FILE.name());
    Object body = exchange.getIn().getBody();
    assertNotNull(header);
    assertNotNull(body);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Aggregations

MockEndpoint (org.apache.camel.component.mock.MockEndpoint)3393 Test (org.junit.Test)2016 Exchange (org.apache.camel.Exchange)506 RouteBuilder (org.apache.camel.builder.RouteBuilder)302 Processor (org.apache.camel.Processor)148 File (java.io.File)144 HashMap (java.util.HashMap)130 ObjectName (javax.management.ObjectName)90 MBeanServer (javax.management.MBeanServer)85 Message (org.apache.camel.Message)85 InputStream (java.io.InputStream)73 ArrayList (java.util.ArrayList)63 CamelExecutionException (org.apache.camel.CamelExecutionException)63 List (java.util.List)57 CamelContext (org.apache.camel.CamelContext)57 ProducerTemplate (org.apache.camel.ProducerTemplate)51 Tx (org.nhindirect.common.tx.model.Tx)49 ByteArrayInputStream (java.io.ByteArrayInputStream)47 Map (java.util.Map)43 RuntimeCamelException (org.apache.camel.RuntimeCamelException)38