use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class AbstractJpaOperationsTests method testExecuteSelectWithNativeQueryReturningEntityClass.
public void testExecuteSelectWithNativeQueryReturningEntityClass() throws ParseException {
final JpaOperations jpaOperations = getJpaOperations(entityManager);
String selectSqlQuery = "select * from Student where lastName = 'Last One'";
Class<?> entityClass = StudentDomain.class;
List<?> students = jpaOperations.getResultListForNativeQuery(selectSqlQuery, entityClass, null, 0, 0);
Assert.assertTrue(students.size() == 1);
StudentDomain retrievedStudent = (StudentDomain) students.iterator().next();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
assertEquals(formatter.parse("1980/01/01"), retrievedStudent.getDateOfBirth());
assertEquals("First One", retrievedStudent.getFirstName());
assertEquals(Gender.MALE, retrievedStudent.getGender());
assertEquals("Last One", retrievedStudent.getLastName());
assertNotNull(retrievedStudent.getLastUpdated());
}
use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class AbstractJpaOperationsTests method testPersistCollectionWithNullElement.
public void testPersistCollectionWithNullElement() {
final JpaOperations jpaOperations = getJpaOperations(entityManager);
final List<?> studentsFromDbBeforeTest = jpaOperations.getResultListForClass(StudentDomain.class, 0, 0);
Assert.assertEquals(3, studentsFromDbBeforeTest.size());
final StudentDomain student1 = JpaTestUtils.getTestStudent();
final StudentDomain student2 = null;
final StudentDomain student3 = JpaTestUtils.getTestStudent();
student1.setFirstName("Karl");
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);
Assert.assertNull(student3.getRollNumber());
jpaOperations.persist(students, 10, false);
Assert.assertNotNull(student1.getRollNumber());
Assert.assertNotNull(student3.getRollNumber());
final List<?> studentsFromDb = jpaOperations.getResultListForClass(StudentDomain.class, 0, 0);
Assert.assertNotNull(studentsFromDb);
Assert.assertEquals(5, studentsFromDb.size());
}
use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class AbstractJpaOperationsTests method testMergeCollectionWithNullElement.
public void testMergeCollectionWithNullElement() {
final JpaOperations jpaOperations = getJpaOperations(entityManager);
final List<?> studentsFromDbBeforeTest = jpaOperations.getResultListForClass(StudentDomain.class, 0, 0);
Assert.assertEquals(3, studentsFromDbBeforeTest.size());
final StudentDomain student1 = JpaTestUtils.getTestStudent();
final StudentDomain student2 = null;
final StudentDomain student3 = JpaTestUtils.getTestStudent();
student1.setFirstName("Karl");
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);
Assert.assertNull(student3.getRollNumber());
Object savedStudents = jpaOperations.merge(students);
entityManager.flush();
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());
}
use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class AbstractJpaOperationsTests method testExecuteUpdateWithNativeNamedQuery.
public void testExecuteUpdateWithNativeNamedQuery() {
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("updateStudentNativeQuery", 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 testExecuteUpdate.
public void testExecuteUpdate() {
final JpaOperations jpaOperations = getJpaOperations(entityManager);
final StudentDomain student = JpaTestUtils.getTestStudent();
List<?> students = jpaOperations.getResultListForClass(StudentDomain.class, 0, 0);
Assert.assertTrue(students.size() == 3);
ParameterSourceFactory requestParameterSourceFactory = new ExpressionEvaluatingParameterSourceFactory(mock(BeanFactory.class));
ParameterSource source = requestParameterSourceFactory.createParameterSource(student);
int updatedRecords = jpaOperations.executeUpdate("update Student s " + "set s.lastName = :lastName, s.lastUpdated = :lastUpdated " + "where s.rollNumber in (select max(a.rollNumber) from Student a)", source);
entityManager.flush();
Assert.assertTrue(1 == updatedRecords);
Assert.assertNull(student.getRollNumber());
}
Aggregations