use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.
the class JpaPollingChannelAdapterUnitTests method testReceiveNull.
/**
*/
@Test
public void testReceiveNull() {
JpaExecutor jpaExecutor = mock(JpaExecutor.class);
when(jpaExecutor.poll()).thenReturn(null);
final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor);
assertNull(jpaPollingChannelAdapter.receive());
}
use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.
the class JpaInboundChannelAdapterParserTests method testJpaExecutorBeanIdNaming.
@Test
public void testJpaExecutorBeanIdNaming() throws Exception {
JpaExecutor jpaExecutor1 = this.context.getBean("jpaInboundChannelAdapter1.jpaExecutor", JpaExecutor.class);
JpaExecutor jpaExecutor2 = this.context.getBean("jpaInboundChannelAdapter2.jpaExecutor", JpaExecutor.class);
assertNotNull(jpaExecutor1);
assertNotNull(jpaExecutor2);
assertNotSame(jpaExecutor1, jpaExecutor2);
assertEquals(5, this.context.getBeansOfType(JpaExecutor.class).size());
JpaExecutor jpaExecutorWithoutId0 = this.context.getBean("org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean#0.jpaExecutor", JpaExecutor.class);
JpaExecutor jpaExecutorWithoutId1 = this.context.getBean("org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean#1.jpaExecutor", JpaExecutor.class);
assertNotNull(jpaExecutorWithoutId0);
assertNotNull(jpaExecutorWithoutId1);
assertNotSame(jpaExecutorWithoutId0, jpaExecutorWithoutId1);
}
use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.
the class JpaInboundChannelAdapterParserTests method testJpaInboundChannelAdapterParser.
@Test
public void testJpaInboundChannelAdapterParser() throws Exception {
AbstractMessageChannel outputChannel = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter1, "outputChannel", AbstractMessageChannel.class);
assertEquals("out", outputChannel.getComponentName());
JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter1, "source.jpaExecutor", JpaExecutor.class);
assertNotNull(jpaExecutor);
Class<?> entityClass = TestUtils.getPropertyValue(jpaExecutor, "entityClass", Class.class);
assertEquals("org.springframework.integration.jpa.test.entity.StudentDomain", entityClass.getName());
JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class);
assertNotNull(jpaOperations);
assertTrue(TestUtils.getPropertyValue(jpaExecutor, "expectSingleResult", Boolean.class));
ParameterSource parameterSource = this.context.getBean(ParameterSource.class);
assertSame(parameterSource, TestUtils.getPropertyValue(jpaExecutor, "parameterSource"));
}
use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.
the class JpaPollingChannelAdapterTests method testWithJpaQueryOneResultOnly.
/**
* In this test, a Jpa Polling Channel Adapter will use JpQL query
* to retrieve a list of records from the database.
*
* @throws Exception
*/
@Test
public void testWithJpaQueryOneResultOnly() throws Exception {
testTrigger.reset();
// ~~~~SETUP~~~~~
final JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
jpaExecutor.setJpaQuery("from Student s where s.firstName = 'First Two'");
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);
StudentDomain student = (StudentDomain) students.iterator().next();
assertEquals("Last Two", student.getLastName());
}
use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.
the class JpaPollingChannelAdapterTests method testWithJpaQueryButNoResultsAndDelete.
@Test
@DirtiesContext
public void testWithJpaQueryButNoResultsAndDelete() throws Exception {
testTrigger.reset();
// ~~~~SETUP~~~~~
final JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
jpaExecutor.setJpaQuery("from Student s where s.lastName = 'Something Else'");
jpaExecutor.setDeleteAfterPoll(true);
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();
Thread.sleep(1000);
final Consumer consumer = new Consumer();
final List<Message<Collection<?>>> received = new ArrayList<Message<Collection<?>>>();
received.add(consumer.poll(10000));
final Message<Collection<?>> message = received.get(0);
adapter.stop();
assertNull(message);
}
Aggregations