Search in sources :

Example 41 with MockEndpoint

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

the class RedisConsumerIntegrationTest method consumerReceivesMessages.

@Test
public void consumerReceivesMessages() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(1);
    mock.expectedBodiesReceived("message");
    sendHeaders(RedisConstants.COMMAND, "PUBLISH", RedisConstants.CHANNEL, "two", RedisConstants.MESSAGE, "message");
    mock.assertIsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 42 with MockEndpoint

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

the class SpringAggregatorWithCustomStrategyTest method testSendingMessagesWithCustomAggregator.

public void testSendingMessagesWithCustomAggregator() throws Exception {
    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
    resultEndpoint.expectedBodiesReceived("message:1 message:2 message:3");
    // lets send a large batch of messages
    for (int i = 1; i <= 3; i++) {
        String body = "message:" + i;
        template.sendBodyAndHeader("direct:start", body, "cheese", 123);
    }
    resultEndpoint.assertIsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 43 with MockEndpoint

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

the class SpringIdempotentConsumerNoSkipDuplicateTest method testDuplicateMessagesAreFilteredOut.

public void testDuplicateMessagesAreFilteredOut() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("one", "two", "one", "two", "one", "three");
    mock.message(0).property(Exchange.DUPLICATE_MESSAGE).isNull();
    mock.message(1).property(Exchange.DUPLICATE_MESSAGE).isNull();
    mock.message(2).property(Exchange.DUPLICATE_MESSAGE).isEqualTo(Boolean.TRUE);
    mock.message(3).property(Exchange.DUPLICATE_MESSAGE).isEqualTo(Boolean.TRUE);
    mock.message(4).property(Exchange.DUPLICATE_MESSAGE).isEqualTo(Boolean.TRUE);
    mock.message(5).property(Exchange.DUPLICATE_MESSAGE).isNull();
    sendMessage("1", "one");
    sendMessage("2", "two");
    sendMessage("1", "one");
    sendMessage("2", "two");
    sendMessage("1", "one");
    sendMessage("3", "three");
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 44 with MockEndpoint

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

the class TransactionalClientDataSourceWithOnExceptionTest method testTransactionRollback.

public void testTransactionRollback() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:error");
    mock.expectedMessageCount(1);
    try {
        template.sendBody("direct:fail", "Hello World");
        fail("Should have thrown exception");
    } catch (RuntimeCamelException e) {
        // expected as we fail
        assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
        assertTrue(e.getCause().getCause() instanceof IllegalArgumentException);
        assertEquals("We don't have Donkeys, only Camels", e.getCause().getCause().getMessage());
    }
    assertMockEndpointsSatisfied();
    int count = jdbc.queryForObject("select count(*) from books", Integer.class);
    assertEquals("Number of books", 1, count);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RuntimeCamelException(org.apache.camel.RuntimeCamelException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 45 with MockEndpoint

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

the class TransactionalClientWithAnnotatedBeanTest method testTransactionSuccess.

@Override
public void testTransactionSuccess() throws Exception {
    MockEndpoint book = getMockEndpoint("mock:book");
    book.expectedMessageCount(2);
    super.testTransactionSuccess();
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

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