Use JdbcTestUtils where appropriate in tests

This commit is contained in:
Mahmoud Ben Hassine
2021-08-26 22:12:34 +02:00
parent 3742931c4c
commit de9ce2d0cc
30 changed files with 154 additions and 125 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2014 the original author or authors.
* Copyright 2008-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.
@@ -36,6 +36,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
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;
@@ -49,7 +50,7 @@ public class CompositeItemWriterSampleFunctionalTests {
+ "Trade: [isin=UK21341EAH44,quantity=214,price=34.11,customer=customer4]"
+ "Trade: [isin=UK21341EAH45,quantity=215,price=35.11,customer=customer5]";
private JdbcOperations jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@@ -61,8 +62,8 @@ public class CompositeItemWriterSampleFunctionalTests {
@Test
public void testJobLaunch() throws Exception {
jdbcTemplate.update("DELETE from TRADE");
int before = jdbcTemplate.queryForObject("SELECT COUNT(*) from TRADE", Integer.class);
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE");
jobLauncherTestUtils.launchJob();
@@ -83,7 +84,7 @@ public class CompositeItemWriterSampleFunctionalTests {
}
};
int after = jdbcTemplate.queryForObject("SELECT COUNT(*) from TRADE", Integer.class);
int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE");
assertEquals(before + 5, after);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2014 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.
@@ -39,6 +39,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.jdbc.JdbcTestUtils;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/customerFilterJob.xml", "/job-runner-context.xml" })
@@ -46,7 +47,7 @@ public class CustomerFilterJobFunctionalTests {
private static final String GET_CUSTOMERS = "select NAME, CREDIT from CUSTOMER order by NAME";
private List<Customer> customers;
private int activeRow = 0;
private JdbcOperations jdbcTemplate;
private JdbcTemplate jdbcTemplate;
private Map<String, Double> credits = new HashMap<>();
@Autowired
@@ -59,8 +60,8 @@ public class CustomerFilterJobFunctionalTests {
@Before
public void onSetUp() throws Exception {
jdbcTemplate.update("delete from TRADE");
jdbcTemplate.update("delete from CUSTOMER where ID > 4");
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "CUSTOMER", "ID > 4");
jdbcTemplate.update("update CUSTOMER set credit=100000");
List<Map<String, Object>> list = jdbcTemplate.queryForList("select name, CREDIT from CUSTOMER");
@@ -72,8 +73,8 @@ public class CustomerFilterJobFunctionalTests {
@After
public void tearDown() throws Exception {
jdbcTemplate.update("delete from TRADE");
jdbcTemplate.update("delete from CUSTOMER where ID > 4");
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "CUSTOMER", "ID > 4");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2007-2014 the original author or authors.
* Copyright 2007-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.
@@ -27,13 +27,14 @@ import org.springframework.jdbc.core.JdbcOperations;
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;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/footballJob.xml", "/job-runner-context.xml" })
public class FootballJobFunctionalTests {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
private JdbcOperations jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
@@ -42,13 +43,11 @@ public class FootballJobFunctionalTests {
@Test
public void testLaunchJob() throws Exception {
jdbcTemplate.update("DELETE FROM PLAYERS");
jdbcTemplate.update("DELETE FROM GAMES");
jdbcTemplate.update("DELETE FROM PLAYER_SUMMARY");
JdbcTestUtils.deleteFromTables(jdbcTemplate, "PLAYERS", "GAMES", "PLAYER_SUMMARY");
jobLauncherTestUtils.launchJob();
int count = jdbcTemplate.queryForObject("SELECT COUNT(*) from PLAYER_SUMMARY", Integer.class);
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "PLAYER_SUMMARY");
assertTrue(count > 0);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2007-2014 the original author or authors.
* Copyright 2007-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.
@@ -43,6 +43,7 @@ import org.springframework.jdbc.core.RowMapper;
import org.springframework.orm.hibernate5.HibernateJdbcException;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.jdbc.JdbcTestUtils;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
@@ -53,13 +54,13 @@ import org.springframework.transaction.support.TransactionTemplate;
* expected value.
*
* @author Dave Syer
* @author Mahmoud Ben Hassine
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/hibernate-context.xml", "/jobs/hibernateJob.xml",
"/job-runner-context.xml" })
public class HibernateFailureJobFunctionalTests {
private static final BigDecimal CREDIT_INCREASE = CustomerCreditIncreaseProcessor.FIXED_AMOUNT;
private static final String DELETE_CUSTOMERS = "DELETE FROM CUSTOMER";
private static final String ALL_CUSTOMERS = "select * from CUSTOMER order by ID";
private static final String CREDIT_COLUMN = "CREDIT";
private static String[] customers = { "INSERT INTO CUSTOMER (id, version, name, credit) VALUES (1, 0, 'customer1', 100000)",
@@ -71,7 +72,7 @@ public class HibernateFailureJobFunctionalTests {
@Autowired
private HibernateCreditDao writer;
private JdbcOperations jdbcTemplate;
private JdbcTemplate jdbcTemplate;
private PlatformTransactionManager transactionManager;
private List<BigDecimal> creditsBeforeUpdate;
@@ -108,7 +109,7 @@ public class HibernateFailureJobFunctionalTests {
throw e;
}
int after = jdbcTemplate.queryForObject("SELECT COUNT(*) from CUSTOMER", Integer.class);
int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "CUSTOMER");
assertEquals(4, after);
validatePostConditions();
@@ -141,7 +142,7 @@ public class HibernateFailureJobFunctionalTests {
@Override
public Void doInTransaction(TransactionStatus status) {
jdbcTemplate.update(DELETE_CUSTOMERS);
JdbcTestUtils.deleteFromTables(jdbcTemplate, "CUSTOMER");
for (String customer : customers) {
jdbcTemplate.update(customer);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2014 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.
@@ -30,18 +30,20 @@ import org.springframework.jdbc.core.JdbcOperations;
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;
/**
* Sample using a step to launch a job.
*
* @author Dave Syer
* @author Mahmoud Ben Hassine
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class JobStepFunctionalTests {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
private JdbcOperations jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
@@ -50,13 +52,13 @@ public class JobStepFunctionalTests {
@Test
public void testJobLaunch() throws Exception {
jdbcTemplate.update("DELETE FROM TRADE");
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
jobLauncherTestUtils.launchJob(new DefaultJobParametersConverter()
.getJobParameters(PropertiesConverter
.stringToProperties("run.id(long)=1,parameter=true,run.date=20070122,input.file=classpath:data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt")));
int after = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM TRADE", Integer.class);
int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE");
assertEquals(5, after);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2012 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.
@@ -38,10 +38,12 @@ import org.springframework.mail.MailMessage;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.jdbc.JdbcTestUtils;
/**
* @author Dan Garrette
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
* @Since 2.1
*/
@@ -67,7 +69,7 @@ public class MailJobFunctionalTests {
private static final Object[] USER8 = new Object[] { 8, "Martin Van Buren", email };
private JdbcOperations jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@@ -92,7 +94,7 @@ public class MailJobFunctionalTests {
@After
public void after() throws Exception {
jdbcTemplate.update("drop table USERS");
JdbcTestUtils.dropTables(jdbcTemplate, "USERS");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2014 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.
@@ -33,18 +33,20 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.jdbc.JdbcTestUtils;
/**
* Simple restart scenario.
*
* @author Robert Kasanicky
* @author Dave Syer
* @author Mahmoud Ben Hassine
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/restartSample.xml",
"/job-runner-context.xml" })
public class RestartFunctionalTests {
private JdbcOperations jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@@ -56,7 +58,7 @@ public class RestartFunctionalTests {
@BeforeTransaction
public void onTearDown() throws Exception {
jdbcTemplate.update("DELETE FROM TRADE");
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
}
/**
@@ -70,7 +72,7 @@ public class RestartFunctionalTests {
*/
@Test
public void testLaunchJob() throws Exception {
int before = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM TRADE", Integer.class);
int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE");
JobExecution jobExecution = runJobForRestartTest();
assertEquals(BatchStatus.FAILED, jobExecution.getStatus());
@@ -83,14 +85,14 @@ public class RestartFunctionalTests {
throw new RuntimeException(ex);
}
int medium = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM TRADE", Integer.class);
int medium = JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE");
// assert based on commit interval = 2
assertEquals(before + 2, medium);
jobExecution = runJobForRestartTest();
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
int after = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM TRADE", Integer.class);
int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE");
assertEquals(before + 5, after);
}

View File

@@ -70,7 +70,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration(locations = { "/skipSample-job-launcher-context.xml" })
public class SkipSampleFunctionalTests {
private JdbcOperations jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
private JobExplorer jobExplorer;
@@ -89,12 +89,11 @@ public class SkipSampleFunctionalTests {
@Before
public void setUp() {
jdbcTemplate.update("DELETE from TRADE");
jdbcTemplate.update("DELETE from CUSTOMER");
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE", "CUSTOMER");
for (int i = 1; i < 10; i++) {
jdbcTemplate.update("INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (" + incrementer.nextIntValue() + ", 0, 'customer" + i + "', 100000)");
}
jdbcTemplate.update("DELETE from ERROR_LOG");
JdbcTestUtils.deleteFromTables(jdbcTemplate, "ERROR_LOG");
}
/**
@@ -263,18 +262,18 @@ public class SkipSampleFunctionalTests {
private void validateLaunchWithSkips(JobExecution jobExecution) {
// Step1: 9 input records, 1 skipped in read, 1 skipped in write =>
// 7 written to output
assertEquals(7, JdbcTestUtils.countRowsInTable((JdbcTemplate) jdbcTemplate, "TRADE"));
assertEquals(7, JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE"));
// Step2: 7 input records, 1 skipped on process, 1 on write => 5 written
// to output
// System.err.println(jdbcTemplate.queryForList("SELECT * FROM TRADE"));
assertEquals(5, jdbcTemplate.queryForObject("SELECT COUNT(*) from TRADE where VERSION=?", Integer.class, 1).intValue());
assertEquals(5, JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, "TRADE", "VERSION=1"));
// 1 record skipped in processing second step
assertEquals(1, SkipCheckingListener.getProcessSkips());
// Both steps contained skips
assertEquals(2, JdbcTestUtils.countRowsInTable((JdbcTemplate) jdbcTemplate, "ERROR_LOG"));
assertEquals(2, JdbcTestUtils.countRowsInTable(jdbcTemplate, "ERROR_LOG"));
assertEquals("2 records were skipped!", jdbcTemplate.queryForObject(
"SELECT MESSAGE from ERROR_LOG where JOB_NAME = ? and STEP_NAME = ?", String.class, "skipJob", "step1"));
@@ -293,13 +292,13 @@ public class SkipSampleFunctionalTests {
private void validateLaunchWithoutSkips(JobExecution jobExecution) {
// Step1: 5 input records => 5 written to output
assertEquals(5, JdbcTestUtils.countRowsInTable((JdbcTemplate) jdbcTemplate, "TRADE"));
assertEquals(5, JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE"));
// Step2: 5 input records => 5 written to output
assertEquals(5, jdbcTemplate.queryForObject("SELECT COUNT(*) from TRADE where VERSION=?", Integer.class, 1).intValue());
assertEquals(5, JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, "TRADE", "VERSION=1"));
// Neither step contained skips
assertEquals(0, JdbcTestUtils.countRowsInTable((JdbcTemplate) jdbcTemplate, "ERROR_LOG"));
assertEquals(0, JdbcTestUtils.countRowsInTable(jdbcTemplate, "ERROR_LOG"));
assertEquals(new BigDecimal("270.75"), jobExecution.getExecutionContext().get(TradeWriter.TOTAL_AMOUNT_KEY));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2014 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.
@@ -41,6 +41,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.jdbc.JdbcTestUtils;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/tradeJob.xml",
@@ -52,7 +53,7 @@ public class TradeJobFunctionalTests {
private List<Customer> customers;
private List<Trade> trades;
private int activeRow = 0;
private JdbcOperations jdbcTemplate;
private JdbcTemplate jdbcTemplate;
private Map<String, Double> credits = new HashMap<>();
@Autowired
@@ -65,7 +66,7 @@ public class TradeJobFunctionalTests {
@Before
public void onSetUp() throws Exception {
jdbcTemplate.update("delete from TRADE");
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
List<Map<String, Object>> list = jdbcTemplate.queryForList("select NAME, CREDIT from CUSTOMER");
for (Map<String, Object> map : list) {
@@ -75,7 +76,7 @@ public class TradeJobFunctionalTests {
@After
public void tearDown() throws Exception {
jdbcTemplate.update("delete from TRADE");
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2014 the original author or authors.
* Copyright 2008-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.
@@ -35,6 +35,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.AfterTransaction;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.jdbc.JdbcTestUtils;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
@@ -45,7 +46,7 @@ import org.springframework.transaction.support.TransactionTemplate;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration()
public class StagingItemReaderTests {
private JdbcOperations jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
private PlatformTransactionManager transactionManager;
@@ -75,7 +76,7 @@ public class StagingItemReaderTests {
@AfterTransaction
public void onTearDownAfterTransaction() throws Exception {
reader.destroy();
jdbcTemplate.update("DELETE FROM BATCH_STAGING");
JdbcTestUtils.deleteFromTables(jdbcTemplate, "BATCH_STAGING");
}
@Transactional

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2014 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.
@@ -33,12 +33,13 @@ import org.springframework.jdbc.core.JdbcOperations;
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 org.springframework.transaction.annotation.Transactional;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class StagingItemWriterTests {
private JdbcOperations jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
private StagingItemWriter<String> writer;
@@ -58,9 +59,9 @@ public class StagingItemWriterTests {
@Transactional
@Test
public void testProcessInsertsNewItem() throws Exception {
int before = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STAGING", Integer.class);
int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STAGING");
writer.write(Collections.singletonList("FOO"));
int after = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STAGING", Integer.class);
int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STAGING");
assertEquals(before + 1, after);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2014 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.
@@ -32,10 +32,12 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.jdbc.JdbcTestUtils;
import org.springframework.transaction.annotation.Transactional;
/**
* @author Lucas Ward
* @author Mahmoud Ben Hassine
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@@ -44,7 +46,7 @@ public class JdbcPlayerDaoIntegrationTests {
private JdbcPlayerDao playerDao;
private Player player;
private static final String GET_PLAYER = "SELECT * from PLAYERS";
private JdbcOperations jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
public void init(DataSource dataSource) {
@@ -63,7 +65,7 @@ public class JdbcPlayerDaoIntegrationTests {
@Before
public void onSetUpInTransaction() throws Exception {
jdbcTemplate.execute("delete from PLAYERS");
JdbcTestUtils.deleteFromTables(jdbcTemplate, "PLAYERS");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2014 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.
@@ -30,10 +30,12 @@ import org.springframework.jdbc.core.JdbcOperations;
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 org.springframework.transaction.annotation.Transactional;
/**
* @author Lucas Ward
* @author Mahmoud Ben Hassine
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@@ -41,7 +43,7 @@ import org.springframework.transaction.annotation.Transactional;
public class JdbcPlayerSummaryDaoIntegrationTests {
private JdbcPlayerSummaryDao playerSummaryDao;
private PlayerSummary summary;
private JdbcOperations jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
public void init(DataSource dataSource) {
@@ -66,7 +68,7 @@ public class JdbcPlayerSummaryDaoIntegrationTests {
@Before
public void onSetUpInTransaction() throws Exception {
jdbcTemplate.execute("delete from PLAYER_SUMMARY");
JdbcTestUtils.deleteFromTables(jdbcTemplate, "PLAYER_SUMMARY");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2014 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.
@@ -36,9 +36,11 @@ import org.springframework.jdbc.core.JdbcOperations;
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
* @author Mahmoud Ben Hassine
* @since 2.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@@ -51,7 +53,7 @@ public class TwoJobInstancesPagingFunctionalTests {
@Autowired
private Job job;
private JdbcOperations jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
@@ -60,11 +62,11 @@ public class TwoJobInstancesPagingFunctionalTests {
@Test
public void testLaunchJobTwice() throws Exception {
int first = jdbcTemplate.queryForObject("select count(0) from CUSTOMER where credit>1000", Integer.class);
int first = JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, "CUSTOMER", "credit>1000");
JobExecution jobExecution = launcher.run(this.job, getJobParameters(1000.));
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
assertEquals(first, jobExecution.getStepExecutions().iterator().next().getWriteCount());
int second = jdbcTemplate.queryForObject("select count(0) from CUSTOMER where credit>1000000", Integer.class);
int second = JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, "CUSTOMER", "credit>1000000");
assertNotSame("The number of records above the threshold did not change", first, second);
jobExecution = launcher.run(this.job, getJobParameters(1000000.));
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());