use of org.apache.camel.examples.SendEmail in project camel by apache.
the class JpaBatchConsumerTest method testBatchConsumer.
@Test
public void testBatchConsumer() throws Exception {
// first create two records
template.sendBody("jpa://" + SendEmail.class.getName(), new SendEmail("foo@beer.org"));
template.sendBody("jpa://" + SendEmail.class.getName(), new SendEmail("bar@beer.org"));
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(2);
mock.message(0).property(Exchange.BATCH_INDEX).isEqualTo(0);
mock.message(0).property(Exchange.BATCH_COMPLETE).isEqualTo(false);
mock.message(1).property(Exchange.BATCH_INDEX).isEqualTo(1);
mock.message(1).property(Exchange.BATCH_COMPLETE).isEqualTo(true);
mock.expectedPropertyReceived(Exchange.BATCH_SIZE, 2);
assertMockEndpointsSatisfied();
}
use of org.apache.camel.examples.SendEmail in project camel by apache.
the class JpaFlushOnSendTest method testRouteJpa.
@Test
public void testRouteJpa() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.sendBody("direct:start", new SendEmail("someone@somewhere.org"));
assertMockEndpointsSatisfied();
assertEntityInDB();
}
use of org.apache.camel.examples.SendEmail in project camel by apache.
the class JpaProducerConcurrentTest method doSendMessages.
private void doSendMessages(int files, int poolSize) throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(files);
getMockEndpoint("mock:result").assertNoDuplicates(body());
ExecutorService executor = Executors.newFixedThreadPool(poolSize);
// we access the responses Map below only inside the main thread,
// so no need for a thread-safe Map implementation
Map<Integer, Future<SendEmail>> responses = new HashMap<Integer, Future<SendEmail>>();
for (int i = 0; i < files; i++) {
final int index = i;
Future<SendEmail> out = executor.submit(new Callable<SendEmail>() {
public SendEmail call() throws Exception {
return template.requestBody("direct:start", new SendEmail("user" + index + "@somewhere.org"), SendEmail.class);
}
});
responses.put(index, out);
}
assertMockEndpointsSatisfied(30, TimeUnit.SECONDS);
assertEquals(files, responses.size());
// get them so they are complete
for (Future<SendEmail> future : responses.values()) {
SendEmail sendEmail = future.get();
assertNotNull(sendEmail);
log.info("Persisted the SendEmail entity with the id {} and the address {}", sendEmail.getId(), sendEmail.getAddress());
}
// assert in the database
assertEntityInDB(files);
executor.shutdownNow();
}
use of org.apache.camel.examples.SendEmail in project camel by apache.
the class JpaProducerPassingEntityManagerTest method testRouteJpa.
@Test
public void testRouteJpa() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
context.startRoute("foo");
JpaEndpoint jpa = context.getEndpoint("jpa://" + SendEmail.class.getName(), JpaEndpoint.class);
EntityManagerFactory emf = jpa.getEntityManagerFactory();
// The entity instance is different if it is retrieved from different EntityManager instance
EntityManager entityManager = emf.createEntityManager();
template.sendBody("direct:start", new SendEmail("foo@beer.org"));
Exchange exchange = mock.getReceivedExchanges().get(0);
SendEmail persistedEntity = exchange.getIn().getBody(SendEmail.class);
SendEmail emfindEntity = entityManager.find(SendEmail.class, persistedEntity.getId());
assertNotSame(emfindEntity, persistedEntity);
entityManager.close();
mock.reset();
// The same EntityManager returns same entity instance from its 1st level cache
entityManager = emf.createEntityManager();
template.sendBodyAndHeader("direct:start", new SendEmail("bar@beer.org"), JpaConstants.ENTITYMANAGER, entityManager);
exchange = mock.getReceivedExchanges().get(0);
persistedEntity = exchange.getIn().getBody(SendEmail.class);
emfindEntity = entityManager.find(SendEmail.class, persistedEntity.getId());
assertSame(emfindEntity, persistedEntity);
entityManager.close();
}
use of org.apache.camel.examples.SendEmail in project camel by apache.
the class JpaRouteMaximumResultsTest method testRouteJpa.
@Test
public void testRouteJpa() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(1);
template.sendBody("direct:start", new SendEmail("one@somewhere.org"));
template.sendBody("direct:start", new SendEmail("two@somewhere.org"));
template.sendBody("direct:start", new SendEmail("three@somewhere.org"));
assertMockEndpointsSatisfied();
assertEntityInDB(3);
// should not consume 3 at once
assertTrue("Should not consume all 3 at once", mock.getReceivedCounter() < 3);
}
Aggregations