Search in sources :

Example 16 with SendEmail

use of org.apache.camel.examples.SendEmail in project camel by apache.

the class JpaProducerRemoveTest method testRouteJpa.

@Test
public void testRouteJpa() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    context.startRoute("foo");
    context.startRoute("foo1");
    JpaEndpoint jpa = context.getEndpoint("jpa://" + SendEmail.class.getName(), JpaEndpoint.class);
    EntityManagerFactory emf = jpa.getEntityManagerFactory();
    EntityManager entityManager = emf.createEntityManager();
    template.sendBody("direct:start", new SendEmail("foo@beer.org"));
    Exchange exchange = mock.getReceivedExchanges().get(0);
    SendEmail persistedEntity = exchange.getIn().getBody(SendEmail.class);
    SendEmail emfindEntity = entityManager.find(SendEmail.class, persistedEntity.getId());
    assertNotSame(emfindEntity, persistedEntity);
    entityManager.close();
    mock.reset();
    entityManager = emf.createEntityManager();
    template.sendBody("direct:remove", persistedEntity);
    exchange = mock.getReceivedExchanges().get(0);
    persistedEntity = exchange.getIn().getBody(SendEmail.class);
    emfindEntity = entityManager.find(SendEmail.class, persistedEntity.getId());
    assertNull(emfindEntity);
    entityManager.close();
}
Also used : Exchange(org.apache.camel.Exchange) EntityManager(javax.persistence.EntityManager) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) EntityManagerFactory(javax.persistence.EntityManagerFactory) JpaEndpoint(org.apache.camel.component.jpa.JpaEndpoint) SendEmail(org.apache.camel.examples.SendEmail) Test(org.junit.Test)

Aggregations

SendEmail (org.apache.camel.examples.SendEmail)16 Test (org.junit.Test)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)13 EntityManager (javax.persistence.EntityManager)3 Exchange (org.apache.camel.Exchange)3 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 JpaComponent (org.apache.camel.component.jpa.JpaComponent)2 JpaEndpoint (org.apache.camel.component.jpa.JpaEndpoint)2 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 Processor (org.apache.camel.Processor)1 ValueBuilder (org.apache.camel.builder.ValueBuilder)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1