use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.
the class JpaPollingChannelAdapterTests method testWithNamedQuery.
/**
* In this test, a Jpa Polling Channel Adapter will use Named query
* to retrieve a list of records from the database.
*
* @throws Exception
*/
@Test
public void testWithNamedQuery() throws Exception {
testTrigger.reset();
// ~~~~SETUP~~~~~
final JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
jpaExecutor.setNamedQuery("selectStudent");
jpaExecutor.afterPropertiesSet();
final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor);
final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter(jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader());
adapter.start();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
final List<Message<Collection<?>>> received = new ArrayList<Message<Collection<?>>>();
final Consumer consumer = new Consumer();
received.add(consumer.poll(10000));
Message<Collection<?>> message = received.get(0);
adapter.stop();
assertNotNull(message);
assertNotNull(message.getPayload());
Collection<?> students = message.getPayload();
assertTrue(students.size() == 1);
}
use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.
the class JpaOutboundChannelAdapterTests method saveEntityWithMergeWithoutSpecifyingEntityClass.
@Test
public void saveEntityWithMergeWithoutSpecifyingEntityClass() throws InterruptedException {
List<?> results1 = this.jdbcTemplate.queryForList("Select * from Student");
Assert.assertNotNull(results1);
Assert.assertTrue(results1.size() == 3);
JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
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());
}
use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.
the class JpaMessageHandlerParserTests method testProcedureParametersAreSet.
@SuppressWarnings("unchecked")
@Test
public void testProcedureParametersAreSet() throws Exception {
setUp("JpaMessageHandlerParserTestsWithEmFactory.xml", getClass());
final JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.consumer, "handler.jpaExecutor", JpaExecutor.class);
final List<JpaParameter> jpaParameters = TestUtils.getPropertyValue(jpaExecutor, "jpaParameters", List.class);
assertTrue(jpaParameters.size() == 3);
JpaParameter parameter1 = jpaParameters.get(0);
JpaParameter parameter2 = jpaParameters.get(1);
JpaParameter parameter3 = jpaParameters.get(2);
assertEquals("firstName", parameter1.getName());
assertEquals("firstaName", parameter2.getName());
assertEquals("updatedDateTime", parameter3.getName());
assertEquals("kenny", parameter1.getValue());
assertEquals("cartman", parameter2.getValue());
assertNull(parameter3.getValue());
assertNull(parameter1.getExpression());
assertNull(parameter2.getExpression());
assertEquals("new java.util.Date()", parameter3.getExpression());
}
use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.
the class JpaMessageHandlerParserTests method testJpaMessageHandlerParser.
@Test
public void testJpaMessageHandlerParser() throws Exception {
setUp("JpaMessageHandlerParserTests.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("from 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);
assertEquals(Integer.valueOf(10), TestUtils.getPropertyValue(jpaExecutor, "flushSize", Integer.class));
assertTrue(TestUtils.getPropertyValue(jpaExecutor, "clearOnFlush", Boolean.class));
}
use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.
the class JpaPollingChannelAdapterUnitTests method testReceiveNotNull.
/**
*/
@Test
public void testReceiveNotNull() {
JpaExecutor jpaExecutor = mock(JpaExecutor.class);
when(jpaExecutor.poll()).thenReturn("Spring");
final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor);
assertNotNull("Expecting a Message to be returned.", jpaPollingChannelAdapter.receive());
assertEquals("Spring", jpaPollingChannelAdapter.receive().getPayload());
}
Aggregations