use of org.apache.camel.component.jpa.JpaComponent in project camel by apache.
the class JpaRouteTest method testRouteJpa.
@Test
public void testRouteJpa() throws Exception {
// should auto setup transaction manager and entity factory
JpaComponent jpa = context.getComponent("jpa", JpaComponent.class);
assertNotNull("Should have been auto assigned", jpa.getEntityManagerFactory());
assertNotNull("Should have been auto assigned", jpa.getTransactionManager());
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
ValueBuilder header = mock.message(0).header(JpaConstants.ENTITYMANAGER);
header.isNotNull();
header.isInstanceOf(EntityManager.class);
template.sendBody("direct:start", new SendEmail("someone@somewhere.org"));
assertMockEndpointsSatisfied();
assertEntityInDB(1);
}
use of org.apache.camel.component.jpa.JpaComponent in project camel by apache.
the class JpaWireTapTest method testRouteJpa.
@Test
public void testRouteJpa() throws Exception {
// should auto setup transaction manager and entity factory
JpaComponent jpa = context.getComponent("jpa", JpaComponent.class);
assertNotNull("Should have been auto assigned", jpa.getEntityManagerFactory());
assertNotNull("Should have been auto assigned", jpa.getTransactionManager());
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(2);
template.sendBody("direct:start", new SendEmail("someone@somewhere.org"));
assertMockEndpointsSatisfied();
assertEntityInDB(2);
}
use of org.apache.camel.component.jpa.JpaComponent in project camel by apache.
the class JpaComponentAutoConfiguration method configureJpaComponent.
@Lazy
@Bean(name = "jpa-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(JpaComponent.class)
public JpaComponent configureJpaComponent(CamelContext camelContext, JpaComponentConfiguration configuration) throws Exception {
JpaComponent component = new JpaComponent();
component.setCamelContext(camelContext);
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null, false);
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
Object value = entry.getValue();
Class<?> paramClass = value.getClass();
if (paramClass.getName().endsWith("NestedConfiguration")) {
Class nestedClass = null;
try {
nestedClass = (Class) paramClass.getDeclaredField("CAMEL_NESTED_CLASS").get(null);
HashMap<String, Object> nestedParameters = new HashMap<>();
IntrospectionSupport.getProperties(value, nestedParameters, null, false);
Object nestedProperty = nestedClass.newInstance();
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), nestedProperty, nestedParameters);
entry.setValue(nestedProperty);
} catch (NoSuchFieldException e) {
}
}
}
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters);
return component;
}
Aggregations