use of org.apache.camel.examples.SendEmail in project camel by apache.
the class JpaRouteSharedEntityManagerTest method testRouteJpaNotShared.
@Test
public void testRouteJpaNotShared() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.sendBody("direct:startNotshared", new SendEmail("one@somewhere.org"));
int countStart = getBrokerCount();
assertThat("brokerCount", countStart, equalTo(1));
// start route
context.startRoute("jpaOwn");
// not the cleanest way to check the number of open connections
int countEnd = getBrokerCount();
assertThat("brokerCount", countEnd, equalTo(2));
latch.countDown();
assertMockEndpointsSatisfied();
}
use of org.apache.camel.examples.SendEmail in project camel by apache.
the class JpaRouteTest method testRouteJpa.
@Test
public void testRouteJpa() throws Exception {
// should auto setup transaction manager and entity factory
JpaComponent jpa = context.getComponent("jpa", JpaComponent.class);
assertNotNull("Should have been auto assigned", jpa.getEntityManagerFactory());
assertNotNull("Should have been auto assigned", jpa.getTransactionManager());
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
ValueBuilder header = mock.message(0).header(JpaConstants.ENTITYMANAGER);
header.isNotNull();
header.isInstanceOf(EntityManager.class);
template.sendBody("direct:start", new SendEmail("someone@somewhere.org"));
assertMockEndpointsSatisfied();
assertEntityInDB(1);
}
use of org.apache.camel.examples.SendEmail in project camel by apache.
the class JpaTXRollbackTest method testTXRollback.
@Test
public void testTXRollback() throws Exception {
// first create three records
template.sendBody("jpa://" + SendEmail.class.getName(), new SendEmail("foo@beer.org"));
template.sendBody("jpa://" + SendEmail.class.getName(), new SendEmail("bar@beer.org"));
template.sendBody("jpa://" + SendEmail.class.getName(), new SendEmail("kaboom@beer.org"));
// should rollback the entire
MockEndpoint mock = getMockEndpoint("mock:result");
// we should retry and try again
mock.expectedMinimumMessageCount(4);
// start route
context.startRoute("foo");
assertMockEndpointsSatisfied();
assertTrue("Should be >= 2, was: " + foo.intValue(), foo.intValue() >= 2);
assertTrue("Should be >= 2, was: " + bar.intValue(), bar.intValue() >= 2);
}
use of org.apache.camel.examples.SendEmail in project camel by apache.
the class JpaWireTapTest method testRouteJpa.
@Test
public void testRouteJpa() throws Exception {
// should auto setup transaction manager and entity factory
JpaComponent jpa = context.getComponent("jpa", JpaComponent.class);
assertNotNull("Should have been auto assigned", jpa.getEntityManagerFactory());
assertNotNull("Should have been auto assigned", jpa.getTransactionManager());
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(2);
template.sendBody("direct:start", new SendEmail("someone@somewhere.org"));
assertMockEndpointsSatisfied();
assertEntityInDB(2);
}
use of org.apache.camel.examples.SendEmail in project camel by apache.
the class JpaTest method testProducerInsertsIntoDatabaseThenConsumerFiresMessageExchange.
@Test
public void testProducerInsertsIntoDatabaseThenConsumerFiresMessageExchange() throws Exception {
transactionTemplate.execute(new TransactionCallback<Object>() {
public Object doInTransaction(TransactionStatus status) {
entityManager.joinTransaction();
// lets delete any exiting records before the test
entityManager.createQuery("delete from " + entityName).executeUpdate();
return null;
}
});
List<?> results = entityManager.createQuery(queryText).getResultList();
assertEquals("Should have no results: " + results, 0, results.size());
// lets produce some objects
template.send(endpoint, new Processor() {
public void process(Exchange exchange) {
exchange.getIn().setBody(new SendEmail("foo@bar.com"));
}
});
// now lets assert that there is a result
results = entityManager.createQuery(queryText).getResultList();
assertEquals("Should have results: " + results, 1, results.size());
SendEmail mail = (SendEmail) results.get(0);
assertEquals("address property", "foo@bar.com", mail.getAddress());
// now lets create a consumer to consume it
consumer = endpoint.createConsumer(new Processor() {
public void process(Exchange e) {
LOG.info("Received exchange: " + e.getIn());
receivedExchange = e;
// should have a EntityManager
EntityManager entityManager = e.getIn().getHeader(JpaConstants.ENTITYMANAGER, EntityManager.class);
assertNotNull("Should have a EntityManager as header", entityManager);
latch.countDown();
}
});
consumer.start();
assertTrue(latch.await(50, TimeUnit.SECONDS));
assertNotNull(receivedExchange);
SendEmail result = receivedExchange.getIn().getBody(SendEmail.class);
assertNotNull("Received a POJO", result);
assertEquals("address property", "foo@bar.com", result.getAddress());
}
Aggregations