use of org.apache.camel.examples.Customer in project camel by apache.
the class JpaUsePersistTest method produceExistingEntityShouldThrowAnException.
@Test
public void produceExistingEntityShouldThrowAnException() throws Exception {
setUp("jpa://" + Customer.class.getName() + "?usePersist=true");
Customer customer = createDefaultCustomer();
save(customer);
long id = customer.getId();
// and adjust some values
customer = createDefaultCustomer();
customer.setId(id);
customer.setName("Max Mustermann");
customer.getAddress().setAddressLine1("Musterstr. 1");
customer.getAddress().setAddressLine2("11111 Enterhausen");
try {
// we cannot store the 2nd customer as its using the same id as the 1st
template.requestBody(endpoint, customer);
fail("Should throw exception");
} catch (Exception e) {
// expected
}
assertEntitiesInDatabase(1, Customer.class.getName());
assertEntitiesInDatabase(1, Address.class.getName());
}
Aggregations