Search in sources :

Example 11 with JpaExecutor

use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.

the class JpaInboundChannelAdapterParserTests method testJpaInboundChannelAdapterParserWithMaxResultsExpression.

@Test
public void testJpaInboundChannelAdapterParserWithMaxResultsExpression() throws Exception {
    AbstractMessageChannel outputChannel = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter3, "outputChannel", AbstractMessageChannel.class);
    assertEquals("out", outputChannel.getComponentName());
    JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter3, "source.jpaExecutor", JpaExecutor.class);
    assertNotNull(jpaExecutor);
    Class<?> entityClass = TestUtils.getPropertyValue(jpaExecutor, "entityClass", Class.class);
    assertEquals("org.springframework.integration.jpa.test.entity.StudentDomain", entityClass.getName());
    final JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class);
    assertNotNull(jpaOperations);
    SpelExpression expression = TestUtils.getPropertyValue(jpaExecutor, "maxResultsExpression", SpelExpression.class);
    assertNotNull(expression);
    assertEquals("@maxNumberOfResults", TestUtils.getPropertyValue(expression, "expression"));
}
Also used : AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) JpaOperations(org.springframework.integration.jpa.core.JpaOperations) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Test(org.junit.Test)

Example 12 with JpaExecutor

use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.

the class JpaInboundChannelAdapterParserTests method testJpaInboundChannelAdapterParserWithMaxResults.

@Test
public void testJpaInboundChannelAdapterParserWithMaxResults() throws Exception {
    AbstractMessageChannel outputChannel = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter2, "outputChannel", AbstractMessageChannel.class);
    assertEquals("out", outputChannel.getComponentName());
    JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter2, "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);
    LiteralExpression expression = TestUtils.getPropertyValue(jpaExecutor, "maxResultsExpression", LiteralExpression.class);
    assertNotNull(expression);
    assertEquals("13", TestUtils.getPropertyValue(expression, "literalValue"));
    assertTrue(TestUtils.getPropertyValue(jpaExecutor, "deleteAfterPoll", Boolean.class));
    assertTrue(TestUtils.getPropertyValue(jpaExecutor, "flush", Boolean.class));
}
Also used : AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) JpaOperations(org.springframework.integration.jpa.core.JpaOperations) LiteralExpression(org.springframework.expression.common.LiteralExpression) Test(org.junit.Test)

Example 13 with JpaExecutor

use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.

the class JpaOutboundGatewayParserTests method testRetrievingJpaOutboundGatewayParser.

@Test
public void testRetrievingJpaOutboundGatewayParser() throws Exception {
    setUp("JpaOutboundGatewayParserTests.xml", getClass(), "retrievingJpaOutboundGateway");
    final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(this.consumer, "inputChannel", AbstractMessageChannel.class);
    assertEquals("in", inputChannel.getComponentName());
    final JpaOutboundGateway jpaOutboundGateway = TestUtils.getPropertyValue(this.consumer, "handler", JpaOutboundGateway.class);
    final OutboundGatewayType gatewayType = TestUtils.getPropertyValue(jpaOutboundGateway, "gatewayType", OutboundGatewayType.class);
    assertEquals(OutboundGatewayType.RETRIEVING, gatewayType);
    long sendTimeout = TestUtils.getPropertyValue(jpaOutboundGateway, "messagingTemplate.sendTimeout", Long.class);
    assertEquals(100, sendTimeout);
    assertFalse(TestUtils.getPropertyValue(jpaOutboundGateway, "requiresReply", Boolean.class));
    final JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.consumer, "handler.jpaExecutor", JpaExecutor.class);
    assertNotNull(jpaExecutor);
    final Class<?> entityClass = TestUtils.getPropertyValue(jpaExecutor, "entityClass", Class.class);
    assertEquals("org.springframework.integration.jpa.test.entity.StudentDomain", entityClass.getName());
    final JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class);
    assertNotNull(jpaOperations);
    assertTrue(TestUtils.getPropertyValue(jpaExecutor, "expectSingleResult", Boolean.class));
    final LiteralExpression maxResultsExpression = TestUtils.getPropertyValue(jpaExecutor, "maxResultsExpression", LiteralExpression.class);
    assertNotNull(maxResultsExpression);
    assertEquals("55", TestUtils.getPropertyValue(maxResultsExpression, "literalValue"));
    assertTrue(TestUtils.getPropertyValue(jpaExecutor, "deleteAfterPoll", Boolean.class));
    assertTrue(TestUtils.getPropertyValue(jpaExecutor, "flush", Boolean.class));
}
Also used : AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) JpaOutboundGateway(org.springframework.integration.jpa.outbound.JpaOutboundGateway) OutboundGatewayType(org.springframework.integration.jpa.support.OutboundGatewayType) JpaOperations(org.springframework.integration.jpa.core.JpaOperations) LiteralExpression(org.springframework.expression.common.LiteralExpression) Test(org.junit.Test)

Example 14 with JpaExecutor

use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.

the class JpaOutboundGatewayParserTests method testUpdatingJpaOutboundGatewayParser.

@Test
public void testUpdatingJpaOutboundGatewayParser() throws Exception {
    setUp("JpaOutboundGatewayParserTests.xml", getClass(), "updatingJpaOutboundGateway");
    final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(this.consumer, "inputChannel", AbstractMessageChannel.class);
    assertEquals("in", inputChannel.getComponentName());
    final JpaOutboundGateway jpaOutboundGateway = TestUtils.getPropertyValue(this.consumer, "handler", JpaOutboundGateway.class);
    final OutboundGatewayType gatewayType = TestUtils.getPropertyValue(jpaOutboundGateway, "gatewayType", OutboundGatewayType.class);
    assertEquals(OutboundGatewayType.UPDATING, gatewayType);
    long sendTimeout = TestUtils.getPropertyValue(jpaOutboundGateway, "messagingTemplate.sendTimeout", Long.class);
    assertEquals(100, sendTimeout);
    assertFalse(TestUtils.getPropertyValue(jpaOutboundGateway, "requiresReply", Boolean.class));
    final JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.consumer, "handler.jpaExecutor", JpaExecutor.class);
    assertNotNull(jpaExecutor);
    final Class<?> entityClass = TestUtils.getPropertyValue(jpaExecutor, "entityClass", Class.class);
    assertEquals("org.springframework.integration.jpa.test.entity.StudentDomain", entityClass.getName());
    final JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class);
    assertNotNull(jpaOperations);
    final Boolean usePayloadAsParameterSource = TestUtils.getPropertyValue(jpaExecutor, "usePayloadAsParameterSource", Boolean.class);
    assertTrue(usePayloadAsParameterSource);
    final Integer order = TestUtils.getPropertyValue(jpaOutboundGateway, "order", Integer.class);
    assertEquals(Integer.valueOf(2), order);
    final PersistMode persistMode = TestUtils.getPropertyValue(jpaExecutor, "persistMode", PersistMode.class);
    assertEquals(PersistMode.PERSIST, persistMode);
    assertEquals(Integer.valueOf(100), TestUtils.getPropertyValue(jpaExecutor, "flushSize", Integer.class));
    assertTrue(TestUtils.getPropertyValue(jpaExecutor, "clearOnFlush", Boolean.class));
}
Also used : PersistMode(org.springframework.integration.jpa.support.PersistMode) AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) JpaOutboundGateway(org.springframework.integration.jpa.outbound.JpaOutboundGateway) OutboundGatewayType(org.springframework.integration.jpa.support.OutboundGatewayType) JpaOperations(org.springframework.integration.jpa.core.JpaOperations) Test(org.junit.Test)

Example 15 with JpaExecutor

use of org.springframework.integration.jpa.core.JpaExecutor in project spring-integration by spring-projects.

the class JpaPollingChannelAdapterTests method testWithJpaQueryAndDelete.

/**
 * In this test, a Jpa Polling Channel Adapter will use JpQL query
 * to retrieve a list of records from the database. Additionally, the records
 * will be deleted after the polling.
 *
 * @throws Exception
 */
@Test
@DirtiesContext
public void testWithJpaQueryAndDelete() throws Exception {
    testTrigger.reset();
    // ~~~~SETUP~~~~~
    final JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
    jpaExecutor.setJpaQuery("from Student s");
    jpaExecutor.setDeleteAfterPoll(true);
    jpaExecutor.setDeleteInBatch(true);
    jpaExecutor.setFlush(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();
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    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 is null.", message);
    assertNotNull(message.getPayload());
    Collection<?> students = message.getPayload();
    assertTrue(students.size() == 3);
    Long studentCount = waitForDeletes(students);
    assertEquals(Long.valueOf(0), studentCount);
}
Also used : 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) 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