use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.
the class JpaMessageHandlerParserTests method testJpaMessageHandlerParserWithEntityManagerFactory.
@Test
public void testJpaMessageHandlerParserWithEntityManagerFactory() throws Exception {
setUp("JpaMessageHandlerParserTestsWithEmFactory.xml", getClass());
final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(this.consumer, "inputChannel", AbstractMessageChannel.class);
assertEquals("target", inputChannel.getComponentName());
final JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.consumer, "handler.jpaExecutor", JpaExecutor.class);
assertNotNull(jpaExecutor);
final String query = TestUtils.getPropertyValue(jpaExecutor, "jpaQuery", String.class);
assertEquals("select student from Student student", query);
final JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class);
assertNotNull(jpaOperations);
final PersistMode persistMode = TestUtils.getPropertyValue(jpaExecutor, "persistMode", PersistMode.class);
assertEquals(PersistMode.PERSIST, persistMode);
@SuppressWarnings("unchecked") List<JpaParameter> jpaParameters = TestUtils.getPropertyValue(jpaExecutor, "jpaParameters", List.class);
assertNotNull(jpaParameters);
assertTrue(jpaParameters.size() == 3);
}
use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.
the class JpaPollingChannelAdapterUnitTests method testGetComponentType.
/**
*/
@Test
public void testGetComponentType() {
JpaExecutor jpaExecutor = mock(JpaExecutor.class);
final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor);
assertEquals("jpa:inbound-channel-adapter", jpaPollingChannelAdapter.getComponentType());
}
use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.
the class JpaOutboundChannelAdapterTests method saveEntityWithPersist.
@Test
public void saveEntityWithPersist() throws InterruptedException {
List<?> results1 = this.jdbcTemplate.queryForList("Select * from Student");
Assert.assertNotNull(results1);
Assert.assertTrue(results1.size() == 3);
JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
jpaExecutor.setEntityClass(StudentDomain.class);
jpaExecutor.setPersistMode(PersistMode.PERSIST);
jpaExecutor.setBeanFactory(mock(BeanFactory.class));
jpaExecutor.afterPropertiesSet();
final JpaOutboundGateway jpaOutboundChannelAdapter = new JpaOutboundGateway(jpaExecutor);
jpaOutboundChannelAdapter.setProducesReply(false);
StudentDomain testStudent = JpaTestUtils.getTestStudent();
Assert.assertNull(testStudent.getRollNumber());
final Message<StudentDomain> message = MessageBuilder.withPayload(testStudent).build();
jpaOutboundChannelAdapter.setBeanFactory(mock(BeanFactory.class));
jpaOutboundChannelAdapter.afterPropertiesSet();
TransactionTemplate transactionTemplate = new TransactionTemplate(this.transactionManager);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
jpaOutboundChannelAdapter.handleMessage(message);
}
});
List<?> results2 = this.jdbcTemplate.queryForList("Select * from Student");
Assert.assertNotNull(results2);
Assert.assertTrue(results2.size() == 4);
Assert.assertNotNull(testStudent.getRollNumber());
}
use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.
the class JpaOutboundChannelAdapterTests method saveEntityWithMerge.
@Test
public void saveEntityWithMerge() throws InterruptedException {
List<?> results1 = this.jdbcTemplate.queryForList("Select * from Student");
Assert.assertNotNull(results1);
Assert.assertTrue(results1.size() == 3);
JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
jpaExecutor.setEntityClass(StudentDomain.class);
jpaExecutor.setBeanFactory(mock(BeanFactory.class));
jpaExecutor.afterPropertiesSet();
final JpaOutboundGateway jpaOutboundChannelAdapter = new JpaOutboundGateway(jpaExecutor);
jpaOutboundChannelAdapter.setProducesReply(false);
StudentDomain testStudent = JpaTestUtils.getTestStudent();
final Message<StudentDomain> message = MessageBuilder.withPayload(testStudent).build();
TransactionTemplate transactionTemplate = new TransactionTemplate(this.transactionManager);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
jpaOutboundChannelAdapter.handleMessage(message);
}
});
List<?> results2 = this.jdbcTemplate.queryForList("Select * from Student");
Assert.assertNotNull(results2);
Assert.assertTrue(results2.size() == 4);
Assert.assertNull(testStudent.getRollNumber());
}
Aggregations