@Test
public void consumeEntity() throws Exception {
setUp("jpa://" + Customer.class.getName() + "?usePersist=" + (usePersist() ? "true" : "false"));
final Customer customer = createDefaultCustomer();
save(customer);
final CountDownLatch latch = new CountDownLatch(1);
consumer = endpoint.createConsumer(new Processor() {
public void process(Exchange e) {
receivedExchange = e;
assertNotNull(e.getIn().getHeader(JpaConstants.JPA_TEMPLATE, JpaTemplate.class));
latch.countDown();
}
});
consumer.start();
boolean received = latch.await(50, TimeUnit.SECONDS);
assertTrue(received);
assertNotNull(receivedExchange);
Customer receivedCustomer = receivedExchange.getIn().getBody(Customer.class);
assertEquals(customer.getName(), receivedCustomer.getName());
assertEquals(customer.getId(), receivedCustomer.getId());
assertEquals(customer.getAddress().getAddressLine1(), receivedCustomer.getAddress().getAddressLine1());
assertEquals(customer.getAddress().getAddressLine2(), receivedCustomer.getAddress().getAddressLine2());
assertEquals(customer.getAddress().getId(), receivedCustomer.getAddress().getId());
// give a bit tiem for consumer to delete after done
Thread.sleep(1000);
assertEntitiesInDatabase(0, Customer.class.getName());