Search in sources :

Example 61 with MockEndpoint

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

the class StringDataFormatTest method testUnMarshalString.

public void testUnMarshalString() throws Exception {
    // include a UTF-8 char in the text จ is a Thai elephant
    byte[] body = "Hello Thai Elephant จ".getBytes();
    MockEndpoint mock = getMockEndpoint("mock:unmarshal");
    mock.expectedMessageCount(1);
    String out = (String) template.requestBody("direct:unmarshal", body);
    assertMockEndpointsSatisfied();
    assertEquals(new String(body, "UTF-8"), out);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 62 with MockEndpoint

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

the class JdbcSpringAggregateTest method testJdbcAggregate.

@Test
public void testJdbcAggregate() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:aggregated");
    mock.expectedBodiesReceived("ABCDE");
    template.sendBodyAndHeader("direct:start", "A", "id", 123);
    template.sendBodyAndHeader("direct:start", "B", "id", 123);
    template.sendBodyAndHeader("direct:start", "C", "id", 123);
    template.sendBodyAndHeader("direct:start", "D", "id", 123);
    template.sendBodyAndHeader("direct:start", "E", "id", 123);
    assertMockEndpointsSatisfied(30, TimeUnit.SECONDS);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 63 with MockEndpoint

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

the class ScanStreamDelayTest method testScanFile.

@Test
public void testScanFile() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(6);
    assertMockEndpointsSatisfied(1, TimeUnit.SECONDS);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 64 with MockEndpoint

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

the class JdbcAggregateConcurrentSameGroupTest method doSendMessages.

private void doSendMessages(int files, int poolSize) throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:aggregated");
    mock.setResultWaitTime(30 * 1000L);
    mock.expectedMessageCount(1);
    ExecutorService executor = Executors.newFixedThreadPool(poolSize);
    for (int i = 0; i < files; i++) {
        final int index = i;
        executor.submit(new Callable<Object>() {

            public Object call() throws Exception {
                template.sendBodyAndHeader("direct:start", index, "id", 123);
                // simulate a little delay
                Thread.sleep(3);
                return null;
            }
        });
    }
    assertMockEndpointsSatisfied();
    executor.shutdownNow();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ExecutorService(java.util.concurrent.ExecutorService) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 65 with MockEndpoint

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

the class JdbcAggregateLoadAndRecoverTest method testLoadAndRecoverJdbcAggregate.

@Test
public void testLoadAndRecoverJdbcAggregate() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(SIZE / 10);
    mock.setResultWaitTime(50 * 1000);
    LOG.info("Staring to send " + SIZE + " messages.");
    for (int i = 0; i < SIZE; i++) {
        final int value = 1;
        char id = 'A';
        Map<String, Object> headers = new HashMap<String, Object>();
        headers.put("id", id);
        headers.put("seq", i);
        LOG.debug("Sending {} with id {}", value, id);
        template.sendBodyAndHeaders("seda:start?size=" + SIZE, value, headers);
        // simulate a little delay
        Thread.sleep(3);
    }
    LOG.info("Sending all " + SIZE + " message done. Now waiting for aggregation to complete.");
    assertMockEndpointsSatisfied();
    int recovered = 0;
    for (Exchange exchange : mock.getReceivedExchanges()) {
        if (exchange.getIn().getHeader(Exchange.REDELIVERED) != null) {
            recovered++;
        }
    }
    int expected = SIZE / 10 / 10;
    assertEquals("There should be " + expected + " recovered", expected, recovered);
}
Also used : Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HashMap(java.util.HashMap) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Aggregations

MockEndpoint (org.apache.camel.component.mock.MockEndpoint)3401 Test (org.junit.Test)2024 Exchange (org.apache.camel.Exchange)511 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