Use JdbcTestUtils where appropriate in tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009-2014 the original author or authors.
|
||||
* Copyright 2009-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,6 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@@ -53,13 +54,13 @@ public class JobLauncherIntegrationTests {
|
||||
@Test
|
||||
public void testLaunchAndRelaunch() throws Exception {
|
||||
|
||||
int before = jdbcTemplate.queryForObject("select count(*) from BATCH_JOB_INSTANCE", Integer.class);
|
||||
int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_INSTANCE");
|
||||
|
||||
JobExecution jobExecution = launch(true,0);
|
||||
launch(false, jobExecution.getId());
|
||||
launch(false, jobExecution.getId());
|
||||
|
||||
int after = jdbcTemplate.queryForObject("select count(*) from BATCH_JOB_INSTANCE", Integer.class);
|
||||
int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_INSTANCE");
|
||||
assertEquals(before+1, after);
|
||||
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -75,8 +76,8 @@ public class RestartIntegrationTests {
|
||||
ExampleItemReader.fail = true;
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("restart", "yes").toJobParameters();
|
||||
|
||||
int beforeManager = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STEP_EXECUTION where STEP_NAME='step1:manager'", Integer.class);
|
||||
int beforePartition = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STEP_EXECUTION where STEP_NAME like 'step1:partition%'", Integer.class);
|
||||
int beforeManager = JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, "BATCH_STEP_EXECUTION", "STEP_NAME='step1:manager'");
|
||||
int beforePartition = JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, "BATCH_STEP_EXECUTION", "STEP_NAME like 'step1:partition%'");
|
||||
|
||||
ExampleItemWriter.clear();
|
||||
JobExecution execution = jobLauncher.run(job, jobParameters);
|
||||
@@ -89,8 +90,8 @@ public class RestartIntegrationTests {
|
||||
// Only 4 because the others were processed in the first attempt
|
||||
assertEquals(4, ExampleItemWriter.getItems().size());
|
||||
|
||||
int afterManager = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STEP_EXECUTION where STEP_NAME='step1:manager'", Integer.class);
|
||||
int afterPartition = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STEP_EXECUTION where STEP_NAME like 'step1:partition%'", Integer.class);
|
||||
int afterManager = JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, "BATCH_STEP_EXECUTION", "STEP_NAME='step1:manager'");
|
||||
int afterPartition = JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, "BATCH_STEP_EXECUTION", "STEP_NAME like 'step1:partition%'");
|
||||
|
||||
// Two attempts
|
||||
assertEquals(2, afterManager-beforeManager);
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -59,11 +60,11 @@ public class VanillaIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testLaunchJob() throws Exception {
|
||||
int beforeManager = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STEP_EXECUTION where STEP_NAME='step1:manager'", Integer.class);
|
||||
int beforePartition = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STEP_EXECUTION where STEP_NAME like 'step1:partition%'", Integer.class);
|
||||
int beforeManager = JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, "BATCH_STEP_EXECUTION", "STEP_NAME='step1:manager'");
|
||||
int beforePartition = JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, "BATCH_STEP_EXECUTION", "STEP_NAME like 'step1:partition%'");
|
||||
assertNotNull(jobLauncher.run(job, new JobParameters()));
|
||||
int afterManager = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STEP_EXECUTION where STEP_NAME='step1:manager'", Integer.class);
|
||||
int afterPartition = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STEP_EXECUTION where STEP_NAME like 'step1:partition%'", Integer.class);
|
||||
int afterManager = JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, "BATCH_STEP_EXECUTION", "STEP_NAME='step1:manager'");
|
||||
int afterPartition = JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, "BATCH_STEP_EXECUTION", "STEP_NAME like 'step1:partition%'");
|
||||
assertEquals(1, afterManager-beforeManager);
|
||||
// Should be same as grid size in step splitter
|
||||
assertEquals(2, afterPartition-beforePartition);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2019 the original author or authors.
|
||||
* Copyright 2006-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,6 +40,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -84,7 +85,7 @@ public class JdbcJobRepositoryTests extends AbstractIntegrationTests {
|
||||
job.setName("foo");
|
||||
int before = 0;
|
||||
JobExecution execution = repository.createJobExecution(job.getName(), new JobParameters());
|
||||
int after = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE", Integer.class);
|
||||
int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_INSTANCE");;
|
||||
assertEquals(before + 1, after);
|
||||
assertNotNull(execution.getId());
|
||||
}
|
||||
@@ -96,7 +97,7 @@ public class JdbcJobRepositoryTests extends AbstractIntegrationTests {
|
||||
JobExecution execution = repository.createJobExecution(job.getName(), new JobParameters());
|
||||
execution.getExecutionContext().put("foo", "bar");
|
||||
repository.updateExecutionContext(execution);
|
||||
int after = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM BATCH_JOB_EXECUTION_CONTEXT", Integer.class);
|
||||
int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION_CONTEXT");
|
||||
assertEquals(before + 1, after);
|
||||
assertNotNull(execution.getId());
|
||||
JobExecution last = repository.getLastJobExecution(job.getName(), new JobParameters());
|
||||
@@ -126,7 +127,7 @@ public class JdbcJobRepositoryTests extends AbstractIntegrationTests {
|
||||
|
||||
assertNotNull(execution);
|
||||
|
||||
int after = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE", Integer.class);
|
||||
int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_INSTANCE");
|
||||
assertNotNull(execution.getId());
|
||||
assertEquals(before + 1, after);
|
||||
|
||||
@@ -147,7 +148,7 @@ public class JdbcJobRepositoryTests extends AbstractIntegrationTests {
|
||||
repository.update(execution);
|
||||
execution.setStatus(BatchStatus.FAILED);
|
||||
|
||||
int before = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE", Integer.class);
|
||||
int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_INSTANCE");
|
||||
assertEquals(1, before);
|
||||
|
||||
long t0 = System.currentTimeMillis();
|
||||
@@ -160,7 +161,7 @@ public class JdbcJobRepositoryTests extends AbstractIntegrationTests {
|
||||
}
|
||||
long t1 = System.currentTimeMillis();
|
||||
|
||||
int after = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE", Integer.class);
|
||||
int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_INSTANCE");
|
||||
assertNotNull(execution.getId());
|
||||
assertEquals(before, after);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2019 the original author or authors.
|
||||
* Copyright 2010-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -226,7 +226,7 @@ public class FaultTolerantStepFactoryBeanIntegrationTests {
|
||||
|
||||
public void clear() {
|
||||
written.clear();
|
||||
jdbcTemplate.update("DELETE FROM ERROR_LOG where STEP_NAME='written'");
|
||||
JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "ERROR_LOG", "STEP_NAME='written'");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -272,7 +272,7 @@ public class FaultTolerantStepFactoryBeanIntegrationTests {
|
||||
|
||||
public void clear() {
|
||||
processed.clear();
|
||||
jdbcTemplate.update("DELETE FROM ERROR_LOG where STEP_NAME='processed'");
|
||||
JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "ERROR_LOG", "STEP_NAME='processed'");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2019 the original author or authors.
|
||||
* Copyright 2010-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -251,7 +251,7 @@ public class FaultTolerantStepFactoryBeanRollbackIntegrationTests {
|
||||
|
||||
public void clear() {
|
||||
written.clear();
|
||||
jdbcTemplate.update("DELETE FROM ERROR_LOG where STEP_NAME='written'");
|
||||
JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "ERROR_LOG", "STEP_NAME='written'");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -304,7 +304,7 @@ public class FaultTolerantStepFactoryBeanRollbackIntegrationTests {
|
||||
|
||||
public void clear() {
|
||||
processed.clear();
|
||||
jdbcTemplate.update("DELETE FROM ERROR_LOG where STEP_NAME='processed'");
|
||||
JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "ERROR_LOG", "STEP_NAME='processed'");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user