use of org.apache.camel.examples.Customer in project camel by apache.
the class JpaProducerWithQueryTest method testProducerWithNamedQuery.
@Test
public void testProducerWithNamedQuery() throws Exception {
template.sendBody("direct:deleteCustomers", "");
Customer c1 = new Customer();
c1.setName("Willem");
template.sendBody("direct:addCustomer", c1);
Customer c2 = new Customer();
c2.setName("Dummy");
template.sendBody("direct:addCustomer", c2);
Object answer = template.requestBody("direct:namedQuery", "Willem");
List list = (List) answer;
assertEquals(1, list.size());
assertEquals("Willem", ((Customer) list.get(0)).getName());
answer = template.requestBody("direct:deleteCustomers", "");
assertEquals(2, ((Integer) answer).intValue());
}
use of org.apache.camel.examples.Customer in project camel by apache.
the class JpaPollingConsumerLockEntityTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() {
return new SpringRouteBuilder() {
public void configure() {
AggregationStrategy enrichStrategy = new AggregationStrategy() {
@Override
public Exchange aggregate(Exchange originalExchange, Exchange jpaExchange) {
Customer customer = jpaExchange.getIn().getBody(Customer.class);
customer.setOrderCount(customer.getOrderCount() + 1);
return jpaExchange;
}
};
onException(Exception.class).setBody().simple("${exception}").to("mock:error").handled(true);
from("direct:locked").onException(OptimisticLockException.class).redeliveryDelay(60).maximumRedeliveries(2).end().pollEnrich().simple("jpa://" + Customer.class.getName() + "?lockModeType=OPTIMISTIC_FORCE_INCREMENT&query=select c from Customer c where c.name like '${header.name}'").aggregationStrategy(enrichStrategy).to("jpa://" + Customer.class.getName()).setBody().simple("orders: ${body.orderCount}").to("mock:locked");
from("direct:not-locked").pollEnrich().simple("jpa://" + Customer.class.getName() + "?query=select c from Customer c where c.name like '${header.name}'").aggregationStrategy(enrichStrategy).to("jpa://" + Customer.class.getName()).setBody().simple("orders: ${body.orderCount}").to("mock:not-locked");
}
};
}
use of org.apache.camel.examples.Customer in project camel by apache.
the class JpaPollingConsumerTest method testPollingConsumer.
@Test
public void testPollingConsumer() throws Exception {
Customer customer = new Customer();
customer.setName("Donald Duck");
saveEntityInDB(customer);
Customer customer2 = new Customer();
customer2.setName("Goofy");
saveEntityInDB(customer2);
assertEntitiesInDatabase(2, Customer.class.getName());
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello Donald Duck how are you today?");
template.sendBodyAndHeader("direct:start", "Hello NAME how are you today?", "name", "Donald%");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.examples.Customer in project camel by apache.
the class JpaWithNamedQueryAndParametersTest method testProducerInsertsIntoDatabaseThenConsumerFiresMessageExchange.
@Test
public void testProducerInsertsIntoDatabaseThenConsumerFiresMessageExchange() throws Exception {
transactionTemplate.execute(new TransactionCallback<Object>() {
public Object doInTransaction(TransactionStatus status) {
entityManager.joinTransaction();
// lets delete any exiting records before the test
entityManager.createQuery("delete from " + entityName).executeUpdate();
// now lets create a dummy entry
Customer dummy = new Customer();
dummy.setName("Test");
entityManager.persist(dummy);
return null;
}
});
List<?> results = entityManager.createQuery(queryText).getResultList();
assertEquals("Should have no results: " + results, 0, results.size());
// lets produce some objects
template.send(endpoint, new Processor() {
public void process(Exchange exchange) {
Customer customer = new Customer();
customer.setName("Willem");
exchange.getIn().setBody(customer);
}
});
// now lets assert that there is a result
results = entityManager.createQuery(queryText).getResultList();
assertEquals("Should have results: " + results, 1, results.size());
Customer customer = (Customer) results.get(0);
assertEquals("name property", "Willem", customer.getName());
// now lets create a consumer to consume it
consumer = endpoint.createConsumer(new Processor() {
public void process(Exchange e) {
LOG.info("Received exchange: " + e.getIn());
receivedExchange = e;
latch.countDown();
}
});
consumer.start();
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertReceivedResult(receivedExchange);
JpaConsumer jpaConsumer = (JpaConsumer) consumer;
assertURIQueryOption(jpaConsumer);
}
use of org.apache.camel.examples.Customer in project camel by apache.
the class AbstractJpaMethodTest method createDefaultCustomer.
protected Customer createDefaultCustomer() {
Customer customer = new Customer();
customer.setName("Christian Mueller");
Address address = new Address();
address.setAddressLine1("Hahnstr. 1");
address.setAddressLine2("60313 Frankfurt am Main");
customer.setAddress(address);
return customer;
}
Aggregations