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);
}
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);
}
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();
}
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);
}
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);
}
Aggregations