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());
}
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());
}
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());
}
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);
}
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;
}
Aggregations