Search in sources :

Example 51 with MockEndpoint

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

the class TransactionalClientDataSourceAsyncTest 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 52 with MockEndpoint

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

the class TransactionalClientDataSourceHandledTest method testTransactionRollback.

public void testTransactionRollback() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:error");
    mock.expectedMessageCount(1);
    template.sendBody("direct:fail", "Hello World");
    assertMockEndpointsSatisfied();
    int count = jdbc.queryForObject("select count(*) from books", Integer.class);
    // there should be 2 books as the first insert operation succeeded
    assertEquals("Number of books", 2, count);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 53 with MockEndpoint

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

the class TransactionalClientDataSourceTransactedWithFileOnExceptionTest method testTransactionRollback.

public void testTransactionRollback() throws Exception {
    MockEndpoint error = getMockEndpoint("mock:error");
    error.expectedMessageCount(1);
    error.message(0).header(Exchange.EXCEPTION_CAUGHT).isNotNull();
    error.message(0).header(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
    error.expectedFileExists("target/transacted/failed/fail.txt");
    template.sendBodyAndHeader("file://target/transacted/fail", "Hello World", Exchange.FILE_NAME, "fail.txt");
    // wait for route to complete
    Thread.sleep(3000);
    // should not be able to process the file so we still got 1 book as we did from the start
    int count = jdbc.queryForObject("select count(*) from books", Integer.class);
    assertEquals("Number of books", 1, count);
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 54 with MockEndpoint

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

the class TransactionalClientDataSourceWithOnExceptionRollbackTest 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());
        RollbackExchangeException rollback = assertIsInstanceOf(RollbackExchangeException.class, e.getCause().getCause());
        assertEquals("Donkey in Action", rollback.getExchange().getIn().getBody());
    }
    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) RollbackExchangeException(org.apache.camel.RollbackExchangeException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 55 with MockEndpoint

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

the class ContainerWideInterceptorTest method testTwo.

public void testTwo() throws Exception {
    int start = myInterceptor.getCount();
    MockEndpoint result = camel2.getEndpoint("mock:result", MockEndpoint.class);
    result.expectedBodiesReceived("Bye World");
    ProducerTemplate template = camel2.createProducerTemplate();
    template.start();
    template.sendBody("direct:two", "Bye World");
    template.stop();
    result.assertIsSatisfied();
    // lets see if the counter is +2 since last (has 2 steps in the route)
    int delta = myInterceptor.getCount() - start;
    assertEquals("Should have been counted +2", 2, delta);
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) 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