Skip to content

Commit 0ae44c8

Browse files
fmbenhassinePhilippe Truche
authored and
Philippe Truche
committed
Add integration tests for all supported databases
Resolves spring-projects#3092
1 parent c8dbe41 commit 0ae44c8

12 files changed

+1103
-0
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@
101101
<woodstox-core.version>6.2.5</woodstox-core.version>
102102
<aspectj.version>1.9.6</aspectj.version>
103103
<mysql-connector-java.version>8.0.23</mysql-connector-java.version>
104+
<postgresql.version>42.2.22</postgresql.version>
105+
<db2.version>11.5.6.0</db2.version>
106+
<oracle.version>21.1.0.0</oracle.version>
107+
<sqlserver.version>9.2.1.jre8</sqlserver.version>
108+
<jtds.version>1.3.1</jtds.version>
104109
<testcontainers.version>1.15.3</testcontainers.version>
105110
<com.ibm.jbatch-tck-spi.version>1.0</com.ibm.jbatch-tck-spi.version>
106111
<javax.inject.version>1</javax.inject.version>

spring-batch-core/pom.xml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,66 @@
112112
<version>${testcontainers.version}</version>
113113
<scope>test</scope>
114114
</dependency>
115+
<dependency>
116+
<groupId>org.postgresql</groupId>
117+
<artifactId>postgresql</artifactId>
118+
<version>${postgresql.version}</version>
119+
<scope>test</scope>
120+
</dependency>
121+
<dependency>
122+
<groupId>org.testcontainers</groupId>
123+
<artifactId>postgresql</artifactId>
124+
<version>${testcontainers.version}</version>
125+
<scope>test</scope>
126+
</dependency>
127+
<dependency>
128+
<groupId>com.ibm.db2</groupId>
129+
<artifactId>jcc</artifactId>
130+
<version>${db2.version}</version>
131+
<scope>test</scope>
132+
</dependency>
133+
<dependency>
134+
<groupId>org.testcontainers</groupId>
135+
<artifactId>db2</artifactId>
136+
<version>${testcontainers.version}</version>
137+
<scope>test</scope>
138+
</dependency>
139+
<dependency>
140+
<groupId>org.testcontainers</groupId>
141+
<artifactId>oracle-xe</artifactId>
142+
<version>${testcontainers.version}</version>
143+
<scope>test</scope>
144+
</dependency>
145+
<dependency>
146+
<groupId>com.oracle.database.jdbc</groupId>
147+
<artifactId>ojdbc8</artifactId>
148+
<version>${oracle.version}</version>
149+
<scope>test</scope>
150+
</dependency>
151+
<dependency>
152+
<groupId>org.testcontainers</groupId>
153+
<artifactId>mssqlserver</artifactId>
154+
<version>${testcontainers.version}</version>
155+
<scope>test</scope>
156+
</dependency>
157+
<dependency>
158+
<groupId>com.microsoft.sqlserver</groupId>
159+
<artifactId>mssql-jdbc</artifactId>
160+
<version>${sqlserver.version}</version>
161+
<scope>test</scope>
162+
</dependency>
163+
<dependency>
164+
<groupId>net.sourceforge.jtds</groupId>
165+
<artifactId>jtds</artifactId>
166+
<version>${jtds.version}</version>
167+
<scope>test</scope>
168+
</dependency>
169+
<dependency>
170+
<groupId>org.xerial</groupId>
171+
<artifactId>sqlite-jdbc</artifactId>
172+
<version>${sqlite.version}</version>
173+
<scope>test</scope>
174+
</dependency>
115175
<dependency>
116176
<groupId>com.h2database</groupId>
117177
<artifactId>h2</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright 2020-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.batch.core.test.repository;
17+
18+
import javax.sql.DataSource;
19+
20+
import com.ibm.db2.jcc.DB2SimpleDataSource;
21+
import org.junit.Assert;
22+
import org.junit.Before;
23+
import org.junit.ClassRule;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
import org.testcontainers.containers.Db2Container;
27+
import org.testcontainers.utility.DockerImageName;
28+
29+
import org.springframework.batch.core.ExitStatus;
30+
import org.springframework.batch.core.Job;
31+
import org.springframework.batch.core.JobExecution;
32+
import org.springframework.batch.core.JobParameters;
33+
import org.springframework.batch.core.JobParametersBuilder;
34+
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
35+
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
36+
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
37+
import org.springframework.batch.core.launch.JobLauncher;
38+
import org.springframework.batch.repeat.RepeatStatus;
39+
import org.springframework.beans.factory.annotation.Autowired;
40+
import org.springframework.context.annotation.Bean;
41+
import org.springframework.context.annotation.Configuration;
42+
import org.springframework.core.io.ClassPathResource;
43+
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
44+
import org.springframework.test.context.ContextConfiguration;
45+
import org.springframework.test.context.junit4.SpringRunner;
46+
47+
/**
48+
* @author Mahmoud Ben Hassine
49+
*/
50+
@RunWith(SpringRunner.class)
51+
@ContextConfiguration
52+
public class Db2JobRepositoryIntegrationTests {
53+
54+
// TODO find the best way to externalize and manage image versions
55+
private static final DockerImageName DB2_IMAGE = DockerImageName.parse("ibmcom/db2:11.5.5.1");
56+
57+
@ClassRule
58+
public static Db2Container db2 = new Db2Container(DB2_IMAGE).acceptLicense();
59+
60+
@Autowired
61+
private DataSource dataSource;
62+
@Autowired
63+
private JobLauncher jobLauncher;
64+
@Autowired
65+
private Job job;
66+
67+
@Before
68+
public void setUp() {
69+
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
70+
databasePopulator.addScript(new ClassPathResource("/org/springframework/batch/core/schema-db2.sql"));
71+
databasePopulator.execute(this.dataSource);
72+
}
73+
74+
@Test
75+
public void testJobExecution() throws Exception {
76+
// given
77+
JobParameters jobParameters = new JobParametersBuilder().toJobParameters();
78+
79+
// when
80+
JobExecution jobExecution = this.jobLauncher.run(this.job, jobParameters);
81+
82+
// then
83+
Assert.assertNotNull(jobExecution);
84+
Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
85+
}
86+
87+
@Configuration
88+
@EnableBatchProcessing
89+
static class TestConfiguration {
90+
91+
@Bean
92+
public DataSource dataSource() throws Exception {
93+
DB2SimpleDataSource dataSource =new DB2SimpleDataSource();
94+
dataSource.setDatabaseName(db2.getDatabaseName());
95+
dataSource.setUser(db2.getUsername());
96+
dataSource.setPassword(db2.getPassword());
97+
dataSource.setDriverType(4);
98+
dataSource.setServerName(db2.getContainerIpAddress());
99+
dataSource.setPortNumber(db2.getMappedPort(Db2Container.DB2_PORT));
100+
dataSource.setSslConnection(false);
101+
return dataSource;
102+
}
103+
104+
@Bean
105+
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps) {
106+
return jobs.get("job")
107+
.start(steps.get("step")
108+
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
109+
.build())
110+
.build();
111+
}
112+
113+
}
114+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright 2020-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.batch.core.test.repository;
17+
18+
import javax.sql.DataSource;
19+
20+
import org.junit.Assert;
21+
import org.junit.Test;
22+
import org.junit.runner.RunWith;
23+
24+
import org.springframework.batch.core.ExitStatus;
25+
import org.springframework.batch.core.Job;
26+
import org.springframework.batch.core.JobExecution;
27+
import org.springframework.batch.core.JobParameters;
28+
import org.springframework.batch.core.JobParametersBuilder;
29+
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
30+
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
31+
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
32+
import org.springframework.batch.core.launch.JobLauncher;
33+
import org.springframework.batch.repeat.RepeatStatus;
34+
import org.springframework.beans.factory.annotation.Autowired;
35+
import org.springframework.context.annotation.Bean;
36+
import org.springframework.context.annotation.Configuration;
37+
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
38+
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
39+
import org.springframework.test.context.ContextConfiguration;
40+
import org.springframework.test.context.junit4.SpringRunner;
41+
42+
/**
43+
* @author Mahmoud Ben Hassine
44+
*/
45+
@RunWith(SpringRunner.class)
46+
@ContextConfiguration
47+
public class DerbyJobRepositoryIntegrationTests {
48+
49+
@Autowired
50+
private JobLauncher jobLauncher;
51+
@Autowired
52+
private Job job;
53+
54+
@Test
55+
public void testJobExecution() throws Exception {
56+
// given
57+
JobParameters jobParameters = new JobParametersBuilder().toJobParameters();
58+
59+
// when
60+
JobExecution jobExecution = this.jobLauncher.run(this.job, jobParameters);
61+
62+
// then
63+
Assert.assertNotNull(jobExecution);
64+
Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
65+
}
66+
67+
@Configuration
68+
@EnableBatchProcessing
69+
static class TestConfiguration {
70+
71+
@Bean
72+
public DataSource dataSource() {
73+
return new EmbeddedDatabaseBuilder()
74+
.setType(EmbeddedDatabaseType.DERBY)
75+
.addScript("/org/springframework/batch/core/schema-derby.sql")
76+
.generateUniqueName(true)
77+
.build();
78+
}
79+
80+
@Bean
81+
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps) {
82+
return jobs.get("job")
83+
.start(steps.get("step")
84+
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
85+
.build())
86+
.build();
87+
}
88+
89+
}
90+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright 2020-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.batch.core.test.repository;
17+
18+
import javax.sql.DataSource;
19+
20+
import org.junit.Assert;
21+
import org.junit.Test;
22+
import org.junit.runner.RunWith;
23+
24+
import org.springframework.batch.core.ExitStatus;
25+
import org.springframework.batch.core.Job;
26+
import org.springframework.batch.core.JobExecution;
27+
import org.springframework.batch.core.JobParameters;
28+
import org.springframework.batch.core.JobParametersBuilder;
29+
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
30+
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
31+
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
32+
import org.springframework.batch.core.launch.JobLauncher;
33+
import org.springframework.batch.repeat.RepeatStatus;
34+
import org.springframework.beans.factory.annotation.Autowired;
35+
import org.springframework.context.annotation.Bean;
36+
import org.springframework.context.annotation.Configuration;
37+
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
38+
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
39+
import org.springframework.test.context.ContextConfiguration;
40+
import org.springframework.test.context.junit4.SpringRunner;
41+
42+
/**
43+
* @author Mahmoud Ben Hassine
44+
*/
45+
@RunWith(SpringRunner.class)
46+
@ContextConfiguration
47+
public class H2JobRepositoryIntegrationTests {
48+
49+
@Autowired
50+
private JobLauncher jobLauncher;
51+
@Autowired
52+
private Job job;
53+
54+
@Test
55+
public void testJobExecution() throws Exception {
56+
// given
57+
JobParameters jobParameters = new JobParametersBuilder().toJobParameters();
58+
59+
// when
60+
JobExecution jobExecution = this.jobLauncher.run(this.job, jobParameters);
61+
62+
// then
63+
Assert.assertNotNull(jobExecution);
64+
Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
65+
}
66+
67+
@Configuration
68+
@EnableBatchProcessing
69+
static class TestConfiguration {
70+
71+
@Bean
72+
public DataSource dataSource() {
73+
return new EmbeddedDatabaseBuilder()
74+
.setType(EmbeddedDatabaseType.H2)
75+
.addScript("/org/springframework/batch/core/schema-h2.sql")
76+
.generateUniqueName(true)
77+
.build();
78+
}
79+
80+
@Bean
81+
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps) {
82+
return jobs.get("job")
83+
.start(steps.get("step")
84+
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
85+
.build())
86+
.build();
87+
}
88+
89+
}
90+
}

0 commit comments

Comments
 (0)