Search in sources :

Example 11 with Customer

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());
}
Also used : Address(org.apache.camel.examples.Address) Customer(org.apache.camel.examples.Customer) Test(org.junit.Test)

Aggregations

Customer (org.apache.camel.examples.Customer)11 Test (org.junit.Test)7 Address (org.apache.camel.examples.Address)4 Exchange (org.apache.camel.Exchange)3 Processor (org.apache.camel.Processor)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 EntityManager (javax.persistence.EntityManager)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)1 SpringRouteBuilder (org.apache.camel.spring.SpringRouteBuilder)1 Before (org.junit.Before)1