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
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.Test;
|
||||
@@ -36,8 +37,8 @@ public class DatasourceTests {
|
||||
@Transactional @Test
|
||||
public void testTemplate() throws Exception {
|
||||
System.err.println(System.getProperty("java.class.path"));
|
||||
jdbcTemplate.execute("delete from T_BARS");
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_BARS");
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(0, count);
|
||||
|
||||
jdbcTemplate.update("INSERT into T_BARS (id,name,foo_date) values (?,?,null)", 0, "foo");
|
||||
|
||||
@@ -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.
|
||||
@@ -48,6 +48,7 @@ import static org.junit.Assert.assertTrue;
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Michael Minella
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 2.1
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@@ -74,7 +75,6 @@ public class JdbcPagingQueryIntegrationTests {
|
||||
String[] names = {"Foo", "Bar", "Baz", "Foo", "Bar", "Baz", "Foo", "Bar", "Baz"};
|
||||
String[] codes = {"A", "B", "A", "B", "B", "B", "A", "B", "A"};
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_FOOS");
|
||||
// jdbcTemplate.update("DELETE from T_FOOS");
|
||||
for(int i = 0; i < names.length; i++) {
|
||||
jdbcTemplate.update("INSERT into T_FOOS (ID,NAME, CODE, VALUE) values (?, ?, ?, ?)", maxId, names[i], codes[i], i);
|
||||
maxId++;
|
||||
@@ -85,7 +85,6 @@ public class JdbcPagingQueryIntegrationTests {
|
||||
@After
|
||||
public void destroy() {
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_FOOS");
|
||||
// jdbcTemplate.update("DELETE from T_FOOS");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-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.
|
||||
@@ -24,9 +24,11 @@ import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
/**
|
||||
* @author Luke Taylor
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class SqliteMaxValueIncrementerTests {
|
||||
static String dbFile;
|
||||
@@ -59,6 +61,6 @@ public class SqliteMaxValueIncrementerTests {
|
||||
assertEquals(1, mvi.getNextKey());
|
||||
assertEquals(2, mvi.getNextKey());
|
||||
assertEquals(3, mvi.getNextKey());
|
||||
assertEquals(1, template.queryForObject("select count(*) from max_value", Integer.class).intValue());
|
||||
assertEquals(1, JdbcTestUtils.countRowsInTable(template, "max_value"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.springframework.retry.support.DefaultRetryState;
|
||||
import org.springframework.retry.support.RetryTemplate;
|
||||
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;
|
||||
@@ -73,7 +74,7 @@ public class ExternalRetryInBatchTests {
|
||||
@Before
|
||||
public void onSetUp() throws Exception {
|
||||
getMessages(); // drain queue
|
||||
jdbcTemplate.execute("delete from T_BARS");
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_BARS");
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
jmsTemplate.convertAndSend("queue", "bar");
|
||||
provider = new ItemReader<String>() {
|
||||
@@ -91,11 +92,11 @@ public class ExternalRetryInBatchTests {
|
||||
@After
|
||||
public void onTearDown() throws Exception {
|
||||
getMessages(); // drain queue
|
||||
jdbcTemplate.execute("delete from T_BARS");
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_BARS");
|
||||
}
|
||||
|
||||
private void assertInitialState() {
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(0, count);
|
||||
}
|
||||
|
||||
@@ -189,7 +190,7 @@ public class ExternalRetryInBatchTests {
|
||||
assertEquals(2, recovered.size());
|
||||
|
||||
// The database portion committed once...
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(0, count);
|
||||
|
||||
// ... and so did the message session.
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.jms.listener.SessionAwareMessageListener;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
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.assertNull;
|
||||
@@ -63,7 +64,7 @@ public class AsynchronousTests {
|
||||
foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
count++;
|
||||
}
|
||||
jdbcTemplate.execute("delete from T_BARS");
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_BARS");
|
||||
|
||||
// Queue is now drained...
|
||||
assertNull(foo);
|
||||
@@ -90,7 +91,7 @@ public class AsynchronousTests {
|
||||
private volatile List<String> list = new ArrayList<>();
|
||||
|
||||
private void assertInitialState() {
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(0, count);
|
||||
}
|
||||
|
||||
@@ -122,7 +123,7 @@ public class AsynchronousTests {
|
||||
String foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
assertEquals(null, foo);
|
||||
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(2, count);
|
||||
|
||||
}
|
||||
@@ -169,7 +170,7 @@ public class AsynchronousTests {
|
||||
msgs.add(text);
|
||||
}
|
||||
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(0, count);
|
||||
|
||||
assertTrue("Foo not on queue", msgs.contains("foo"));
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
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;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
@@ -84,13 +85,13 @@ public class SynchronousTests implements ApplicationContextAware {
|
||||
foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
count++;
|
||||
}
|
||||
jdbcTemplate.execute("delete from T_BARS");
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_BARS");
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
jmsTemplate.convertAndSend("queue", "bar");
|
||||
}
|
||||
|
||||
private void assertInitialState() {
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(0, count);
|
||||
}
|
||||
|
||||
@@ -110,7 +111,7 @@ public class SynchronousTests implements ApplicationContextAware {
|
||||
}
|
||||
});
|
||||
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(2, count);
|
||||
|
||||
assertTrue(list.contains("foo"));
|
||||
@@ -154,7 +155,7 @@ public class SynchronousTests implements ApplicationContextAware {
|
||||
}
|
||||
|
||||
// The database portion rolled back...
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(0, count);
|
||||
|
||||
// ... and so did the message session. The rollback should have restored
|
||||
@@ -221,7 +222,7 @@ public class SynchronousTests implements ApplicationContextAware {
|
||||
}
|
||||
|
||||
// The database portion committed...
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(2, count);
|
||||
|
||||
// ...but the JMS session rolled back, so the message is still there
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.retry.support.DefaultRetryState;
|
||||
import org.springframework.retry.support.RetryTemplate;
|
||||
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;
|
||||
@@ -64,7 +65,7 @@ public class ExternalRetryTests {
|
||||
@Before
|
||||
public void onSetUp() throws Exception {
|
||||
getMessages(); // drain queue
|
||||
jdbcTemplate.execute("delete from T_BARS");
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_BARS");
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
provider = new ItemReader<String>() {
|
||||
@Nullable
|
||||
@@ -79,7 +80,7 @@ public class ExternalRetryTests {
|
||||
}
|
||||
|
||||
private void assertInitialState() {
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(0, count);
|
||||
}
|
||||
|
||||
@@ -167,7 +168,7 @@ public class ExternalRetryTests {
|
||||
List<String> msgs = getMessages();
|
||||
|
||||
// The database portion committed once...
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(1, count);
|
||||
|
||||
// ... and so did the message session.
|
||||
@@ -235,7 +236,7 @@ public class ExternalRetryTests {
|
||||
assertEquals(1, recovered.size());
|
||||
|
||||
// The database portion committed once...
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(0, count);
|
||||
|
||||
// ... and so did the message session.
|
||||
|
||||
@@ -30,6 +30,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.TransactionStatus;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -61,7 +62,7 @@ public class SynchronousTests {
|
||||
|
||||
@BeforeTransaction
|
||||
public void onSetUpBeforeTransaction() throws Exception {
|
||||
jdbcTemplate.execute("delete from T_BARS");
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_BARS");
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
final String text = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
@@ -81,11 +82,11 @@ public class SynchronousTests {
|
||||
foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
count++;
|
||||
}
|
||||
jdbcTemplate.execute("delete from T_BARS");
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_BARS");
|
||||
}
|
||||
|
||||
private void assertInitialState() {
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(0, count);
|
||||
}
|
||||
|
||||
@@ -140,7 +141,7 @@ public class SynchronousTests {
|
||||
List<String> msgs = getMessages();
|
||||
|
||||
// The database portion committed once...
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(1, count);
|
||||
|
||||
// ... and so did the message session.
|
||||
@@ -193,7 +194,7 @@ public class SynchronousTests {
|
||||
List<String> msgs = getMessages();
|
||||
|
||||
// The database portion committed once...
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(1, count);
|
||||
|
||||
// ... and so did the message session.
|
||||
@@ -252,7 +253,7 @@ public class SynchronousTests {
|
||||
}
|
||||
|
||||
// The nested database transaction has committed...
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(1, count);
|
||||
|
||||
// force rollback...
|
||||
@@ -267,7 +268,7 @@ public class SynchronousTests {
|
||||
List<String> msgs = getMessages();
|
||||
|
||||
// The database portion rolled back...
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(0, count);
|
||||
|
||||
// ... and so did the message session.
|
||||
@@ -316,7 +317,7 @@ public class SynchronousTests {
|
||||
List<String> msgs = getMessages();
|
||||
|
||||
// The database portion committed once...
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(1, count);
|
||||
|
||||
// ... and so did the message session.
|
||||
@@ -375,7 +376,7 @@ public class SynchronousTests {
|
||||
List<String> msgs = getMessages();
|
||||
|
||||
// The database portion rolled back...
|
||||
int count = jdbcTemplate.queryForObject("select count(*) from T_BARS", Integer.class);
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
assertEquals(0, count);
|
||||
|
||||
// ... and so did the message session.
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.annotation.Repeat;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
/**
|
||||
* This is an abstract test class.
|
||||
@@ -61,7 +62,7 @@ public abstract class AbstractSampleJobTests {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
this.jdbcTemplate.update("drop table TESTS");
|
||||
JdbcTestUtils.dropTables(this.jdbcTemplate, "TESTS");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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.
|
||||
@@ -32,6 +32,7 @@ import org.springframework.context.ApplicationContextAware;
|
||||
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/sample-steps.xml" })
|
||||
@@ -58,7 +59,7 @@ public class SampleStepTests implements ApplicationContextAware {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
this.jdbcTemplate.update("drop table TESTS");
|
||||
JdbcTestUtils.dropTables(this.jdbcTemplate, "TESTS");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user