Search in sources :

Example 31 with StudentDomain

use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.

the class JpaOutboundChannelAdapterTests method saveEntityWithPersistWithinChain.

// INT-2557
@Test
public void saveEntityWithPersistWithinChain() throws InterruptedException {
    List<?> results1 = this.jdbcTemplate.queryForList("Select * from Student");
    Assert.assertNotNull(results1);
    Assert.assertTrue(results1.size() == 3);
    StudentDomain testStudent = JpaTestUtils.getTestStudent();
    Assert.assertNull(testStudent.getRollNumber());
    this.jpaOutboundChannelAdapterWithinChain.send(MessageBuilder.withPayload(testStudent).build());
    List<?> results2 = this.jdbcTemplate.queryForList("Select * from Student");
    Assert.assertNotNull(results2);
    Assert.assertTrue(results2.size() == 4);
    Assert.assertNotNull(testStudent.getRollNumber());
}
Also used : StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain) Test(org.junit.Test)

Example 32 with StudentDomain

use of org.springframework.integration.jpa.test.entity.StudentDomain 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());
}
Also used : StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain) JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) BeanFactory(org.springframework.beans.factory.BeanFactory) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test)

Example 33 with StudentDomain

use of org.springframework.integration.jpa.test.entity.StudentDomain 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());
}
Also used : StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain) JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) BeanFactory(org.springframework.beans.factory.BeanFactory) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test)

Example 34 with StudentDomain

use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.

the class JpaOutboundGatewayIntegrationTests method testFindByEntityClass.

@Test
public void testFindByEntityClass() throws Exception {
    this.handler = message -> {
        assertThat(message.getPayload(), Matchers.instanceOf(StudentDomain.class));
        StudentDomain student = (StudentDomain) message.getPayload();
        assertEquals("First One", student.getFirstName());
    };
    this.responseChannel.subscribe(this.handler);
    Message<Long> message = MessageBuilder.withPayload(1001L).build();
    this.findByEntityClassChannel.send(message);
}
Also used : StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain) Test(org.junit.Test)

Example 35 with StudentDomain

use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.

the class JpaTestUtils method getTestStudent.

public static StudentDomain getTestStudent() {
    Calendar dateOfBirth = Calendar.getInstance();
    dateOfBirth.set(1984, 0, 31);
    StudentDomain student = new StudentDomain().withFirstName("First Executor").withLastName("Last Executor").withGender(Gender.MALE).withDateOfBirth(dateOfBirth.getTime()).withLastUpdated(new Date());
    return student;
}
Also used : StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain) Calendar(java.util.Calendar) Date(java.util.Date)

Aggregations

StudentDomain (org.springframework.integration.jpa.test.entity.StudentDomain)35 Test (org.junit.Test)21 BeanFactory (org.springframework.beans.factory.BeanFactory)7 ArrayList (java.util.ArrayList)5 TransactionStatus (org.springframework.transaction.TransactionStatus)5 Transactional (org.springframework.transaction.annotation.Transactional)5 JpaExecutor (org.springframework.integration.jpa.core.JpaExecutor)4 ExpressionEvaluatingParameterSourceFactory (org.springframework.integration.jpa.support.parametersource.ExpressionEvaluatingParameterSourceFactory)4 ParameterSource (org.springframework.integration.jpa.support.parametersource.ParameterSource)4 Calendar (java.util.Calendar)3 Date (java.util.Date)3 ParameterSourceFactory (org.springframework.integration.jpa.support.parametersource.ParameterSourceFactory)3 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)3 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)3 List (java.util.List)2 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)2 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1 Map (java.util.Map)1