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 = jpaTemplate.find(queryText);
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 JpaTemplate
JpaTemplate template = e.getIn().getHeader(JpaConstants.JPA_TEMPLATE, JpaTemplate.class);
assertNotNull("Should have a JpaTemplate as header", template);
latch.countDown();
}
});
consumer.start();
boolean received = latch.await(50, TimeUnit.SECONDS);
assertTrue("Did not receive the message!", received);
assertNotNull(receivedExchange);
SendEmail result = receivedExchange.getIn().getBody(SendEmail.class);
assertNotNull("Received a POJO", result);
assertEquals("address property", "foo@bar.com", result.getAddress());
}