use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class AbstractJpaOperationsTests method testDeleteInBatchWithEmptyCollection.
public void testDeleteInBatchWithEmptyCollection() {
final JpaOperations jpaOperations = getJpaOperations(entityManager);
final List<?> students = jpaOperations.getResultListForClass(StudentDomain.class, 0, 0);
Assert.assertNotNull(students);
Assert.assertTrue(students.size() == 3);
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
// explicitly setting the transaction name is something that can only be done programmatically
def.setName("SomeOtherTxName");
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = transactionManager.getTransaction(def);
jpaOperations.deleteInBatch(new ArrayList<StudentDomain>(0));
entityManager.flush();
transactionManager.commit(status);
final List<?> studentsFromDb = jpaOperations.getResultListForClass(StudentDomain.class, 0, 0);
Assert.assertNotNull(studentsFromDb);
// Nothing should have happened
Assert.assertTrue(studentsFromDb.size() == 3);
}
use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class AbstractJpaOperationsTests method testMerge.
/**
* Test method for {@link org.springframework.integration.jpa.core.DefaultJpaOperations#merge(java.lang.Object)}.
*/
public void testMerge() {
final JpaOperations jpaOperations = getJpaOperations(entityManager);
final StudentDomain student = JpaTestUtils.getTestStudent();
Assert.assertNull(student.getRollNumber());
final StudentDomain savedStudent = (StudentDomain) jpaOperations.merge(student);
entityManager.flush();
Assert.assertNull(student.getRollNumber());
Assert.assertNotNull(savedStudent);
Assert.assertNotNull(savedStudent.getRollNumber());
Assert.assertTrue(student != savedStudent);
}
use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class AbstractJpaOperationsTests method testDelete.
public void testDelete() {
final JpaOperations jpaOperations = getJpaOperations(entityManager);
final List<?> studentsFromDb = jpaOperations.getResultListForClass(StudentDomain.class, 0, 0);
Assert.assertNotNull(studentsFromDb);
Assert.assertTrue(studentsFromDb.size() == 3);
final StudentDomain student = jpaOperations.find(StudentDomain.class, 1001L);
Assert.assertNotNull(student);
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
// explicitly setting the transaction name is something that can only be done programmatically
def.setName("SomeOtherTxName");
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = transactionManager.getTransaction(def);
jpaOperations.delete(student);
entityManager.flush();
transactionManager.commit(status);
final List<?> studentsFromDbAfterDelete = jpaOperations.getResultListForClass(StudentDomain.class, 0, 0);
Assert.assertNotNull(studentsFromDbAfterDelete);
Assert.assertTrue(studentsFromDbAfterDelete.size() == 2);
}
use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class JpaTests method testUpdatingGatewayFlow.
@Test
public void testUpdatingGatewayFlow() {
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.updatingGatewayFlowInput.send(MessageBuilder.withPayload(student).build());
Message<?> receive = this.persistResults.receive(10_000);
assertNotNull(receive);
StudentDomain mergedStudent = (StudentDomain) receive.getPayload();
assertEquals(student.getFirstName(), mergedStudent.getFirstName());
assertNotNull(mergedStudent.getRollNumber());
assertNull(student.getRollNumber());
}
use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class JpaOutboundGatewayTests method persistStudentUsingMerge.
@Test
@Transactional
public void persistStudentUsingMerge() {
final StudentDomain studentToPersist = JpaTestUtils.getTestStudent();
Assert.assertNull(studentToPersist.getRollNumber());
final StudentDomain persistedStudent = studentService.persistStudentUsingMerge(studentToPersist);
Assert.assertNotNull(persistedStudent);
Assert.assertNotNull(persistedStudent.getRollNumber());
}
Aggregations