use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class JpaPollingChannelAdapterTests method testWithJpaQueryOneResultOnly.
/**
* In this test, a Jpa Polling Channel Adapter will use JpQL query
* to retrieve a list of records from the database.
*
* @throws Exception
*/
@Test
public void testWithJpaQueryOneResultOnly() throws Exception {
testTrigger.reset();
// ~~~~SETUP~~~~~
final JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
jpaExecutor.setJpaQuery("from Student s where s.firstName = 'First Two'");
jpaExecutor.afterPropertiesSet();
final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor);
final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter(jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader());
adapter.start();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
final List<Message<Collection<?>>> received = new ArrayList<Message<Collection<?>>>();
final Consumer consumer = new Consumer();
received.add(consumer.poll(10000));
Message<Collection<?>> message = received.get(0);
adapter.stop();
assertNotNull(message);
assertNotNull(message.getPayload());
Collection<?> students = message.getPayload();
assertTrue(students.size() == 1);
StudentDomain student = (StudentDomain) students.iterator().next();
assertEquals("Last Two", student.getLastName());
}
use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class JpaExecutorTests method selectWithMessageAsParameterSource.
@Test
@Transactional
public void selectWithMessageAsParameterSource() {
String query = "select s from Student s where s.firstName = :firstName";
Message<Map<String, String>> message = MessageBuilder.withPayload(Collections.singletonMap("firstName", "First One")).build();
JpaExecutor executor = getJpaExecutorForMessageAsParamSource(query);
StudentDomain student = (StudentDomain) executor.poll(message);
Assert.assertNotNull(student);
}
use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class JpaExecutorTests method selectWithPayloadAsParameterSource.
@Test
@Transactional
public void selectWithPayloadAsParameterSource() {
String query = "select s from Student s where s.firstName = :firstName";
Message<String> message = MessageBuilder.withPayload("First One").build();
JpaExecutor executor = getJpaExecutorForPayloadAsParamSource(query);
StudentDomain student = (StudentDomain) executor.poll(message);
Assert.assertNotNull(student);
}
use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class AbstractJpaOperationsTests method testPersist.
/**
* Test method for {@link org.springframework.integration.jpa.core.DefaultJpaOperations#persist(java.lang.Object)}.
*/
public void testPersist() {
final JpaOperations jpaOperations = getJpaOperations(entityManager);
final StudentDomain student = JpaTestUtils.getTestStudent();
Assert.assertNull(student.getRollNumber());
jpaOperations.persist(student, 1, false);
Assert.assertNotNull(student.getRollNumber());
assertTrue(entityManager.contains(student));
}
use of org.springframework.integration.jpa.test.entity.StudentDomain in project spring-integration by spring-projects.
the class AbstractJpaOperationsTests method testPersistCollection.
public void testPersistCollection() {
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());
jpaOperations.persist(students, 1, true);
Assert.assertNotNull(student1.getRollNumber());
Assert.assertNotNull(student2.getRollNumber());
Assert.assertNotNull(student3.getRollNumber());
assertFalse(entityManager.contains(student1));
assertFalse(entityManager.contains(student2));
assertFalse(entityManager.contains(student3));
}
Aggregations