Skip to content

Commit c91cbac

Browse files
committed
Rework the tests and fix a JDK 11 issue
1 parent f14329f commit c91cbac

11 files changed

+65
-73
lines changed

src/test/java/examples/springbatch/NoPersistenceBatchConfigurer.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/test/java/examples/springbatch/Person.java renamed to src/test/java/examples/springbatch/common/Person.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package examples.springbatch;
16+
package examples.springbatch.common;
1717

1818
public class Person {
1919
private Integer id;

src/test/java/examples/springbatch/PersonProcessor.java renamed to src/test/java/examples/springbatch/common/PersonProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package examples.springbatch;
16+
package examples.springbatch.common;
1717

1818
import org.springframework.batch.core.StepExecution;
1919
import org.springframework.batch.core.annotation.BeforeChunk;

src/test/java/examples/springbatch/UpdateStatementConvertor.java renamed to src/test/java/examples/springbatch/common/UpdateStatementConvertor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package examples.springbatch;
16+
package examples.springbatch.common;
1717

18-
import static examples.springbatch.PersonDynamicSqlSupport.*;
18+
import static examples.springbatch.mapper.PersonDynamicSqlSupport.*;
1919
import static org.mybatis.dynamic.sql.SqlBuilder.*;
2020

2121
import org.mybatis.dynamic.sql.render.RenderingStrategy;

src/test/java/examples/springbatch/CursorReaderBatchConfiguration.java renamed to src/test/java/examples/springbatch/cursor/CursorReaderBatchConfiguration.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package examples.springbatch;
16+
package examples.springbatch.cursor;
1717

18-
import static examples.springbatch.PersonDynamicSqlSupport.*;
19-
import static org.mybatis.dynamic.sql.SqlBuilder.*;
18+
import static examples.springbatch.mapper.PersonDynamicSqlSupport.lastName;
19+
import static examples.springbatch.mapper.PersonDynamicSqlSupport.person;
20+
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
2021

2122
import javax.sql.DataSource;
2223

@@ -37,19 +38,23 @@
3738
import org.springframework.batch.item.ItemProcessor;
3839
import org.springframework.batch.item.ItemReader;
3940
import org.springframework.batch.item.ItemWriter;
40-
import org.springframework.batch.test.JobLauncherTestUtils;
4141
import org.springframework.beans.factory.annotation.Autowired;
4242
import org.springframework.context.annotation.Bean;
4343
import org.springframework.context.annotation.ComponentScan;
4444
import org.springframework.context.annotation.Configuration;
4545
import org.springframework.core.convert.converter.Converter;
46+
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
4647
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
4748
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
49+
import org.springframework.transaction.PlatformTransactionManager;
50+
51+
import examples.springbatch.common.Person;
52+
import examples.springbatch.mapper.PersonMapper;
4853

4954
@EnableBatchProcessing
5055
@Configuration
51-
@ComponentScan("examples.springbatch")
52-
@MapperScan("examples.springbatch")
56+
@ComponentScan("examples.springbatch.common")
57+
@MapperScan("examples.springbatch.mapper")
5358
public class CursorReaderBatchConfiguration {
5459

5560
@Autowired
@@ -62,23 +67,25 @@ public class CursorReaderBatchConfiguration {
6267
public DataSource dataSource() {
6368
return new EmbeddedDatabaseBuilder()
6469
.setType(EmbeddedDatabaseType.HSQL)
70+
.addScript("classpath:/org/springframework/batch/core/schema-drop-hsqldb.sql")
71+
.addScript("classpath:/org/springframework/batch/core/schema-hsqldb.sql")
6572
.addScript("classpath:/examples/springbatch/schema.sql")
6673
.addScript("classpath:/examples/springbatch/data.sql")
6774
.build();
6875
}
6976

7077
@Bean
71-
public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) {
72-
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
73-
bean.setDataSource(dataSource);
74-
return bean;
78+
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
79+
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
80+
sessionFactory.setDataSource(dataSource);
81+
return sessionFactory.getObject();
7582
}
76-
83+
7784
@Bean
78-
public JobLauncherTestUtils jobLauncherTestUtils() {
79-
return new JobLauncherTestUtils();
85+
public PlatformTransactionManager dtm(DataSource dataSource) {
86+
return new DataSourceTransactionManager(dataSource);
8087
}
81-
88+
8289
@Bean
8390
public MyBatisCursorItemReader<Person> reader(SqlSessionFactory sqlSessionFactory) {
8491
SelectStatementProvider selectStatement = SpringBatchUtility.selectForCursor(person.allColumns())

src/test/java/examples/springbatch/SpringBatchCursorTest.java renamed to src/test/java/examples/springbatch/cursor/SpringBatchCursorTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,37 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package examples.springbatch;
16+
package examples.springbatch.cursor;
1717

1818
import static org.mybatis.dynamic.sql.SqlBuilder.*;
19-
20-
import static examples.springbatch.PersonDynamicSqlSupport.*;
19+
import static examples.springbatch.mapper.PersonDynamicSqlSupport.*;
2120
import static org.assertj.core.api.Assertions.assertThat;
2221

2322
import org.apache.ibatis.session.SqlSession;
23+
import org.apache.ibatis.session.SqlSessionFactory;
2424
import org.junit.jupiter.api.Test;
2525
import org.mybatis.dynamic.sql.render.RenderingStrategy;
2626
import org.mybatis.dynamic.sql.select.SelectDSL;
2727
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
28-
import org.mybatis.spring.SqlSessionFactoryBean;
2928
import org.springframework.batch.core.ExitStatus;
3029
import org.springframework.batch.core.JobExecution;
3130
import org.springframework.batch.core.StepExecution;
3231
import org.springframework.batch.test.JobLauncherTestUtils;
32+
import org.springframework.batch.test.context.SpringBatchTest;
3333
import org.springframework.beans.factory.annotation.Autowired;
3434
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3535

36+
import examples.springbatch.mapper.PersonMapper;
37+
38+
@SpringBatchTest
3639
@SpringJUnitConfig(classes=CursorReaderBatchConfiguration.class)
3740
public class SpringBatchCursorTest {
3841

3942
@Autowired
4043
private JobLauncherTestUtils jobLauncherTestUtils;
4144

4245
@Autowired
43-
private SqlSessionFactoryBean sqlSessionFactory;
46+
private SqlSessionFactory sqlSessionFactory;
4447

4548
@Test
4649
public void testThatRowsAreTransformedToUpperCase() throws Exception {
@@ -63,7 +66,7 @@ private int numberOfRowsProcessed(JobExecution jobExecution) {
6366
}
6467

6568
private long upperCaseRowCount() throws Exception {
66-
try (SqlSession sqlSession = sqlSessionFactory.getObject().openSession()) {
69+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
6770
PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);
6871

6972
SelectStatementProvider selectStatement = SelectDSL.select(count())

src/test/java/examples/springbatch/PersonDynamicSqlSupport.java renamed to src/test/java/examples/springbatch/mapper/PersonDynamicSqlSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package examples.springbatch;
16+
package examples.springbatch.mapper;
1717

1818
import java.sql.JDBCType;
1919

src/test/java/examples/springbatch/PersonMapper.java renamed to src/test/java/examples/springbatch/mapper/PersonMapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package examples.springbatch;
16+
package examples.springbatch.mapper;
1717

1818
import java.util.List;
1919
import java.util.Map;
@@ -28,6 +28,8 @@
2828
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
2929
import org.mybatis.dynamic.sql.util.springbatch.SpringBatchProviderAdapter;
3030

31+
import examples.springbatch.common.Person;
32+
3133
@Mapper
3234
public interface PersonMapper {
3335

src/test/java/examples/springbatch/PagingReaderBatchConfiguration.java renamed to src/test/java/examples/springbatch/paging/PagingReaderBatchConfiguration.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package examples.springbatch;
16+
package examples.springbatch.paging;
1717

18-
import static examples.springbatch.PersonDynamicSqlSupport.*;
18+
import static examples.springbatch.mapper.PersonDynamicSqlSupport.*;
1919
import static org.mybatis.dynamic.sql.SqlBuilder.*;
2020

2121
import javax.sql.DataSource;
@@ -37,19 +37,22 @@
3737
import org.springframework.batch.item.ItemProcessor;
3838
import org.springframework.batch.item.ItemReader;
3939
import org.springframework.batch.item.ItemWriter;
40-
import org.springframework.batch.test.JobLauncherTestUtils;
4140
import org.springframework.beans.factory.annotation.Autowired;
4241
import org.springframework.context.annotation.Bean;
4342
import org.springframework.context.annotation.ComponentScan;
4443
import org.springframework.context.annotation.Configuration;
4544
import org.springframework.core.convert.converter.Converter;
45+
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
4646
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
4747
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
4848

49+
import examples.springbatch.common.Person;
50+
import examples.springbatch.mapper.PersonMapper;
51+
4952
@EnableBatchProcessing
5053
@Configuration
51-
@ComponentScan("examples.springbatch")
52-
@MapperScan("examples.springbatch")
54+
@ComponentScan("examples.springbatch.common")
55+
@MapperScan("examples.springbatch.mapper")
5356
public class PagingReaderBatchConfiguration {
5457

5558
@Autowired
@@ -62,23 +65,25 @@ public class PagingReaderBatchConfiguration {
6265
public DataSource dataSource() {
6366
return new EmbeddedDatabaseBuilder()
6467
.setType(EmbeddedDatabaseType.HSQL)
68+
.addScript("classpath:/org/springframework/batch/core/schema-drop-hsqldb.sql")
69+
.addScript("classpath:/org/springframework/batch/core/schema-hsqldb.sql")
6570
.addScript("classpath:/examples/springbatch/schema.sql")
6671
.addScript("classpath:/examples/springbatch/data.sql")
6772
.build();
6873
}
6974

7075
@Bean
71-
public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) {
72-
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
73-
bean.setDataSource(dataSource);
74-
return bean;
76+
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
77+
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
78+
sessionFactory.setDataSource(dataSource);
79+
return sessionFactory.getObject();
7580
}
7681

7782
@Bean
78-
public JobLauncherTestUtils jobLauncherTestUtils() {
79-
return new JobLauncherTestUtils();
83+
public DataSourceTransactionManager dtm(DataSource dataSource) {
84+
return new DataSourceTransactionManager(dataSource);
8085
}
81-
86+
8287
@Bean
8388
public MyBatisPagingItemReader<Person> reader(SqlSessionFactory sqlSessionFactory) {
8489
SelectStatementProvider selectStatement = SpringBatchUtility.selectForPaging(person.allColumns())

src/test/java/examples/springbatch/SpringBatchPagingTest.java renamed to src/test/java/examples/springbatch/paging/SpringBatchPagingTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,37 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package examples.springbatch;
16+
package examples.springbatch.paging;
1717

1818
import static org.mybatis.dynamic.sql.SqlBuilder.*;
19-
20-
import static examples.springbatch.PersonDynamicSqlSupport.*;
19+
import static examples.springbatch.mapper.PersonDynamicSqlSupport.*;
2120
import static org.assertj.core.api.Assertions.assertThat;
2221

2322
import org.apache.ibatis.session.SqlSession;
23+
import org.apache.ibatis.session.SqlSessionFactory;
2424
import org.junit.jupiter.api.Test;
2525
import org.mybatis.dynamic.sql.render.RenderingStrategy;
2626
import org.mybatis.dynamic.sql.select.SelectDSL;
2727
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
28-
import org.mybatis.spring.SqlSessionFactoryBean;
2928
import org.springframework.batch.core.ExitStatus;
3029
import org.springframework.batch.core.JobExecution;
3130
import org.springframework.batch.core.StepExecution;
3231
import org.springframework.batch.test.JobLauncherTestUtils;
32+
import org.springframework.batch.test.context.SpringBatchTest;
3333
import org.springframework.beans.factory.annotation.Autowired;
3434
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3535

36+
import examples.springbatch.mapper.PersonMapper;
37+
38+
@SpringBatchTest
3639
@SpringJUnitConfig(classes=PagingReaderBatchConfiguration.class)
3740
public class SpringBatchPagingTest {
3841

3942
@Autowired
4043
private JobLauncherTestUtils jobLauncherTestUtils;
4144

4245
@Autowired
43-
private SqlSessionFactoryBean sqlSessionFactory;
46+
private SqlSessionFactory sqlSessionFactory;
4447

4548
@Test
4649
public void testThatRowsAreTransformedToUpperCase() throws Exception {
@@ -71,7 +74,7 @@ private int numberOfChunks(JobExecution jobExecution) {
7174
}
7275

7376
private long upperCaseRowCount() throws Exception {
74-
try (SqlSession sqlSession = sqlSessionFactory.getObject().openSession()) {
77+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
7578
PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);
7679

7780
SelectStatementProvider selectStatement = SelectDSL.select(count())

src/test/resources/logback.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<configuration>
2121
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
2222
<encoder>
23-
<pattern>%d [acct] %-5level %logger{36} - %msg%n</pattern>
23+
<pattern>%d %-5level %logger{36} - %msg%n</pattern>
2424
</encoder>
2525
</appender>
2626

0 commit comments

Comments
 (0)