Search in sources :

Example 21 with StudentDomain

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

the class JpaTests method testRetrievingGatewayFlow.

@Test
public void testRetrievingGatewayFlow() {
    this.retrievingGatewayFlowInput.send(MessageBuilder.withPayload(1002L).build());
    Message<?> receive = this.retrieveResults.receive(10_000);
    assertNotNull(receive);
    assertThat(receive.getPayload(), instanceOf(StudentDomain.class));
    StudentDomain student = (StudentDomain) receive.getPayload();
    assertEquals("First Two", student.getFirstName());
    assertEquals(Gender.FEMALE, student.getGender());
}
Also used : StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain) Test(org.junit.Test)

Example 22 with StudentDomain

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

the class JpaTests method testInboundAdapterFlow.

@Test
public void testInboundAdapterFlow() {
    Message<?> message = this.pollingResults.receive(10_000);
    assertNotNull(message);
    assertThat(message.getPayload(), instanceOf(StudentDomain.class));
    StudentDomain student = (StudentDomain) message.getPayload();
    assertEquals("First One", student.getFirstName());
}
Also used : StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain) Test(org.junit.Test)

Example 23 with StudentDomain

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

the class JpaTests method testOutboundAdapterFlow.

@Test
public void testOutboundAdapterFlow() {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    List<?> results1 = jdbcTemplate.queryForList("Select * from Student");
    assertNotNull(results1);
    assertTrue(results1.size() == 3);
    Calendar dateOfBirth = Calendar.getInstance();
    dateOfBirth.set(1981, 9, 27);
    StudentDomain student = new StudentDomain().withFirstName("Artem").withLastName("Bilan").withGender(Gender.MALE).withDateOfBirth(dateOfBirth.getTime()).withLastUpdated(new Date());
    assertNull(student.getRollNumber());
    this.outboundAdapterFlowInput.send(MessageBuilder.withPayload(student).build());
    List<?> results2 = jdbcTemplate.queryForList("Select * from Student");
    assertNotNull(results2);
    assertTrue(results2.size() == 4);
    assertNotNull(student.getRollNumber());
}
Also used : StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain) Calendar(java.util.Calendar) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Date(java.util.Date) Test(org.junit.Test)

Example 24 with StudentDomain

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

the class JpaOutboundChannelAdapterTransactionalTests method saveEntityWithTransaction.

@Test
@DirtiesContext
public void saveEntityWithTransaction() throws InterruptedException {
    List<?> results1 = new JdbcTemplate(dataSource).queryForList("Select * from Student");
    Assert.assertNotNull(results1);
    Assert.assertTrue(results1.size() == 3);
    StudentDomain testStudent = JpaTestUtils.getTestStudent();
    Message<StudentDomain> message = MessageBuilder.withPayload(testStudent).build();
    channel.send(message);
    List<?> results2 = new JdbcTemplate(dataSource).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) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 25 with StudentDomain

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

the class JpaOutboundGatewayTests method persistStudent.

@Test
@Transactional
public void persistStudent() {
    final StudentDomain studentToPersist = JpaTestUtils.getTestStudent();
    Assert.assertNull(studentToPersist.getRollNumber());
    final StudentDomain persistedStudent = studentService.persistStudent(studentToPersist);
    Assert.assertNotNull(persistedStudent);
    Assert.assertNotNull(persistedStudent.getRollNumber());
}
Also used : StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

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