BATCH-354: removed Spring transaction management and replaced with programmatic transactions for the JpaPagingItemReader, added integration tests
This commit is contained in:
@@ -7,7 +7,6 @@ import org.springframework.batch.item.CommonItemStreamItemReaderTests;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -43,32 +42,32 @@ public class JpaPagingItemReaderCommonTests extends CommonItemStreamItemReaderTe
|
||||
}
|
||||
|
||||
|
||||
@Transactional @Test
|
||||
@Test
|
||||
public void testRestart() throws Exception {
|
||||
super.testRestart();
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
@Test
|
||||
public void testResetAndRestart() throws Exception {
|
||||
super.testResetAndRestart();
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
@Test
|
||||
public void testReopen() throws Exception {
|
||||
super.testReopen();
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
@Test
|
||||
public void testRead() throws Exception {
|
||||
super.testRead();
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
@Test
|
||||
public void testReset() throws Exception {
|
||||
super.testReset();
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
@Test
|
||||
public void testEmptyInput() throws Exception {
|
||||
super.testEmptyInput();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.springframework.batch.item.database;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
|
||||
/**
|
||||
* Tests for {@link org.springframework.batch.item.database.JpaPagingItemReader}.
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "data-source-context.xml")
|
||||
public class JpaPagingItemReaderIntegrationTests extends AbstractDataSourceItemReaderIntegrationTests {
|
||||
|
||||
protected ItemReader<Foo> createItemReader() throws Exception {
|
||||
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
|
||||
factoryBean.setDataSource(dataSource);
|
||||
factoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
|
||||
factoryBean.setPersistenceUnitName("bar");
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
EntityManagerFactory entityManagerFactory = factoryBean.getObject();
|
||||
|
||||
String jpqlQuery = "select f from Foo f";
|
||||
|
||||
JpaPagingItemReader<Foo> inputSource = new JpaPagingItemReader<Foo>();
|
||||
inputSource.setQueryString(jpqlQuery);
|
||||
inputSource.setEntityManagerFactory(entityManagerFactory);
|
||||
inputSource.afterPropertiesSet();
|
||||
inputSource.setSaveState(true);
|
||||
|
||||
return inputSource;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user