diff --git a/build.gradle b/build.gradle index 9ebd09086..9110e0d4f 100644 --- a/build.gradle +++ b/build.gradle @@ -71,7 +71,7 @@ allprojects { derbyVersion = '10.14.2.0' groovyVersion = '2.5.14' hamcrestVersion = '2.2' - h2databaseVersion = '1.4.200' + h2databaseVersion = '2.0.206' hibernateVersion = '5.4.32.Final' hibernateValidatorVersion = '6.1.7.Final' javaxElVersion = '3.0.0' @@ -425,6 +425,7 @@ project('spring-batch-core-tests') { compile "org.springframework:spring-aop:$springVersion" testCompile "org.hsqldb:hsqldb:$hsqldbVersion" + testCompile "com.h2database:h2:$h2databaseVersion" testCompile "commons-io:commons-io:$commonsIoVersion" testCompile "org.apache.derby:derby:$derbyVersion" testCompile "junit:junit:${junitVersion}" diff --git a/spring-batch-core-tests/src/main/java/org/springframework/batch/sample/domain/repository/H2CompatibilityModeJobRepositoryIntegrationTests.java b/spring-batch-core-tests/src/test/java/org/springframework/batch/core/test/repository/H2CompatibilityModeJobRepositoryIntegrationTests.java similarity index 81% rename from spring-batch-core-tests/src/main/java/org/springframework/batch/sample/domain/repository/H2CompatibilityModeJobRepositoryIntegrationTests.java rename to spring-batch-core-tests/src/test/java/org/springframework/batch/core/test/repository/H2CompatibilityModeJobRepositoryIntegrationTests.java index 8e9b6b9c0..0c87dafa5 100644 --- a/spring-batch-core-tests/src/main/java/org/springframework/batch/sample/domain/repository/H2CompatibilityModeJobRepositoryIntegrationTests.java +++ b/spring-batch-core-tests/src/test/java/org/springframework/batch/core/test/repository/H2CompatibilityModeJobRepositoryIntegrationTests.java @@ -18,6 +18,7 @@ package org.springframework.batch.core.test.repository; import java.util.Arrays; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; import javax.sql.DataSource; @@ -29,6 +30,7 @@ import org.junit.runners.Parameterized.Parameters; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; +import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; @@ -39,6 +41,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.Resource; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.SimpleDriverDataSource; import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils; @@ -46,6 +49,7 @@ import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; /** * @author Henning Pƶttker + * @author Mahmoud Ben Hassine */ @RunWith(Parameterized.class) public class H2CompatibilityModeJobRepositoryIntegrationTests { @@ -58,31 +62,31 @@ public class H2CompatibilityModeJobRepositoryIntegrationTests { @Test public void testJobExecution() throws Exception { - var context = new AnnotationConfigApplicationContext(); + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.register(TestConfiguration.class); context.registerBean(DataSource.class, this::buildDataSource); context.refresh(); - var jobLauncher = context.getBean(JobLauncher.class); - var job = context.getBean(Job.class); + JobLauncher jobLauncher = context.getBean(JobLauncher.class); + Job job = context.getBean(Job.class); - var jobExecution = jobLauncher.run(job, new JobParameters()); + JobExecution jobExecution = jobLauncher.run(job, new JobParameters()); Assert.assertNotNull(jobExecution); Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus()); - var jdbcTemplate = new JdbcTemplate(context.getBean(DataSource.class)); + JdbcTemplate jdbcTemplate = new JdbcTemplate(context.getBean(DataSource.class)); jdbcTemplate.execute("SHUTDOWN"); } private DataSource buildDataSource() { - var connectionUrl = String.format( + String connectionUrl = String.format( "jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false;MODE=%s", UUID.randomUUID(), this.compatibilityMode ); - var dataSource = new SimpleDriverDataSource(new org.h2.Driver(), connectionUrl, "sa", ""); - var populator = new ResourceDatabasePopulator(); - var resource = new DefaultResourceLoader() + DataSource dataSource = new SimpleDriverDataSource(new org.h2.Driver(), connectionUrl, "sa", ""); + ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); + Resource resource = new DefaultResourceLoader() .getResource("/org/springframework/batch/core/schema-h2.sql"); populator.addScript(resource); DatabasePopulatorUtils.execute(populator, dataSource); @@ -106,6 +110,6 @@ public class H2CompatibilityModeJobRepositoryIntegrationTests { public static List data() throws Exception { return Arrays.stream(org.h2.engine.Mode.ModeEnum.values()) .map(mode -> new Object[]{mode.toString()}) - .toList(); + .collect(Collectors.toList()); } }