Search in sources :

Example 6 with StudentDomain

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);
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain) TransactionStatus(org.springframework.transaction.TransactionStatus)

Example 7 with StudentDomain

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);
}
Also used : StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain)

Example 8 with StudentDomain

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);
}
Also used : StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) TransactionStatus(org.springframework.transaction.TransactionStatus)

Example 9 with StudentDomain

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());
}
Also used : StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain) Calendar(java.util.Calendar) Date(java.util.Date) Test(org.junit.Test)

Example 10 with StudentDomain

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