Search in sources :

Example 6 with JpaExecutor

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());
}
Also used : JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) Test(org.junit.Test)

Example 7 with JpaExecutor

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);
}
Also used : JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) Test(org.junit.Test)

Example 8 with JpaExecutor

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"));
}
Also used : AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) ParameterSource(org.springframework.integration.jpa.support.parametersource.ParameterSource) JpaOperations(org.springframework.integration.jpa.core.JpaOperations) Test(org.junit.Test)

Example 9 with JpaExecutor

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());
}
Also used : StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain) Message(org.springframework.messaging.Message) Consumer(org.springframework.integration.jpa.test.Consumer) JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) ArrayList(java.util.ArrayList) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Collection(java.util.Collection) Test(org.junit.Test)

Example 10 with JpaExecutor

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);
}
Also used : Consumer(org.springframework.integration.jpa.test.Consumer) Message(org.springframework.messaging.Message) JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) ArrayList(java.util.ArrayList) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Collection(java.util.Collection) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Aggregations

Test (org.junit.Test)24 JpaExecutor (org.springframework.integration.jpa.core.JpaExecutor)24 ArrayList (java.util.ArrayList)9 Collection (java.util.Collection)9 SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)9 Consumer (org.springframework.integration.jpa.test.Consumer)9 Message (org.springframework.messaging.Message)9 AbstractMessageChannel (org.springframework.integration.channel.AbstractMessageChannel)7 JpaOperations (org.springframework.integration.jpa.core.JpaOperations)7 StudentDomain (org.springframework.integration.jpa.test.entity.StudentDomain)4 DirtiesContext (org.springframework.test.annotation.DirtiesContext)4 BeanFactory (org.springframework.beans.factory.BeanFactory)3 LiteralExpression (org.springframework.expression.common.LiteralExpression)3 JpaParameter (org.springframework.integration.jpa.support.JpaParameter)3 PersistMode (org.springframework.integration.jpa.support.PersistMode)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)3 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)3 JpaOutboundGateway (org.springframework.integration.jpa.outbound.JpaOutboundGateway)2 OutboundGatewayType (org.springframework.integration.jpa.support.OutboundGatewayType)2