use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class JpaOutboundChannelAdapterTests method saveEntityWithMergeWithoutSpecifyingEntityClass.
@Test
public void saveEntityWithMergeWithoutSpecifyingEntityClass() throws InterruptedException {
List<?> results1 = this.jdbcTemplate.queryForList("Select * from Student");
Assert.assertNotNull(results1);
Assert.assertTrue(results1.size() == 3);
JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
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 testFindByPayloadType.
@Test
public void testFindByPayloadType() throws Exception {
this.handler = message -> {
assertThat(message.getPayload(), Matchers.instanceOf(StudentDomain.class));
StudentDomain student = (StudentDomain) message.getPayload();
assertEquals("First Two", student.getFirstName());
};
this.responseChannel.subscribe(this.handler);
StudentDomain payload = new StudentDomain();
payload.setRollNumber(1002L);
Message<StudentDomain> message = MessageBuilder.withPayload(payload).build();
this.findByPayloadTypeChannel.send(message);
}
use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class AbstractJpaOperationsTests method testExecuteUpdateWithNamedQuery.
public void testExecuteUpdateWithNamedQuery() {
final JpaOperations jpaOperations = getJpaOperations(entityManager);
final StudentDomain student = JpaTestUtils.getTestStudent();
ParameterSourceFactory requestParameterSourceFactory = new ExpressionEvaluatingParameterSourceFactory(mock(BeanFactory.class));
ParameterSource source = requestParameterSourceFactory.createParameterSource(student);
int updatedRecords = jpaOperations.executeUpdateWithNamedQuery("updateStudent", source);
entityManager.flush();
Assert.assertTrue(1 == updatedRecords);
Assert.assertNull(student.getRollNumber());
}
use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class AbstractJpaOperationsTests method testMergeCollection.
public void testMergeCollection() {
final JpaOperations jpaOperations = getJpaOperations(entityManager);
final StudentDomain student1 = JpaTestUtils.getTestStudent();
final StudentDomain student2 = JpaTestUtils.getTestStudent();
final StudentDomain student3 = JpaTestUtils.getTestStudent();
student1.setFirstName("Karl");
student2.setFirstName("Otto");
student3.setFirstName("Wilhelm");
List<StudentDomain> students = new ArrayList<StudentDomain>(3);
students.add(student1);
students.add(student2);
students.add(student3);
Assert.assertNull(student1.getRollNumber());
Assert.assertNull(student2.getRollNumber());
Assert.assertNull(student3.getRollNumber());
Object savedStudents = jpaOperations.merge(students, 10, true);
Assert.assertTrue(savedStudents instanceof List<?>);
@SuppressWarnings("unchecked") List<StudentDomain> savedStudentCollection = (List<StudentDomain>) savedStudents;
Assert.assertNotNull(savedStudentCollection.get(0).getRollNumber());
Assert.assertNotNull(savedStudentCollection.get(1).getRollNumber());
Assert.assertNotNull(savedStudentCollection.get(2).getRollNumber());
}
use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class AbstractJpaOperationsTests method testExecuteUpdateWithNativeQuery.
public void testExecuteUpdateWithNativeQuery() {
final JpaOperations jpaOperations = getJpaOperations(entityManager);
final StudentDomain student = JpaTestUtils.getTestStudent();
ExpressionEvaluatingParameterSourceFactory requestParameterSourceFactory = new ExpressionEvaluatingParameterSourceFactory(mock(BeanFactory.class));
ParameterSource source = requestParameterSourceFactory.createParameterSource(student);
int updatedRecords = jpaOperations.executeUpdateWithNativeQuery("update Student " + "set lastName = :lastName, lastUpdated = :lastUpdated " + "where rollNumber in (select max(a.rollNumber) from Student a)", source);
entityManager.flush();
Assert.assertTrue(1 == updatedRecords);
Assert.assertNull(student.getRollNumber());
}
Aggregations