use of org.apache.camel.examples.Customer in project camel by apache.
the class AbstractJpaMethodTest method produceNewEntity.
@Test
public void produceNewEntity() throws Exception {
setUp("jpa://" + Customer.class.getName() + "?usePersist=" + (usePersist() ? "true" : "false"));
Customer customer = createDefaultCustomer();
Customer receivedCustomer = template.requestBody(endpoint, customer, Customer.class);
assertEquals(customer.getName(), receivedCustomer.getName());
assertNotNull(receivedCustomer.getId());
assertEquals(customer.getAddress().getAddressLine1(), receivedCustomer.getAddress().getAddressLine1());
assertEquals(customer.getAddress().getAddressLine2(), receivedCustomer.getAddress().getAddressLine2());
assertNotNull(receivedCustomer.getAddress().getId());
List<?> results = entityManager.createQuery("select o from " + Customer.class.getName() + " o").getResultList();
assertEquals(1, results.size());
Customer persistedCustomer = (Customer) results.get(0);
assertEquals(receivedCustomer.getName(), persistedCustomer.getName());
assertEquals(receivedCustomer.getId(), persistedCustomer.getId());
assertEquals(receivedCustomer.getAddress().getAddressLine1(), persistedCustomer.getAddress().getAddressLine1());
assertEquals(receivedCustomer.getAddress().getAddressLine2(), persistedCustomer.getAddress().getAddressLine2());
assertEquals(receivedCustomer.getAddress().getId(), persistedCustomer.getAddress().getId());
}
use of org.apache.camel.examples.Customer in project camel by apache.
the class AbstractJpaMethodTest method consumeEntity.
@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.ENTITYMANAGER, EntityManager.class));
latch.countDown();
}
});
consumer.start();
assertTrue(latch.await(50, TimeUnit.SECONDS));
consumer.stop();
Thread.sleep(1000);
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 time for consumer to delete after done
Thread.sleep(1000);
assertEntitiesInDatabase(0, Customer.class.getName());
assertEntitiesInDatabase(0, Address.class.getName());
}
use of org.apache.camel.examples.Customer in project camel by apache.
the class JpaUseMergeTest method produceExistingEntity.
@Test
public void produceExistingEntity() throws Exception {
setUp("jpa://" + Customer.class.getName() + "?usePersist=false");
final Customer customer = createDefaultCustomer();
transactionTemplate.execute(new TransactionCallback<Object>() {
public Object doInTransaction(TransactionStatus status) {
entityManager.joinTransaction();
entityManager.persist(customer);
entityManager.flush();
return null;
}
});
assertEntitiesInDatabase(1, Customer.class.getName());
assertEntitiesInDatabase(1, Address.class.getName());
// do detach the persisted entity first before modifying it as we intend to merge it later on below
entityManager.detach(customer);
customer.setName("Max Mustermann");
customer.getAddress().setAddressLine1("Musterstr. 1");
customer.getAddress().setAddressLine2("11111 Enterhausen");
Customer receivedCustomer = template.requestBody(endpoint, customer, Customer.class);
assertEquals(customer.getName(), receivedCustomer.getName());
assertNotNull(receivedCustomer.getId());
assertEquals(customer.getAddress().getAddressLine1(), receivedCustomer.getAddress().getAddressLine1());
assertEquals(customer.getAddress().getAddressLine2(), receivedCustomer.getAddress().getAddressLine2());
assertNotNull(receivedCustomer.getAddress().getId());
List<?> results = entityManager.createQuery("select o from " + Customer.class.getName() + " o").getResultList();
assertEquals(1, results.size());
Customer persistedCustomer = (Customer) results.get(0);
assertEquals(receivedCustomer.getName(), persistedCustomer.getName());
assertEquals(receivedCustomer.getId(), persistedCustomer.getId());
assertEquals(receivedCustomer.getAddress().getAddressLine1(), persistedCustomer.getAddress().getAddressLine1());
assertEquals(receivedCustomer.getAddress().getAddressLine2(), persistedCustomer.getAddress().getAddressLine2());
assertEquals(receivedCustomer.getAddress().getId(), persistedCustomer.getAddress().getId());
}
use of org.apache.camel.examples.Customer in project camel by apache.
the class JpaWithNamedQueryAndParametersTest method assertReceivedResult.
protected void assertReceivedResult(Exchange exchange) {
assertNotNull(exchange);
Customer result = exchange.getIn().getBody(Customer.class);
assertNotNull("Received a POJO", result);
assertEquals("name property", "Willem", result.getName());
}
use of org.apache.camel.examples.Customer in project camel by apache.
the class JpaPollingConsumerLockEntityTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
Customer customer = new Customer();
customer.setName("Donald Duck");
saveEntityInDB(customer);
Customer customer2 = new Customer();
customer2.setName("Goofy");
saveEntityInDB(customer2);
assertEntityInDB(2, Customer.class);
}
Aggregations