General cleanup in spring-batch-samples
* Delete unused classes, files, misc ide files * Cleanup checkstyle/pmd/findbugs reports * Add @Override as needed * Remove schema versions in xml configs * Remove unused imports * General tidying * Cleanup deprecated jdbctemplate methods * Fix @Ignored OrderItemReaderTests test
This commit is contained in:
@@ -27,9 +27,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/compositeItemWriterSampleJob.xml", "/job-runner-context.xml" })
|
||||
public class CompositeItemWriterSampleFunctionalTests {
|
||||
|
||||
private static final String GET_TRADES = "SELECT isin, quantity, price, customer FROM TRADE order by isin";
|
||||
|
||||
private static final String EXPECTED_OUTPUT_FILE = "Trade: [isin=UK21341EAH41,quantity=211,price=31.11,customer=customer1]"
|
||||
+ "Trade: [isin=UK21341EAH42,quantity=212,price=32.11,customer=customer2]"
|
||||
+ "Trade: [isin=UK21341EAH43,quantity=213,price=33.11,customer=customer3]"
|
||||
@@ -48,16 +46,14 @@ public class CompositeItemWriterSampleFunctionalTests {
|
||||
|
||||
@Test
|
||||
public void testJobLaunch() throws Exception {
|
||||
|
||||
jdbcTemplate.update("DELETE from TRADE");
|
||||
int before = jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE");
|
||||
int before = jdbcTemplate.queryForObject("SELECT COUNT(*) from TRADE", Integer.class);
|
||||
|
||||
jobLauncherTestUtils.launchJob();
|
||||
|
||||
checkOutputFile("target/test-outputs/CustomerReport1.txt");
|
||||
checkOutputFile("target/test-outputs/CustomerReport2.txt");
|
||||
checkOutputTable(before);
|
||||
|
||||
}
|
||||
|
||||
private void checkOutputTable(int before) {
|
||||
@@ -71,13 +67,14 @@ public class CompositeItemWriterSampleFunctionalTests {
|
||||
}
|
||||
};
|
||||
|
||||
int after = jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE");
|
||||
int after = jdbcTemplate.queryForObject("SELECT COUNT(*) from TRADE", Integer.class);
|
||||
|
||||
assertEquals(before + 5, after);
|
||||
|
||||
|
||||
jdbcTemplate.query(GET_TRADES, new RowCallbackHandler() {
|
||||
private int activeRow = 0;
|
||||
|
||||
@Override
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
Trade trade = trades.get(activeRow++);
|
||||
|
||||
@@ -101,5 +98,4 @@ public class CompositeItemWriterSampleFunctionalTests {
|
||||
|
||||
assertEquals(EXPECTED_OUTPUT_FILE, output);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2012 the original author or authors.
|
||||
* Copyright 2006-2014 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,12 +43,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/customerFilterJob.xml", "/job-runner-context.xml" })
|
||||
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 Map<String, Double> credits = new HashMap<String, Double>();
|
||||
|
||||
@@ -65,7 +62,9 @@ public class CustomerFilterJobFunctionalTests {
|
||||
jdbcTemplate.update("delete from TRADE");
|
||||
jdbcTemplate.update("delete from CUSTOMER where ID > 4");
|
||||
jdbcTemplate.update("update CUSTOMER set credit=100000");
|
||||
|
||||
List<Map<String, Object>> list = jdbcTemplate.queryForList("select name, CREDIT from CUSTOMER");
|
||||
|
||||
for (Map<String, Object> map : list) {
|
||||
credits.put((String) map.get("NAME"), ((Number) map.get("CREDIT")).doubleValue());
|
||||
}
|
||||
@@ -79,17 +78,15 @@ public class CustomerFilterJobFunctionalTests {
|
||||
|
||||
@Test
|
||||
public void testFilterJob() throws Exception {
|
||||
|
||||
JobExecution jobExecution = jobLauncherTestUtils.launchJob();
|
||||
|
||||
customers = Arrays.asList(new Customer("customer1", (credits.get("customer1"))), new Customer("customer2",
|
||||
(credits.get("customer2"))), new Customer("customer3", 100500), new Customer("customer4", credits
|
||||
.get("customer4")), new Customer("customer5", 32345), new Customer("customer6", 123456));
|
||||
|
||||
// check content of the customer table
|
||||
activeRow = 0;
|
||||
jdbcTemplate.query(GET_CUSTOMERS, new RowCallbackHandler() {
|
||||
|
||||
@Override
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
Customer customer = customers.get(activeRow++);
|
||||
assertEquals(customer.getName(), rs.getString(1));
|
||||
@@ -101,7 +98,6 @@ public class CustomerFilterJobFunctionalTests {
|
||||
assertEquals("4", step1Execution.get("READ_COUNT").toString());
|
||||
assertEquals("1", step1Execution.get("FILTER_COUNT").toString());
|
||||
assertEquals("3", step1Execution.get("WRITE_COUNT").toString());
|
||||
|
||||
}
|
||||
|
||||
private Map<String, Object> getStepExecution(JobExecution jobExecution, String stepName) {
|
||||
@@ -174,7 +170,5 @@ public class CustomerFilterJobFunctionalTests {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@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;
|
||||
|
||||
@Autowired
|
||||
@@ -29,16 +27,13 @@ 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");
|
||||
|
||||
jobLauncherTestUtils.launchJob();
|
||||
|
||||
int count = jdbcTemplate.queryForInt("SELECT COUNT(*) from PLAYER_SUMMARY");
|
||||
int count = jdbcTemplate.queryForObject("SELECT COUNT(*) from PLAYER_SUMMARY", Integer.class);
|
||||
assertTrue(count > 0);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,29 +42,21 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/hibernate-context.xml", "/jobs/hibernateJob.xml",
|
||||
"/job-runner-context.xml" })
|
||||
public class HibernateFailureJobFunctionalTests {
|
||||
|
||||
@Autowired
|
||||
private HibernateCreditDao writer;
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
private static final BigDecimal CREDIT_INCREASE = CustomerCreditIncreaseProcessor.FIXED_AMOUNT;
|
||||
|
||||
private static String[] customers = { "INSERT INTO CUSTOMER (id, version, name, credit) VALUES (1, 0, 'customer1', 100000)",
|
||||
"INSERT INTO CUSTOMER (id, version, name, credit) VALUES (2, 0, 'customer2', 100000)",
|
||||
"INSERT INTO CUSTOMER (id, version, name, credit) VALUES (3, 0, 'customer3', 100000)",
|
||||
"INSERT INTO CUSTOMER (id, version, name, credit) VALUES (4, 0, 'customer4', 100000)"};
|
||||
|
||||
private static String DELETE_CUSTOMERS = "DELETE FROM CUSTOMER";
|
||||
|
||||
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)",
|
||||
"INSERT INTO CUSTOMER (id, version, name, credit) VALUES (2, 0, 'customer2', 100000)",
|
||||
"INSERT INTO CUSTOMER (id, version, name, credit) VALUES (3, 0, 'customer3', 100000)",
|
||||
"INSERT INTO CUSTOMER (id, version, name, credit) VALUES (4, 0, 'customer4', 100000)"};
|
||||
|
||||
protected static final String ID_COLUMN = "ID";
|
||||
|
||||
@Autowired
|
||||
private HibernateCreditDao writer;
|
||||
private JdbcOperations jdbcTemplate;
|
||||
private PlatformTransactionManager transactionManager;
|
||||
private List<BigDecimal> creditsBeforeUpdate;
|
||||
|
||||
@Autowired
|
||||
@@ -82,7 +74,6 @@ public class HibernateFailureJobFunctionalTests {
|
||||
|
||||
@Test
|
||||
public void testLaunchJob() throws Exception {
|
||||
|
||||
validatePreConditions();
|
||||
|
||||
JobParameters params = new JobParametersBuilder().addString("key", "failureJob").toJobParameters();
|
||||
@@ -100,11 +91,11 @@ public class HibernateFailureJobFunctionalTests {
|
||||
// assertEquals(1, writer.getErrors().size());
|
||||
throw e;
|
||||
}
|
||||
int after = jdbcTemplate.queryForInt("SELECT COUNT(*) from CUSTOMER");
|
||||
|
||||
int after = jdbcTemplate.queryForObject("SELECT COUNT(*) from CUSTOMER", Integer.class);
|
||||
assertEquals(4, after);
|
||||
|
||||
validatePostConditions();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,8 +105,10 @@ public class HibernateFailureJobFunctionalTests {
|
||||
protected void validatePreConditions() throws Exception {
|
||||
ensureState();
|
||||
creditsBeforeUpdate = (List<BigDecimal>) new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
@Override
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
return jdbcTemplate.query(ALL_CUSTOMERS, new ParameterizedRowMapper<BigDecimal>() {
|
||||
@Override
|
||||
public BigDecimal mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
return rs.getBigDecimal(CREDIT_COLUMN);
|
||||
}
|
||||
@@ -129,32 +122,31 @@ public class HibernateFailureJobFunctionalTests {
|
||||
* customer table and reading the expected defaults.
|
||||
*/
|
||||
private void ensureState(){
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback(){
|
||||
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
@Override
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
jdbcTemplate.update(DELETE_CUSTOMERS);
|
||||
jdbcTemplate.update(DELETE_CUSTOMERS);
|
||||
for (String customer : customers) {
|
||||
jdbcTemplate.update(customer);
|
||||
jdbcTemplate.update(customer);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Credit was increased by CREDIT_INCREASE
|
||||
*/
|
||||
protected void validatePostConditions() throws Exception {
|
||||
|
||||
final List<BigDecimal> matches = new ArrayList<BigDecimal>();
|
||||
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
@Override
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
jdbcTemplate.query(ALL_CUSTOMERS, new RowCallbackHandler() {
|
||||
|
||||
private int i = 0;
|
||||
|
||||
@Override
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
final BigDecimal creditBeforeUpdate = creditsBeforeUpdate.get(i++);
|
||||
final BigDecimal expectedCredit = creditBeforeUpdate.add(CREDIT_INCREASE);
|
||||
@@ -164,6 +156,7 @@ public class HibernateFailureJobFunctionalTests {
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -26,8 +26,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/infiniteLoopJob.xml" })
|
||||
public class JobOperatorFunctionalTests {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(JobOperatorFunctionalTests.class);
|
||||
private static final Log LOG = LogFactory.getLog(JobOperatorFunctionalTests.class);
|
||||
|
||||
@Autowired
|
||||
private JobOperator operator;
|
||||
@@ -47,7 +46,6 @@ public class JobOperatorFunctionalTests {
|
||||
|
||||
@Test
|
||||
public void testStartStopResumeJob() throws Exception {
|
||||
|
||||
String params = new JobParametersBuilder().addLong("jobOperatorTestParam", 7L).toJobParameters().toString();
|
||||
|
||||
long executionId = operator.start(job.getName(), params);
|
||||
@@ -67,14 +65,12 @@ public class JobOperatorFunctionalTests {
|
||||
// latest execution is the first in the returned list
|
||||
assertEquals(resumedExecutionId, executions.get(0).longValue());
|
||||
assertEquals(executionId, executions.get(1).longValue());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param executionId id of running job execution
|
||||
*/
|
||||
private void stopAndCheckStatus(long executionId) throws Exception {
|
||||
|
||||
// wait to the job to get up and running
|
||||
Thread.sleep(1000);
|
||||
|
||||
@@ -88,7 +84,7 @@ public class JobOperatorFunctionalTests {
|
||||
|
||||
int count = 0;
|
||||
while (operator.getRunningExecutions(job.getName()).contains(executionId) && count <= 10) {
|
||||
logger.info("Checking for running JobExecution: count=" + count);
|
||||
LOG.info("Checking for running JobExecution: count=" + count);
|
||||
Thread.sleep(100);
|
||||
count++;
|
||||
}
|
||||
@@ -101,7 +97,7 @@ public class JobOperatorFunctionalTests {
|
||||
|
||||
// there is just a single step in the test job
|
||||
Map<Long, String> summaries = operator.getStepExecutionSummaries(executionId);
|
||||
System.err.println(summaries);
|
||||
LOG.info(summaries);
|
||||
assertTrue(summaries.values().toString().contains(BatchStatus.STOPPED.toString()));
|
||||
}
|
||||
|
||||
@@ -117,24 +113,25 @@ public class JobOperatorFunctionalTests {
|
||||
long exec2 = operator.startNextInstance(jobName);
|
||||
|
||||
assertTrue(exec1 != exec2);
|
||||
assertTrue(operator.getParameters(exec1) != operator.getParameters(exec2));
|
||||
assertTrue(!operator.getParameters(exec1).equals(operator.getParameters(exec2)));
|
||||
|
||||
Set<Long> executions = operator.getRunningExecutions(jobName);
|
||||
assertTrue(executions.contains(exec1));
|
||||
assertTrue(executions.contains(exec2));
|
||||
|
||||
int count = 0;
|
||||
boolean running = operator.getSummary(exec1).contains("STARTED")
|
||||
&& operator.getSummary(exec2).contains("STARTED");
|
||||
|
||||
while (count++ < 10 && !running) {
|
||||
Thread.sleep(100L);
|
||||
running = operator.getSummary(exec1).contains("STARTED") && operator.getSummary(exec2).contains("STARTED");
|
||||
}
|
||||
|
||||
assertTrue(String.format("Jobs not started: [%s] and [%s]", operator.getSummary(exec1), operator
|
||||
.getSummary(exec1)), running);
|
||||
|
||||
operator.stop(exec1);
|
||||
operator.stop(exec2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2012 the original author or authors.
|
||||
* Copyright 2006-2014 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,11 +39,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class JobStepFunctionalTests {
|
||||
|
||||
@Autowired
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
// auto-injected attributes
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
@@ -53,16 +50,13 @@ public class JobStepFunctionalTests {
|
||||
|
||||
@Test
|
||||
public void testJobLaunch() throws Exception {
|
||||
|
||||
jdbcTemplate.update("DELETE FROM 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.queryForInt("SELECT COUNT(*) FROM TRADE");
|
||||
int after = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM TRADE", Integer.class);
|
||||
assertEquals(5, after);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2014 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.
|
||||
@@ -46,16 +46,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/partitionFileJob.xml",
|
||||
"/job-runner-context.xml" })
|
||||
public class PartitionFileJobFunctionalTests implements ApplicationContextAware {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("inputTestReader")
|
||||
private ItemReader<CustomerCredit> inputReader;
|
||||
|
||||
@Autowired
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
@@ -66,7 +65,6 @@ public class PartitionFileJobFunctionalTests implements ApplicationContextAware
|
||||
*/
|
||||
@Test
|
||||
public void testUpdateCredit() throws Exception {
|
||||
|
||||
assertTrue("Define a prototype bean called 'outputTestReader' to check the output", applicationContext
|
||||
.containsBeanDefinition("outputTestReader"));
|
||||
|
||||
@@ -93,7 +91,6 @@ public class PartitionFileJobFunctionalTests implements ApplicationContextAware
|
||||
assertEquals(inputs.get(i).getCredit().add(CustomerCreditIncreaseProcessor.FIXED_AMOUNT).intValue(),
|
||||
outputs.get(i).getCredit().intValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,11 +99,12 @@ public class PartitionFileJobFunctionalTests implements ApplicationContextAware
|
||||
private Set<CustomerCredit> getCredits(ItemReader<CustomerCredit> reader) throws Exception {
|
||||
CustomerCredit credit;
|
||||
Set<CustomerCredit> result = new LinkedHashSet<CustomerCredit>();
|
||||
|
||||
while ((credit = reader.read()) != null) {
|
||||
result.add(credit);
|
||||
}
|
||||
return result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,5 +124,4 @@ public class PartitionFileJobFunctionalTests implements ApplicationContextAware
|
||||
((ItemStream) reader).close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2014 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.
|
||||
@@ -46,16 +46,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/partitionJdbcJob.xml",
|
||||
"/job-runner-context.xml" })
|
||||
public class PartitionJdbcJobFunctionalTests implements ApplicationContextAware {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("inputTestReader")
|
||||
private ItemReader<CustomerCredit> inputReader;
|
||||
|
||||
@Autowired
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
@@ -66,7 +65,6 @@ public class PartitionJdbcJobFunctionalTests implements ApplicationContextAware
|
||||
*/
|
||||
@Test
|
||||
public void testUpdateCredit() throws Exception {
|
||||
|
||||
assertTrue("Define a prototype bean called 'outputTestReader' to check the output", applicationContext
|
||||
.containsBeanDefinition("outputTestReader"));
|
||||
|
||||
@@ -93,7 +91,6 @@ public class PartitionJdbcJobFunctionalTests implements ApplicationContextAware
|
||||
assertEquals(inputs.get(i).getCredit().add(CustomerCreditIncreaseProcessor.FIXED_AMOUNT).intValue(),
|
||||
outputs.get(i).getCredit().intValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,5 +123,4 @@ public class PartitionJdbcJobFunctionalTests implements ApplicationContextAware
|
||||
((ItemStream) reader).close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2012 the original author or authors.
|
||||
* Copyright 2006-2014 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.
|
||||
@@ -44,13 +44,11 @@ import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/restartSample.xml",
|
||||
"/job-runner-context.xml" })
|
||||
public class RestartFunctionalTests {
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
// auto-injected attributes
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
@@ -72,8 +70,7 @@ public class RestartFunctionalTests {
|
||||
*/
|
||||
@Test
|
||||
public void testLaunchJob() throws Exception {
|
||||
|
||||
int before = jdbcTemplate.queryForInt("SELECT COUNT(*) FROM TRADE");
|
||||
int before = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM TRADE", Integer.class);
|
||||
|
||||
JobExecution jobExecution = runJobForRestartTest();
|
||||
assertEquals(BatchStatus.FAILED, jobExecution.getStatus());
|
||||
@@ -86,14 +83,14 @@ public class RestartFunctionalTests {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
int medium = jdbcTemplate.queryForInt("SELECT COUNT(*) FROM TRADE");
|
||||
int medium = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM TRADE", Integer.class);
|
||||
// assert based on commit interval = 2
|
||||
assertEquals(before + 2, medium);
|
||||
|
||||
jobExecution = runJobForRestartTest();
|
||||
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
|
||||
|
||||
int after = jdbcTemplate.queryForInt("SELECT COUNT(*) FROM TRADE");
|
||||
int after = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM TRADE", Integer.class);
|
||||
|
||||
assertEquals(before + 5, after);
|
||||
}
|
||||
@@ -105,5 +102,4 @@ public class RestartFunctionalTests {
|
||||
.getJobParameters(PropertiesConverter
|
||||
.stringToProperties("run.id(long)=1,parameter=true,run.date=20070122,input.file=classpath:data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2009 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
/**
|
||||
* Temporary test suite to find bug in build....
|
||||
*
|
||||
*/
|
||||
@Ignore
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({SkipSampleFunctionalTests.class, CustomerFilterJobFunctionalTests.class})
|
||||
public class TestSuite {
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2012 the original author or authors.
|
||||
* Copyright 2006-2014 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.
|
||||
@@ -46,14 +46,12 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/tradeJob.xml",
|
||||
"/job-runner-context.xml" })
|
||||
public class TradeJobFunctionalTests {
|
||||
|
||||
private static final String GET_TRADES = "select ISIN, QUANTITY, PRICE, CUSTOMER, ID, VERSION from TRADE order by ISIN";
|
||||
private static final String GET_CUSTOMERS = "select NAME, CREDIT from CUSTOMER order by NAME";
|
||||
|
||||
private List<Customer> customers;
|
||||
private List<Trade> trades;
|
||||
private int activeRow = 0;
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
private Map<String, Double> credits = new HashMap<String, Double>();
|
||||
|
||||
@@ -69,6 +67,7 @@ public class TradeJobFunctionalTests {
|
||||
public void onSetUp() throws Exception {
|
||||
jdbcTemplate.update("delete from TRADE");
|
||||
List<Map<String, Object>> list = jdbcTemplate.queryForList("select NAME, CREDIT from CUSTOMER");
|
||||
|
||||
for (Map<String, Object> map : list) {
|
||||
credits.put((String) map.get("NAME"), ((Number) map.get("CREDIT")).doubleValue());
|
||||
}
|
||||
@@ -81,7 +80,6 @@ public class TradeJobFunctionalTests {
|
||||
|
||||
@Test
|
||||
public void testLaunchJob() throws Exception {
|
||||
|
||||
jobLauncherTestUtils.launchJob();
|
||||
|
||||
customers = Arrays.asList(new Customer("customer1", (credits.get("customer1") - 98.34)),
|
||||
@@ -95,9 +93,8 @@ public class TradeJobFunctionalTests {
|
||||
new Trade("UK21341EAH48", 108, new BigDecimal("109.25"), "customer3"),
|
||||
new Trade("UK21341EAH49", 854, new BigDecimal("123.39"), "customer4"));
|
||||
|
||||
// check content of the trade table
|
||||
jdbcTemplate.query(GET_TRADES, new RowCallbackHandler() {
|
||||
|
||||
@Override
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
Trade trade = trades.get(activeRow++);
|
||||
|
||||
@@ -110,10 +107,9 @@ public class TradeJobFunctionalTests {
|
||||
|
||||
assertEquals(activeRow, trades.size());
|
||||
|
||||
// check content of the customer table
|
||||
activeRow = 0;
|
||||
jdbcTemplate.query(GET_CUSTOMERS, new RowCallbackHandler() {
|
||||
|
||||
@Override
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
Customer customer = customers.get(activeRow++);
|
||||
|
||||
@@ -123,8 +119,6 @@ public class TradeJobFunctionalTests {
|
||||
});
|
||||
|
||||
assertEquals(customers.size(), activeRow);
|
||||
|
||||
// check content of the output file
|
||||
}
|
||||
|
||||
private static class Customer {
|
||||
@@ -179,9 +173,5 @@ public class TradeJobFunctionalTests {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2008 the original author or authors.
|
||||
* Copyright 2006-2014 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,8 +27,6 @@ import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ItemStreamException;
|
||||
import org.springframework.batch.item.ParseException;
|
||||
import org.springframework.batch.item.UnexpectedInputException;
|
||||
|
||||
/**
|
||||
* Unit test class that was used as part of the Reference Documentation. I'm only including it in the
|
||||
@@ -38,15 +36,13 @@ import org.springframework.batch.item.UnexpectedInputException;
|
||||
*
|
||||
*/
|
||||
public class CustomItemReaderTests {
|
||||
|
||||
ItemReader<String> itemReader;
|
||||
private ItemReader<String> itemReader;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see junit.framework.TestCase#setUp()
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
List<String> items = new ArrayList<String>();
|
||||
items.add("1");
|
||||
items.add("2");
|
||||
@@ -57,7 +53,6 @@ public class CustomItemReaderTests {
|
||||
|
||||
@Test
|
||||
public void testRead() throws Exception{
|
||||
|
||||
assertEquals("1", itemReader.read());
|
||||
assertEquals("2", itemReader.read());
|
||||
assertEquals("3", itemReader.read());
|
||||
@@ -66,7 +61,6 @@ public class CustomItemReaderTests {
|
||||
|
||||
@Test
|
||||
public void testRestart() throws Exception{
|
||||
|
||||
ExecutionContext executionContext = new ExecutionContext();
|
||||
((ItemStream)itemReader).open(executionContext);
|
||||
assertEquals("1", itemReader.read());
|
||||
@@ -82,24 +76,24 @@ public class CustomItemReaderTests {
|
||||
}
|
||||
|
||||
public static class CustomItemReader<T> implements ItemReader<T>, ItemStream {
|
||||
|
||||
List<T> items;
|
||||
int currentIndex = 0;
|
||||
private static final String CURRENT_INDEX = "current.index";
|
||||
|
||||
|
||||
private List<T> items;
|
||||
private int currentIndex = 0;
|
||||
|
||||
public CustomItemReader(List<T> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public T read() throws Exception, UnexpectedInputException,
|
||||
ParseException {
|
||||
|
||||
@Override
|
||||
public T read() throws Exception {
|
||||
if (currentIndex < items.size()) {
|
||||
return items.get(currentIndex++);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void open(ExecutionContext executionContext) throws ItemStreamException {
|
||||
if(executionContext.containsKey(CURRENT_INDEX)){
|
||||
currentIndex = executionContext.getInt(CURRENT_INDEX);
|
||||
@@ -109,11 +103,12 @@ public class CustomItemReaderTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws ItemStreamException {}
|
||||
|
||||
@Override
|
||||
public void update(ExecutionContext executionContext) throws ItemStreamException {
|
||||
executionContext.putInt(CURRENT_INDEX, currentIndex);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2008 the original author or authors.
|
||||
* Copyright 2006-2014 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.
|
||||
@@ -34,21 +34,19 @@ import org.springframework.batch.support.transaction.TransactionAwareProxyFactor
|
||||
*
|
||||
*/
|
||||
public class CustomItemWriterTests {
|
||||
|
||||
@Test
|
||||
public void testFlush() throws Exception {
|
||||
|
||||
CustomItemWriter<String> itemWriter = new CustomItemWriter<String>();
|
||||
itemWriter.write(Collections.singletonList("1"));
|
||||
assertEquals(1, itemWriter.getOutput().size());
|
||||
itemWriter.write(Arrays.asList(new String[] {"2","3"}));
|
||||
itemWriter.write(Arrays.asList("2","3"));
|
||||
assertEquals(3, itemWriter.getOutput().size());
|
||||
}
|
||||
|
||||
public static class CustomItemWriter<T> implements ItemWriter<T> {
|
||||
private List<T> output = TransactionAwareProxyFactory.createTransactionalList();
|
||||
|
||||
List<T> output = TransactionAwareProxyFactory.createTransactionalList();
|
||||
|
||||
@Override
|
||||
public void write(List<? extends T> items) throws Exception {
|
||||
output.addAll(items);
|
||||
}
|
||||
|
||||
@@ -20,15 +20,9 @@ import org.springframework.util.Assert;
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ErrorLogTasklet implements Tasklet, StepExecutionListener {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
private String jobName;
|
||||
|
||||
private StepExecution stepExecution;
|
||||
|
||||
private String stepName;
|
||||
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
@@ -58,6 +52,7 @@ public class ErrorLogTasklet implements Tasklet, StepExecutionListener {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeStep(StepExecution stepExecution) {
|
||||
this.jobName = stepExecution.getJobExecution().getJobInstance().getJobName().trim();
|
||||
this.stepName = (String) stepExecution.getJobExecution().getExecutionContext().get("stepName");
|
||||
@@ -65,8 +60,8 @@ public class ErrorLogTasklet implements Tasklet, StepExecutionListener {
|
||||
stepExecution.getJobExecution().getExecutionContext().remove("stepName");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
|
||||
public class OutputFileListenerTests {
|
||||
|
||||
private OutputFileListener listener = new OutputFileListener();
|
||||
private StepExecution stepExecution = new StepExecution("foo", new JobExecution(0L), 1L);
|
||||
|
||||
@@ -40,5 +39,4 @@ public class OutputFileListenerTests {
|
||||
listener.createOutputNameFromInput(stepExecution);
|
||||
assertEquals("bar.csv", stepExecution.getExecutionContext().getString("outputFile"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.springframework.batch.core.job.flow.FlowExecutionStatus;
|
||||
import org.springframework.batch.core.job.flow.JobExecutionDecider;
|
||||
|
||||
public class SkipCheckingDecider implements JobExecutionDecider {
|
||||
|
||||
@Override
|
||||
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
|
||||
if (!stepExecution.getExitStatus().getExitCode().equals(
|
||||
ExitStatus.FAILED.getExitCode())
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration()
|
||||
public class StagingItemReaderTests {
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
@@ -54,7 +53,7 @@ public class StagingItemReaderTests {
|
||||
StepExecution stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance(jobId,
|
||||
"testJob"), new JobParameters()));
|
||||
writer.beforeStep(stepExecution);
|
||||
writer.write(Arrays.asList(new String[] { "FOO", "BAR", "SPAM", "BUCKET" }));
|
||||
writer.write(Arrays.asList("FOO", "BAR", "SPAM", "BUCKET"));
|
||||
reader.beforeStep(stepExecution);
|
||||
}
|
||||
|
||||
@@ -67,8 +66,7 @@ public class StagingItemReaderTests {
|
||||
@Transactional
|
||||
@Test
|
||||
public void testReaderWithProcessorUpdatesProcessIndicator() throws Exception {
|
||||
|
||||
long id = jdbcTemplate.queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", jobId);
|
||||
long id = jdbcTemplate.queryForObject("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", Long.class, jobId);
|
||||
String before = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
String.class, id);
|
||||
assertEquals(StagingItemWriter.NEW, before);
|
||||
@@ -84,7 +82,6 @@ public class StagingItemReaderTests {
|
||||
String after = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
String.class, id);
|
||||
assertEquals(StagingItemWriter.DONE, after);
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -103,7 +100,7 @@ public class StagingItemReaderTests {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
long id = jdbcTemplate.queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", jobId);
|
||||
long id = jdbcTemplate.queryForObject("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", Long.class, jobId);
|
||||
String before = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
String.class, id);
|
||||
assertEquals(StagingItemWriter.DONE, before);
|
||||
@@ -112,14 +109,13 @@ public class StagingItemReaderTests {
|
||||
@Transactional
|
||||
@Test
|
||||
public void testReaderRollsBackProcessIndicator() throws Exception {
|
||||
|
||||
TransactionTemplate txTemplate = new TransactionTemplate(transactionManager);
|
||||
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||
|
||||
final Long idToUse = (Long) txTemplate.execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus transactionStatus) {
|
||||
|
||||
long id = jdbcTemplate.queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", jobId);
|
||||
long id = jdbcTemplate.queryForObject("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", Long.class, jobId);
|
||||
String before = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
String.class, id);
|
||||
assertEquals(StagingItemWriter.NEW, before);
|
||||
@@ -136,6 +132,5 @@ public class StagingItemReaderTests {
|
||||
String after = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
String.class, idToUse);
|
||||
assertEquals(StagingItemWriter.NEW, after);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2012 the original author or authors.
|
||||
* Copyright 2006-2014 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,7 +38,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class StagingItemWriterTests {
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
@@ -59,10 +58,10 @@ public class StagingItemWriterTests {
|
||||
@Transactional
|
||||
@Test
|
||||
public void testProcessInsertsNewItem() throws Exception {
|
||||
int before = jdbcTemplate.queryForInt("SELECT COUNT(*) from BATCH_STAGING");
|
||||
int before = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STAGING", Integer.class);
|
||||
writer.write(Collections.singletonList("FOO"));
|
||||
int after = jdbcTemplate.queryForInt("SELECT COUNT(*) from BATCH_STAGING");
|
||||
|
||||
int after = jdbcTemplate.queryForObject("SELECT COUNT(*) from BATCH_STAGING", Integer.class);
|
||||
assertEquals(before + 1, after);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2012 the original author or authors.
|
||||
* Copyright 2006-2014 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.
|
||||
@@ -42,11 +42,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = {"/data-source-context.xml"})
|
||||
public class JdbcGameDaoIntegrationTests {
|
||||
|
||||
private JdbcGameDao gameDao;
|
||||
|
||||
private Game game = new Game();
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
@@ -59,7 +56,6 @@ public class JdbcGameDaoIntegrationTests {
|
||||
|
||||
@Before
|
||||
public void onSetUpBeforeTransaction() throws Exception {
|
||||
|
||||
game.setId("XXXXX00");
|
||||
game.setYear(1996);
|
||||
game.setTeam("mia");
|
||||
@@ -75,12 +71,10 @@ public class JdbcGameDaoIntegrationTests {
|
||||
game.setReceptions(1);
|
||||
game.setReceptionYards(16);
|
||||
game.setTotalTd(2);
|
||||
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
public void testWrite() {
|
||||
|
||||
gameDao.write(Collections.singletonList(game));
|
||||
|
||||
Game tempGame = jdbcTemplate.queryForObject("SELECT * FROM GAMES where PLAYER_ID=? AND YEAR_NO=?",
|
||||
@@ -89,9 +83,8 @@ public class JdbcGameDaoIntegrationTests {
|
||||
}
|
||||
|
||||
private static class GameRowMapper implements ParameterizedRowMapper<Game> {
|
||||
|
||||
@Override
|
||||
public Game mapRow(ResultSet rs, int arg1) throws SQLException {
|
||||
|
||||
if (rs == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2012 the original author or authors.
|
||||
* Copyright 2006-2014 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,18 +41,13 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = {"/data-source-context.xml"})
|
||||
public class JdbcPlayerDaoIntegrationTests {
|
||||
|
||||
private JdbcPlayerDao playerDao;
|
||||
|
||||
private Player player;
|
||||
|
||||
private static final String GET_PLAYER = "SELECT * from PLAYERS";
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public void init(DataSource dataSource) {
|
||||
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
playerDao = new JdbcPlayerDao();
|
||||
playerDao.setDataSource(dataSource);
|
||||
@@ -64,24 +59,19 @@ public class JdbcPlayerDaoIntegrationTests {
|
||||
player.setPosition("QB");
|
||||
player.setBirthYear(1975);
|
||||
player.setDebutYear(1998);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void onSetUpInTransaction() throws Exception {
|
||||
|
||||
jdbcTemplate.execute("delete from PLAYERS");
|
||||
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
@Test
|
||||
@Transactional
|
||||
public void testSavePlayer(){
|
||||
|
||||
playerDao.savePlayer(player);
|
||||
|
||||
jdbcTemplate.query(GET_PLAYER, new RowCallbackHandler(){
|
||||
|
||||
jdbcTemplate.query(GET_PLAYER, new RowCallbackHandler() {
|
||||
@Override
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
assertEquals(rs.getString("PLAYER_ID"), "AKFJDL00");
|
||||
assertEquals(rs.getString("LAST_NAME"), "Doe");
|
||||
@@ -92,5 +82,4 @@ public class JdbcPlayerDaoIntegrationTests {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2012 the original author or authors.
|
||||
* Copyright 2006-2014 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,16 +39,12 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "/data-source-context.xml" })
|
||||
public class JdbcPlayerSummaryDaoIntegrationTests {
|
||||
|
||||
private JdbcPlayerSummaryDao playerSummaryDao;
|
||||
|
||||
private PlayerSummary summary;
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public void init(DataSource dataSource) {
|
||||
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
playerSummaryDao = new JdbcPlayerSummaryDao();
|
||||
playerSummaryDao.setDataSource(dataSource);
|
||||
@@ -66,27 +62,21 @@ public class JdbcPlayerSummaryDaoIntegrationTests {
|
||||
summary.setReceptions(0);
|
||||
summary.setReceptionYards(0);
|
||||
summary.setTotalTd(0);
|
||||
|
||||
}
|
||||
|
||||
@Before
|
||||
public void onSetUpInTransaction() throws Exception {
|
||||
|
||||
jdbcTemplate.execute("delete from PLAYER_SUMMARY");
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test
|
||||
@Transactional
|
||||
public void testWrite() {
|
||||
|
||||
playerSummaryDao.write(Collections.singletonList(summary));
|
||||
|
||||
PlayerSummary testSummary = jdbcTemplate.queryForObject("SELECT * FROM PLAYER_SUMMARY",
|
||||
new PlayerSummaryMapper());
|
||||
|
||||
assertEquals(summary, testSummary);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,10 +9,8 @@ import org.junit.Test;
|
||||
import org.springframework.batch.item.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.item.file.transform.DefaultFieldSet;
|
||||
import org.springframework.batch.item.file.transform.FieldSet;
|
||||
import org.springframework.batch.sample.domain.multiline.AggregateItemFieldSetMapper;
|
||||
|
||||
public class AggregateItemFieldSetMapperTests {
|
||||
|
||||
private AggregateItemFieldSetMapper<String> mapper = new AggregateItemFieldSetMapper<String>();
|
||||
|
||||
@Test
|
||||
@@ -59,6 +57,4 @@ public class AggregateItemFieldSetMapperTests {
|
||||
});
|
||||
assertEquals("foo", mapper.mapFieldSet(new DefaultFieldSet(new String[] { "FOO" })).getItem());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,22 +6,17 @@ import java.util.Collection;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.sample.domain.multiline.AggregateItem;
|
||||
import org.springframework.batch.sample.domain.multiline.AggregateItemReader;
|
||||
|
||||
public class AggregateItemReaderTests {
|
||||
|
||||
private ItemReader<AggregateItem<String>> input;
|
||||
|
||||
private AggregateItemReader<String> provider;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// create mock for input
|
||||
input = new ItemReader<AggregateItem<String>>() {
|
||||
|
||||
private int count = 0;
|
||||
|
||||
@Override
|
||||
public AggregateItem<String> read() {
|
||||
switch (count++) {
|
||||
case 0:
|
||||
@@ -38,17 +33,15 @@ public class AggregateItemReaderTests {
|
||||
}
|
||||
|
||||
};
|
||||
// create provider
|
||||
|
||||
provider = new AggregateItemReader<String>();
|
||||
provider.setItemReader(input);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNext() throws Exception {
|
||||
// read object
|
||||
Object result = provider.read();
|
||||
|
||||
// it should be collection of 3 strings "line"
|
||||
Collection<?> lines = (Collection<?>) result;
|
||||
assertEquals(3, lines.size());
|
||||
|
||||
@@ -56,9 +49,6 @@ public class AggregateItemReaderTests {
|
||||
assertEquals("line", line);
|
||||
}
|
||||
|
||||
// read object again - it should return null
|
||||
assertNull(provider.read());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2014 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.
|
||||
@@ -20,14 +20,12 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.sample.domain.multiline.AggregateItem;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class AggregateItemTests {
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.sample.domain.multiline.AggregateItem#getFooter()}.
|
||||
*/
|
||||
@@ -65,5 +63,4 @@ public class AggregateItemTests {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.springframework.batch.sample.domain.order.internal.mapper.AddressFiel
|
||||
import org.springframework.batch.sample.support.AbstractFieldSetMapperTests;
|
||||
|
||||
public class AddressFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
|
||||
private static final String ADDRESSEE = "Jan Hrach";
|
||||
private static final String ADDRESS_LINE_1 = "Plynarenska 7c";
|
||||
private static final String ADDRESS_LINE_2 = "";
|
||||
@@ -16,6 +15,7 @@ public class AddressFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
private static final String COUNTRY = "Slovakia";
|
||||
private static final String ZIP_CODE = "80000";
|
||||
|
||||
@Override
|
||||
protected Object expectedDomainObject() {
|
||||
Address address = new Address();
|
||||
address.setAddressee(ADDRESSEE);
|
||||
@@ -28,6 +28,7 @@ public class AddressFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
return address;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens = new String[] { ADDRESSEE, ADDRESS_LINE_1, ADDRESS_LINE_2, CITY, STATE, COUNTRY, ZIP_CODE };
|
||||
String[] columnNames = new String[] { AddressFieldSetMapper.ADDRESSEE_COLUMN,
|
||||
@@ -38,6 +39,7 @@ public class AddressFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FieldSetMapper<Address> fieldSetMapper() {
|
||||
return new AddressFieldSetMapper();
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ import org.springframework.batch.sample.domain.order.internal.mapper.BillingFiel
|
||||
import org.springframework.batch.sample.support.AbstractFieldSetMapperTests;
|
||||
|
||||
public class BillingFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
|
||||
private static final String PAYMENT_ID = "777";
|
||||
private static final String PAYMENT_DESC = "My last penny";
|
||||
|
||||
@Override
|
||||
protected Object expectedDomainObject() {
|
||||
BillingInfo bInfo = new BillingInfo();
|
||||
bInfo.setPaymentDesc(PAYMENT_DESC);
|
||||
@@ -18,6 +18,7 @@ public class BillingFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
return bInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens = new String[] { PAYMENT_ID, PAYMENT_DESC };
|
||||
String[] columnNames = new String[] { BillingFieldSetMapper.PAYMENT_TYPE_ID_COLUMN,
|
||||
@@ -25,8 +26,8 @@ public class BillingFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FieldSetMapper<BillingInfo> fieldSetMapper() {
|
||||
return new BillingFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.springframework.batch.sample.domain.order.internal.mapper.CustomerFie
|
||||
import org.springframework.batch.sample.support.AbstractFieldSetMapperTests;
|
||||
|
||||
public class CustomerFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
|
||||
private static final boolean BUSINESS_CUSTOMER = false;
|
||||
private static final String FIRST_NAME = "Jan";
|
||||
private static final String LAST_NAME = "Hrach";
|
||||
@@ -16,6 +15,7 @@ public class CustomerFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
private static final long REG_ID = 1;
|
||||
private static final boolean VIP = true;
|
||||
|
||||
@Override
|
||||
protected Object expectedDomainObject() {
|
||||
Customer cs = new Customer();
|
||||
cs.setBusinessCustomer(BUSINESS_CUSTOMER);
|
||||
@@ -28,6 +28,7 @@ public class CustomerFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
return cs;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens = new String[] { Customer.LINE_ID_NON_BUSINESS_CUST, FIRST_NAME, LAST_NAME, MIDDLE_NAME,
|
||||
CustomerFieldSetMapper.TRUE_SYMBOL, String.valueOf(REG_ID), CustomerFieldSetMapper.TRUE_SYMBOL };
|
||||
@@ -39,8 +40,8 @@ public class CustomerFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FieldSetMapper<Customer> fieldSetMapper() {
|
||||
return new CustomerFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ import org.springframework.batch.sample.domain.order.internal.mapper.HeaderField
|
||||
import org.springframework.batch.sample.support.AbstractFieldSetMapperTests;
|
||||
|
||||
public class HeaderFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
|
||||
private static final long ORDER_ID = 1;
|
||||
private static final String DATE = "2007-01-01";
|
||||
|
||||
@Override
|
||||
protected Object expectedDomainObject() {
|
||||
Order order = new Order();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
@@ -23,6 +23,7 @@ public class HeaderFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
return order;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens = new String[] { String.valueOf(ORDER_ID), DATE };
|
||||
String[] columnNames = new String[] { HeaderFieldSetMapper.ORDER_ID_COLUMN,
|
||||
@@ -30,8 +31,8 @@ public class HeaderFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FieldSetMapper<Order> fieldSetMapper() {
|
||||
return new HeaderFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.springframework.batch.sample.domain.order.internal.mapper.OrderItemFi
|
||||
import org.springframework.batch.sample.support.AbstractFieldSetMapperTests;
|
||||
|
||||
public class OrderItemFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
|
||||
private static final BigDecimal DISCOUNT_AMOUNT = new BigDecimal("1");
|
||||
private static final BigDecimal DISCOUNT_PERC = new BigDecimal("2");
|
||||
private static final BigDecimal HANDLING_PRICE = new BigDecimal("3");
|
||||
@@ -19,6 +18,7 @@ public class OrderItemFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
private static final BigDecimal SHIPPING_PRICE = new BigDecimal("7");
|
||||
private static final BigDecimal TOTAL_PRICE = new BigDecimal("8");
|
||||
|
||||
@Override
|
||||
protected Object expectedDomainObject() {
|
||||
LineItem item = new LineItem();
|
||||
item.setDiscountAmount(DISCOUNT_AMOUNT);
|
||||
@@ -32,6 +32,7 @@ public class OrderItemFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens = new String[] { String.valueOf(DISCOUNT_AMOUNT), String.valueOf(DISCOUNT_PERC),
|
||||
String.valueOf(HANDLING_PRICE), String.valueOf(ITEM_ID), String.valueOf(PRICE),
|
||||
@@ -44,8 +45,8 @@ public class OrderItemFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FieldSetMapper<LineItem> fieldSetMapper() {
|
||||
return new OrderItemFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,10 +7,7 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.file.mapping.FieldSetMapper;
|
||||
@@ -19,15 +16,12 @@ import org.springframework.batch.item.file.transform.FieldSet;
|
||||
import org.springframework.batch.sample.domain.order.internal.OrderItemReader;
|
||||
|
||||
public class OrderItemReaderTests {
|
||||
|
||||
private OrderItemReader provider;
|
||||
|
||||
private ItemReader<FieldSet> input;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUp() {
|
||||
|
||||
input = (ItemReader<FieldSet>) mock(ItemReader.class);
|
||||
|
||||
provider = new OrderItemReader();
|
||||
@@ -35,7 +29,7 @@ public class OrderItemReaderTests {
|
||||
}
|
||||
|
||||
/*
|
||||
* OrderItemProvider is resposible for retrieving validated value object
|
||||
* OrderItemProvider is responsible for retrieving validated value object
|
||||
* from input source. OrderItemProvider.next(): - reads lines from the input
|
||||
* source - returned as fieldsets - pass fieldsets to the mapper - mapper
|
||||
* will create value object - pass value object to validator - returns
|
||||
@@ -44,12 +38,9 @@ public class OrderItemReaderTests {
|
||||
* In testNext method we are going to test these responsibilities. So we
|
||||
* need create mock objects for input source, mapper and validator.
|
||||
*/
|
||||
@Ignore //TODO mockito fix
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testNext() throws Exception {
|
||||
|
||||
// create fieldsets and set return values for input source
|
||||
FieldSet headerFS = new DefaultFieldSet(new String[] { Order.LINE_ID_HEADER });
|
||||
FieldSet customerFS = new DefaultFieldSet(new String[] { Customer.LINE_ID_NON_BUSINESS_CUST });
|
||||
FieldSet billingFS = new DefaultFieldSet(new String[] { Address.LINE_ID_BILLING_ADDR });
|
||||
@@ -60,19 +51,9 @@ public class OrderItemReaderTests {
|
||||
FieldSet footerFS = new DefaultFieldSet(new String[] { Order.LINE_ID_FOOTER, "100", "3", "3" }, new String[] {
|
||||
"ID", "TOTAL_PRICE", "TOTAL_LINE_ITEMS", "TOTAL_ITEMS" });
|
||||
|
||||
when(input.read()).thenReturn(headerFS);
|
||||
when(input.read()).thenReturn(customerFS);
|
||||
when(input.read()).thenReturn(billingFS);
|
||||
when(input.read()).thenReturn(shippingFS);
|
||||
when(input.read()).thenReturn(billingInfoFS);
|
||||
when(input.read()).thenReturn(shippingInfoFS);
|
||||
when(input.read()).thenReturn(itemFS);
|
||||
when(input.read()).thenReturn(footerFS);
|
||||
when(input.read()).thenReturn(null);
|
||||
// replay(input);
|
||||
// input.read();
|
||||
when(input.read()).thenReturn(headerFS, customerFS, billingFS, shippingFS, billingInfoFS,
|
||||
shippingInfoFS, itemFS, itemFS, itemFS, footerFS, null);
|
||||
|
||||
// create value objects
|
||||
Order order = new Order();
|
||||
Customer customer = new Customer();
|
||||
Address billing = new Address();
|
||||
@@ -81,10 +62,7 @@ public class OrderItemReaderTests {
|
||||
ShippingInfo shippingInfo = new ShippingInfo();
|
||||
LineItem item = new LineItem();
|
||||
|
||||
// create mock mapper
|
||||
@SuppressWarnings("rawtypes")
|
||||
FieldSetMapper mapper = mock(FieldSetMapper.class);
|
||||
// set how mapper should respond - set return values for mapper
|
||||
when(mapper.mapFieldSet(headerFS)).thenReturn(order);
|
||||
when(mapper.mapFieldSet(customerFS)).thenReturn(customer);
|
||||
when(mapper.mapFieldSet(billingFS)).thenReturn(billing);
|
||||
@@ -93,7 +71,6 @@ public class OrderItemReaderTests {
|
||||
when(mapper.mapFieldSet(shippingInfoFS)).thenReturn(shippingInfo);
|
||||
when(mapper.mapFieldSet(itemFS)).thenReturn(item);
|
||||
|
||||
// set-up provider: set mappers
|
||||
provider.setAddressMapper(mapper);
|
||||
provider.setBillingMapper(mapper);
|
||||
provider.setCustomerMapper(mapper);
|
||||
@@ -101,31 +78,25 @@ public class OrderItemReaderTests {
|
||||
provider.setItemMapper(mapper);
|
||||
provider.setShippingMapper(mapper);
|
||||
|
||||
// call tested method
|
||||
Object result = provider.read();
|
||||
|
||||
// verify result
|
||||
assertNotNull(result);
|
||||
|
||||
// verify whether order is constructed correctly
|
||||
// Order object should contain same instances as returned by mapper
|
||||
Order o = (Order) result;
|
||||
assertEquals(o, order);
|
||||
assertEquals(o.getCustomer(), customer);
|
||||
// is it non-bussines customer
|
||||
assertFalse(o.getCustomer().isBusinessCustomer());
|
||||
assertEquals(o.getBillingAddress(), billing);
|
||||
assertEquals(o.getShippingAddress(), shipping);
|
||||
assertEquals(o.getBilling(), billingInfo);
|
||||
assertEquals(o.getShipping(), shippingInfo);
|
||||
// there should be 3 line items
|
||||
|
||||
assertEquals(3, o.getLineItems().size());
|
||||
for (Iterator<?> i = o.getLineItems().iterator(); i.hasNext();) {
|
||||
assertEquals(i.next(), item);
|
||||
|
||||
for (LineItem lineItem : o.getLineItems()) {
|
||||
assertEquals(lineItem, item);
|
||||
}
|
||||
|
||||
// try to retrieve next object - nothing should be returned
|
||||
assertNull(provider.read());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ import org.springframework.batch.sample.domain.order.internal.mapper.ShippingFie
|
||||
import org.springframework.batch.sample.support.AbstractFieldSetMapperTests;
|
||||
|
||||
public class ShippingFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
|
||||
private static final String SHIPPER_ID = "1";
|
||||
private static final String SHIPPING_INFO = "most interesting and informative shipping info ever";
|
||||
private static final String SHIPPING_TYPE_ID = "X";
|
||||
|
||||
@Override
|
||||
protected Object expectedDomainObject() {
|
||||
ShippingInfo info = new ShippingInfo();
|
||||
info.setShipperId(SHIPPER_ID);
|
||||
@@ -20,6 +20,7 @@ public class ShippingFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens = new String[] { SHIPPER_ID, SHIPPING_INFO, SHIPPING_TYPE_ID };
|
||||
String[] columnNames = new String[] { ShippingFieldSetMapper.SHIPPER_ID_COLUMN,
|
||||
@@ -27,8 +28,8 @@ public class ShippingFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FieldSetMapper<ShippingInfo> fieldSetMapper() {
|
||||
return new ShippingFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.batch.sample.domain.trade;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -16,25 +13,21 @@ import org.springframework.batch.item.file.transform.LineTokenizer;
|
||||
*
|
||||
*/
|
||||
public class CompositeCustomerUpdateLineTokenizerTests {
|
||||
|
||||
StubLineTokenizer customerTokenizer;
|
||||
FieldSet customerFieldSet = new DefaultFieldSet(null);
|
||||
StubLineTokenizer footerTokenizer;
|
||||
FieldSet footerFieldSet = new DefaultFieldSet(null);
|
||||
CompositeCustomerUpdateLineTokenizer compositeTokenizer;
|
||||
private StubLineTokenizer customerTokenizer;
|
||||
private FieldSet customerFieldSet = new DefaultFieldSet(null);
|
||||
private FieldSet footerFieldSet = new DefaultFieldSet(null);
|
||||
private CompositeCustomerUpdateLineTokenizer compositeTokenizer;
|
||||
|
||||
@Before
|
||||
public void init(){
|
||||
customerTokenizer = new StubLineTokenizer(customerFieldSet);
|
||||
footerTokenizer = new StubLineTokenizer(footerFieldSet);
|
||||
compositeTokenizer = new CompositeCustomerUpdateLineTokenizer();
|
||||
compositeTokenizer.setCustomerTokenizer(customerTokenizer);
|
||||
compositeTokenizer.setFooterTokenizer(footerTokenizer);
|
||||
compositeTokenizer.setFooterTokenizer(new StubLineTokenizer(footerFieldSet));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomerAdd() throws Exception{
|
||||
|
||||
String customerAddLine = "AFDASFDASFDFSA";
|
||||
FieldSet fs = compositeTokenizer.tokenize(customerAddLine);
|
||||
assertEquals(customerFieldSet, fs);
|
||||
@@ -43,7 +36,6 @@ public class CompositeCustomerUpdateLineTokenizerTests {
|
||||
|
||||
@Test
|
||||
public void testCustomerDelete() throws Exception{
|
||||
|
||||
String customerAddLine = "DFDASFDASFDFSA";
|
||||
FieldSet fs = compositeTokenizer.tokenize(customerAddLine);
|
||||
assertEquals(customerFieldSet, fs);
|
||||
@@ -52,7 +44,6 @@ public class CompositeCustomerUpdateLineTokenizerTests {
|
||||
|
||||
@Test
|
||||
public void testCustomerUpdate() throws Exception{
|
||||
|
||||
String customerAddLine = "UFDASFDASFDFSA";
|
||||
FieldSet fs = compositeTokenizer.tokenize(customerAddLine);
|
||||
assertEquals(customerFieldSet, fs);
|
||||
@@ -61,21 +52,19 @@ public class CompositeCustomerUpdateLineTokenizerTests {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testInvalidLine() throws Exception{
|
||||
|
||||
String invalidLine = "INVALID";
|
||||
compositeTokenizer.tokenize(invalidLine);
|
||||
}
|
||||
|
||||
|
||||
private static class StubLineTokenizer implements LineTokenizer{
|
||||
|
||||
private static class StubLineTokenizer implements LineTokenizer{
|
||||
private final FieldSet fieldSetToReturn;
|
||||
private String tokenizedLine;
|
||||
|
||||
public StubLineTokenizer(FieldSet fieldSetToReturn) {
|
||||
this.fieldSetToReturn = fieldSetToReturn;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FieldSet tokenize(String line) {
|
||||
this.tokenizedLine = line;
|
||||
return fieldSetToReturn;
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.batch.sample.domain.trade;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -21,10 +18,9 @@ import org.junit.Test;
|
||||
*
|
||||
*/
|
||||
public class CustomerUpdateProcessorTests {
|
||||
|
||||
CustomerDao customerDao;
|
||||
InvalidCustomerLogger logger;
|
||||
CustomerUpdateProcessor processor;
|
||||
private CustomerDao customerDao;
|
||||
private InvalidCustomerLogger logger;
|
||||
private CustomerUpdateProcessor processor;
|
||||
|
||||
@Before
|
||||
public void init(){
|
||||
@@ -37,16 +33,14 @@ public class CustomerUpdateProcessorTests {
|
||||
|
||||
@Test
|
||||
public void testSuccessfulAdd() throws Exception{
|
||||
|
||||
CustomerUpdate customerUpdate = new CustomerUpdate(ADD, "test customer", new BigDecimal(232.2));
|
||||
CustomerUpdate customerUpdate = new CustomerUpdate(ADD, "test customer", new BigDecimal("232.2"));
|
||||
when(customerDao.getCustomerByName("test customer")).thenReturn(null);
|
||||
assertEquals(customerUpdate, processor.process(customerUpdate));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidAdd() throws Exception{
|
||||
|
||||
CustomerUpdate customerUpdate = new CustomerUpdate(ADD, "test customer", new BigDecimal(232.2));
|
||||
CustomerUpdate customerUpdate = new CustomerUpdate(ADD, "test customer", new BigDecimal("232.2"));
|
||||
when(customerDao.getCustomerByName("test customer")).thenReturn(new CustomerCredit());
|
||||
logger.log(customerUpdate);
|
||||
assertNull("Processor should return null", processor.process(customerUpdate));
|
||||
@@ -54,27 +48,23 @@ public class CustomerUpdateProcessorTests {
|
||||
|
||||
@Test
|
||||
public void testDelete() throws Exception{
|
||||
//delete should never work, therefore, ensure it fails fast.
|
||||
CustomerUpdate customerUpdate = new CustomerUpdate(DELETE, "test customer", new BigDecimal(232.2));
|
||||
CustomerUpdate customerUpdate = new CustomerUpdate(DELETE, "test customer", new BigDecimal("232.2"));
|
||||
logger.log(customerUpdate);
|
||||
assertNull("Processor should return null", processor.process(customerUpdate));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccessfulUpdate() throws Exception{
|
||||
|
||||
CustomerUpdate customerUpdate = new CustomerUpdate(UPDATE, "test customer", new BigDecimal(232.2));
|
||||
CustomerUpdate customerUpdate = new CustomerUpdate(UPDATE, "test customer", new BigDecimal("232.2"));
|
||||
when(customerDao.getCustomerByName("test customer")).thenReturn(new CustomerCredit());
|
||||
assertEquals(customerUpdate, processor.process(customerUpdate));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidUpdate() throws Exception{
|
||||
|
||||
CustomerUpdate customerUpdate = new CustomerUpdate(UPDATE, "test customer", new BigDecimal(232.2));
|
||||
CustomerUpdate customerUpdate = new CustomerUpdate(UPDATE, "test customer", new BigDecimal("232.2"));
|
||||
when(customerDao.getCustomerByName("test customer")).thenReturn(null);
|
||||
logger.log(customerUpdate);
|
||||
assertNull("Processor should return null", processor.process(customerUpdate));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
package org.springframework.batch.sample.domain.trade;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TradeTests {
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
public class TradeTests {
|
||||
@Test
|
||||
public void testEquality(){
|
||||
|
||||
Trade trade1 = new Trade("isin", 1, new BigDecimal(1.1), "customer1");
|
||||
Trade trade1Clone = new Trade("isin", 1, new BigDecimal(1.1), "customer1");
|
||||
Trade trade2 = new Trade("isin", 1, new BigDecimal(2.3), "customer2");
|
||||
Trade trade1 = new Trade("isin", 1, new BigDecimal("1.1"), "customer1");
|
||||
Trade trade1Clone = new Trade("isin", 1, new BigDecimal("1.1"), "customer1");
|
||||
Trade trade2 = new Trade("isin", 1, new BigDecimal("2.3"), "customer2");
|
||||
|
||||
assertEquals(trade1, trade1Clone);
|
||||
assertFalse(trade1.equals(trade2));
|
||||
|
||||
@@ -8,12 +8,11 @@ import org.junit.Test;
|
||||
import org.springframework.batch.sample.domain.trade.CustomerCredit;
|
||||
|
||||
/**
|
||||
* Tests for {@link CustomerCreditItemWriter}.
|
||||
* Tests for {@link CustomerCreditIncreaseProcessor}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class CustomerCreditIncreaseProcessorTests {
|
||||
|
||||
private CustomerCreditIncreaseProcessor tested = new CustomerCreditIncreaseProcessor();
|
||||
|
||||
/*
|
||||
@@ -21,8 +20,7 @@ public class CustomerCreditIncreaseProcessorTests {
|
||||
*/
|
||||
@Test
|
||||
public void testProcess() throws Exception {
|
||||
|
||||
final BigDecimal oldCredit = new BigDecimal(10.54);
|
||||
final BigDecimal oldCredit = new BigDecimal("10.54");
|
||||
CustomerCredit customerCredit = new CustomerCredit();
|
||||
customerCredit.setCredit(oldCredit);
|
||||
|
||||
|
||||
@@ -11,14 +11,11 @@ import org.springframework.batch.sample.support.AbstractRowMapperTests;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
public class CustomerCreditRowMapperTests extends AbstractRowMapperTests {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final int ID = 12;
|
||||
private static final String CUSTOMER = "Jozef Mak";
|
||||
private static final BigDecimal CREDIT = new BigDecimal(0.1);
|
||||
private static final BigDecimal CREDIT = new BigDecimal("0.1");
|
||||
|
||||
@Override
|
||||
protected Object expectedDomainObject() {
|
||||
CustomerCredit credit = new CustomerCredit();
|
||||
credit.setId(ID);
|
||||
@@ -27,14 +24,15 @@ public class CustomerCreditRowMapperTests extends AbstractRowMapperTests {
|
||||
return credit;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RowMapper rowMapper() {
|
||||
return new CustomerCreditRowMapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUpResultSetMock(ResultSet rs) throws SQLException {
|
||||
when(rs.getInt(CustomerCreditRowMapper.ID_COLUMN)).thenReturn(ID);
|
||||
when(rs.getString(CustomerCreditRowMapper.NAME_COLUMN)).thenReturn(CUSTOMER);
|
||||
when(rs.getBigDecimal(CustomerCreditRowMapper.CREDIT_COLUMN)).thenReturn(CREDIT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.springframework.batch.sample.domain.trade.internal;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collections;
|
||||
@@ -12,16 +11,14 @@ import org.springframework.batch.sample.domain.trade.CustomerCredit;
|
||||
import org.springframework.batch.sample.domain.trade.CustomerCreditDao;
|
||||
|
||||
public class CustomerCreditUpdateProcessorTests {
|
||||
|
||||
private CustomerCreditDao dao;
|
||||
private CustomerCreditUpdateWriter writer;
|
||||
private static final double CREDIT_FILTER = 355.0;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
//create mock writer
|
||||
dao = mock(CustomerCreditDao.class);
|
||||
//create processor, set writer and credit filter
|
||||
|
||||
writer = new CustomerCreditUpdateWriter();
|
||||
writer.setDao(dao);
|
||||
writer.setCreditFilter(CREDIT_FILTER);
|
||||
@@ -29,25 +26,15 @@ public class CustomerCreditUpdateProcessorTests {
|
||||
|
||||
@Test
|
||||
public void testProcess() throws Exception {
|
||||
|
||||
//set-up mock writer - no writer's method should be called
|
||||
|
||||
//create credit and set it to same value as credit filter
|
||||
CustomerCredit credit = new CustomerCredit();
|
||||
credit.setCredit(new BigDecimal(CREDIT_FILTER));
|
||||
//call tested method
|
||||
|
||||
writer.write(Collections.singletonList(credit));
|
||||
//verify method calls - no method should be called
|
||||
//because credit is not greater then credit filter
|
||||
|
||||
//change credit to be greater than credit filter
|
||||
|
||||
credit.setCredit(new BigDecimal(CREDIT_FILTER + 1));
|
||||
//reset and set-up writer - write method is expected to be called
|
||||
|
||||
dao.writeCredit(credit);
|
||||
|
||||
//call tested method
|
||||
writer.write(Collections.singletonList(credit));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,28 +11,23 @@ import org.springframework.batch.sample.domain.trade.CustomerDebitDao;
|
||||
import org.springframework.batch.sample.domain.trade.Trade;
|
||||
|
||||
public class CustomerUpdateProcessorTests {
|
||||
|
||||
@Test
|
||||
public void testProcess() {
|
||||
|
||||
//create trade object
|
||||
Trade trade = new Trade();
|
||||
trade.setCustomer("testCustomerName");
|
||||
trade.setPrice(new BigDecimal(123.0));
|
||||
trade.setPrice(new BigDecimal("123.0"));
|
||||
|
||||
//create dao
|
||||
CustomerDebitDao dao = new CustomerDebitDao() {
|
||||
@Override
|
||||
public void write(CustomerDebit customerDebit) {
|
||||
assertEquals("testCustomerName", customerDebit.getName());
|
||||
assertEquals(new BigDecimal(123.0), customerDebit.getDebit());
|
||||
assertEquals(new BigDecimal("123.0"), customerDebit.getDebit());
|
||||
}
|
||||
};
|
||||
|
||||
//create processor and set dao
|
||||
CustomerUpdateWriter processor = new CustomerUpdateWriter();
|
||||
processor.setDao(dao);
|
||||
|
||||
//call tested method - see asserts in dao.write() method
|
||||
processor.write(Collections.singletonList(trade));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,17 +28,13 @@ import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.domain.trade.CustomerCredit;
|
||||
|
||||
public class FlatFileCustomerCreditDaoTests {
|
||||
|
||||
private ResourceLifecycleItemWriter output;
|
||||
private FlatFileCustomerCreditDao writer;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
//create mock for OutputSource
|
||||
output = mock(ResourceLifecycleItemWriter.class);
|
||||
|
||||
//create new writer
|
||||
writer = new FlatFileCustomerCreditDao();
|
||||
writer.setItemWriter(output);
|
||||
}
|
||||
@@ -46,45 +42,34 @@ public class FlatFileCustomerCreditDaoTests {
|
||||
@Test
|
||||
public void testOpen() throws Exception {
|
||||
ExecutionContext executionContext = new ExecutionContext();
|
||||
//set-up outputSource mock
|
||||
|
||||
output.open(executionContext);
|
||||
|
||||
//call tested method
|
||||
writer.open(executionContext);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClose() throws Exception{
|
||||
|
||||
//set-up outputSource mock
|
||||
output.close();
|
||||
|
||||
//call tested method
|
||||
writer.close();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrite() throws Exception {
|
||||
|
||||
//Create and set-up CustomerCredit
|
||||
CustomerCredit credit = new CustomerCredit();
|
||||
credit.setCredit(new BigDecimal(1));
|
||||
credit.setName("testName");
|
||||
|
||||
//set separator
|
||||
writer.setSeparator(";");
|
||||
|
||||
//set-up OutputSource mock
|
||||
output.write(Collections.singletonList("testName;1"));
|
||||
output.open(new ExecutionContext());
|
||||
|
||||
//call tested method
|
||||
writer.writeCredit(credit);
|
||||
}
|
||||
|
||||
private interface ResourceLifecycleItemWriter extends ItemWriter<String>, ItemStream{
|
||||
|
||||
private interface ResourceLifecycleItemWriter extends ItemWriter<String>, ItemStream {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,8 @@ import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
public class ItemTrackingTradeItemWriter implements ItemWriter<Trade> {
|
||||
|
||||
private List<Trade> items = new ArrayList<Trade>();
|
||||
|
||||
private String writeFailureISIN;
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
@@ -27,30 +24,27 @@ public class ItemTrackingTradeItemWriter implements ItemWriter<Trade> {
|
||||
this.writeFailureISIN = writeFailureISIN;
|
||||
}
|
||||
|
||||
public void setItems(List<Trade> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public List<Trade> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void clearItems() {
|
||||
this.items.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(List<? extends Trade> items) throws Exception {
|
||||
List<Trade> newItems = new ArrayList<Trade>();
|
||||
|
||||
for (Trade t : items) {
|
||||
if (t.getIsin().equals(this.writeFailureISIN)) {
|
||||
throw new IOException("write failed");
|
||||
}
|
||||
|
||||
newItems.add(t);
|
||||
|
||||
if (jdbcTemplate != null) {
|
||||
jdbcTemplate.update("UPDATE TRADE set VERSION=? where ID=? and version=?", t.getVersion() + 1, t
|
||||
.getId(), t.getVersion());
|
||||
}
|
||||
}
|
||||
|
||||
this.items.addAll(newItems);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2012 the original author or authors.
|
||||
* Copyright 2006-2014 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.
|
||||
@@ -37,7 +37,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration()
|
||||
public class JdbcCustomerDebitDaoTests {
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
@@ -48,27 +47,23 @@ public class JdbcCustomerDebitDaoTests {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
@Test
|
||||
@Transactional
|
||||
public void testWrite() {
|
||||
|
||||
//insert customer credit
|
||||
jdbcTemplate.execute("INSERT INTO CUSTOMER VALUES (99, 0, 'testName', 100)");
|
||||
|
||||
//create customer debit
|
||||
CustomerDebit customerDebit = new CustomerDebit();
|
||||
customerDebit.setName("testName");
|
||||
customerDebit.setDebit(BigDecimal.valueOf(5));
|
||||
|
||||
//call writer
|
||||
writer.write(customerDebit);
|
||||
|
||||
//verify customer credit
|
||||
jdbcTemplate.query("SELECT name, credit FROM CUSTOMER WHERE name = 'testName'",
|
||||
new RowCallbackHandler() {
|
||||
@Override
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
assertEquals(95, rs.getLong("credit"));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2012 the original author or authors.
|
||||
* Copyright 2006-2014 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,11 +40,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = {"/data-source-context.xml"})
|
||||
public class JdbcTradeWriterTests implements InitializingBean {
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
private JdbcTradeDao writer;
|
||||
|
||||
private AbstractDataFieldMaxValueIncrementer incrementer;
|
||||
|
||||
@Autowired
|
||||
@@ -52,7 +49,6 @@ public class JdbcTradeWriterTests implements InitializingBean {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.writer = new JdbcTradeDao();
|
||||
this.writer.setDataSource(dataSource);
|
||||
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@@ -61,13 +57,13 @@ public class JdbcTradeWriterTests implements InitializingBean {
|
||||
this.incrementer = incrementer;
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
@Test
|
||||
@Transactional
|
||||
public void testWrite() {
|
||||
|
||||
Trade trade = new Trade();
|
||||
trade.setCustomer("testCustomer");
|
||||
trade.setIsin("5647238492");
|
||||
trade.setPrice(new BigDecimal(Double.toString(99.69)));
|
||||
trade.setPrice(new BigDecimal("99.69"));
|
||||
trade.setQuantity(5);
|
||||
|
||||
writer.writeTrade(trade);
|
||||
|
||||
@@ -9,15 +9,12 @@ import org.springframework.batch.sample.domain.trade.Trade;
|
||||
import org.springframework.batch.sample.support.AbstractFieldSetMapperTests;
|
||||
|
||||
public class TradeFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
|
||||
private static final String CUSTOMER = "Mike Tomcat";
|
||||
|
||||
private static final BigDecimal PRICE = new BigDecimal(1.3);
|
||||
|
||||
private static final long QUANTITY = 7;
|
||||
|
||||
private static final String ISIN = "fj893gnsalX";
|
||||
|
||||
@Override
|
||||
protected Object expectedDomainObject() {
|
||||
Trade trade = new Trade();
|
||||
trade.setIsin(ISIN);
|
||||
@@ -27,6 +24,7 @@ public class TradeFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
return trade;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens = new String[4];
|
||||
tokens[TradeFieldSetMapper.ISIN_COLUMN] = ISIN;
|
||||
@@ -37,8 +35,8 @@ public class TradeFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
return new DefaultFieldSet(tokens);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FieldSetMapper<Trade> fieldSetMapper() {
|
||||
return new TradeFieldSetMapper();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,30 +10,23 @@ import org.springframework.batch.sample.domain.trade.Trade;
|
||||
import org.springframework.batch.sample.domain.trade.TradeDao;
|
||||
|
||||
public class TradeProcessorTests {
|
||||
|
||||
private TradeDao writer;
|
||||
private TradeWriter processor;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
//create mock writer
|
||||
writer = mock(TradeDao.class);
|
||||
|
||||
//create processor
|
||||
processor = new TradeWriter();
|
||||
processor.setDao(writer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcess() {
|
||||
|
||||
Trade trade = new Trade();
|
||||
//set-up mock writer
|
||||
|
||||
writer.writeTrade(trade);
|
||||
|
||||
//call tested method
|
||||
processor.write(Collections.singletonList(trade));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,25 +11,28 @@ import org.springframework.batch.sample.support.AbstractRowMapperTests;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
public class TradeRowMapperTests extends AbstractRowMapperTests {
|
||||
|
||||
private static final String ISIN = "jsgk342";
|
||||
private static final long QUANTITY = 0;
|
||||
private static final BigDecimal PRICE = new BigDecimal(1.1);
|
||||
private static final BigDecimal PRICE = new BigDecimal("1.1");
|
||||
private static final String CUSTOMER = "Martin Hrancok";
|
||||
|
||||
@Override
|
||||
protected Object expectedDomainObject() {
|
||||
Trade trade = new Trade();
|
||||
trade.setIsin(ISIN);
|
||||
trade.setQuantity(QUANTITY);
|
||||
trade.setPrice(PRICE);
|
||||
trade.setCustomer(CUSTOMER);
|
||||
|
||||
return trade;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RowMapper rowMapper() {
|
||||
return new TradeRowMapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUpResultSetMock(ResultSet rs) throws SQLException {
|
||||
when(rs.getLong(TradeRowMapper.ID_COLUMN)).thenReturn(12L);
|
||||
when(rs.getString(TradeRowMapper.ISIN_COLUMN)).thenReturn(ISIN);
|
||||
@@ -38,5 +41,4 @@ public class TradeRowMapperTests extends AbstractRowMapperTests {
|
||||
when(rs.getString(TradeRowMapper.CUSTOMER_COLUMN)).thenReturn(CUSTOMER);
|
||||
when(rs.getInt(TradeRowMapper.VERSION_COLUMN)).thenReturn(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2014 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.
|
||||
@@ -49,7 +49,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/ioSampleJob.xml",
|
||||
"/jobs/iosample/delimited.xml" })
|
||||
public class TwoJobInstancesDelimitedFunctionalTests {
|
||||
|
||||
@Autowired
|
||||
private JobLauncher launcher;
|
||||
|
||||
@@ -74,15 +73,13 @@ public class TwoJobInstancesDelimitedFunctionalTests {
|
||||
}
|
||||
|
||||
private void verifyOutput(int expected) throws Exception {
|
||||
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("inputFile",
|
||||
"file:./target/test-outputs/delimitedOutput.csv").toJobParameters();
|
||||
StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(jobParameters);
|
||||
|
||||
int count = StepScopeTestUtils.doInStepScope(stepExecution, new Callable<Integer>() {
|
||||
|
||||
@Override
|
||||
public Integer call() throws Exception {
|
||||
|
||||
int count = 0;
|
||||
|
||||
readerStream.open(new ExecutionContext());
|
||||
@@ -96,18 +93,14 @@ public class TwoJobInstancesDelimitedFunctionalTests {
|
||||
readerStream.close();
|
||||
}
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
assertEquals(expected, count);
|
||||
|
||||
}
|
||||
|
||||
protected JobParameters getJobParameters(String fileName) {
|
||||
return new JobParametersBuilder().addLong("timestamp", new Date().getTime()).addString("inputFile", fileName)
|
||||
.addString("outputFile", "file:./target/test-outputs/delimitedOutput.csv").toJobParameters();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2012 the original author or authors.
|
||||
* Copyright 2006-2014 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.
|
||||
@@ -45,7 +45,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/ioSampleJob.xml",
|
||||
"/jobs/iosample/jdbcPaging.xml" })
|
||||
public class TwoJobInstancesPagingFunctionalTests {
|
||||
|
||||
@Autowired
|
||||
private JobLauncher launcher;
|
||||
|
||||
@@ -61,11 +60,11 @@ public class TwoJobInstancesPagingFunctionalTests {
|
||||
|
||||
@Test
|
||||
public void testLaunchJobTwice() throws Exception {
|
||||
int first = jdbcTemplate.queryForInt("select count(0) from CUSTOMER where credit>1000");
|
||||
int first = jdbcTemplate.queryForObject("select count(0) from CUSTOMER where credit>1000", Integer.class);
|
||||
JobExecution jobExecution = launcher.run(this.job, getJobParameters(1000.));
|
||||
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
|
||||
assertEquals(first, jobExecution.getStepExecutions().iterator().next().getWriteCount());
|
||||
int second = jdbcTemplate.queryForInt("select count(0) from CUSTOMER where credit>1000000");
|
||||
int second = jdbcTemplate.queryForObject("select count(0) from CUSTOMER where credit>1000000", Integer.class);
|
||||
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());
|
||||
@@ -76,5 +75,4 @@ public class TwoJobInstancesPagingFunctionalTests {
|
||||
return new JobParametersBuilder().addLong("timestamp", new Date().getTime()).addDouble("credit", amount)
|
||||
.toJobParameters();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2014 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.
|
||||
@@ -28,6 +28,7 @@ public class DelegatingTradeLineAggregator implements LineAggregator<Object> {
|
||||
private LineAggregator<Trade> tradeLineAggregator;
|
||||
private LineAggregator<CustomerCredit> customerLineAggregator;
|
||||
|
||||
@Override
|
||||
public String aggregate(Object item) {
|
||||
if (item instanceof Trade) {
|
||||
return this.tradeLineAggregator.aggregate((Trade) item);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2014 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,16 +30,16 @@ import org.springframework.util.Assert;
|
||||
* @since 2.0
|
||||
*/
|
||||
public class MultiLineTradeItemReader implements ItemReader<Trade>, ItemStream {
|
||||
|
||||
private FlatFileItemReader<FieldSet> delegate;
|
||||
|
||||
/**
|
||||
* @see org.springframework.batch.item.ItemReader#read()
|
||||
*/
|
||||
@Override
|
||||
public Trade read() throws Exception {
|
||||
Trade t = null;
|
||||
|
||||
for (FieldSet line = null; (line = this.delegate.read()) != null;) {
|
||||
for (FieldSet line; (line = this.delegate.read()) != null;) {
|
||||
String prefix = line.readString(0);
|
||||
if (prefix.equals("BEGIN")) {
|
||||
t = new Trade(); // Record must start with 'BEGIN'
|
||||
@@ -66,14 +66,17 @@ public class MultiLineTradeItemReader implements ItemReader<Trade>, ItemStream {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws ItemStreamException {
|
||||
this.delegate.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(ExecutionContext executionContext) throws ItemStreamException {
|
||||
this.delegate.open(executionContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(ExecutionContext executionContext) throws ItemStreamException {
|
||||
this.delegate.update(executionContext);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2014 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.
|
||||
@@ -31,17 +31,19 @@ import org.springframework.batch.sample.domain.trade.Trade;
|
||||
* @since 2.0
|
||||
*/
|
||||
public class MultiLineTradeItemWriter implements ItemWriter<Trade>, ItemStream {
|
||||
|
||||
private FlatFileItemWriter<String> delegate;
|
||||
|
||||
@Override
|
||||
public void write(List<? extends Trade> items) throws Exception {
|
||||
List<String> lines = new ArrayList<String>();
|
||||
|
||||
for (Trade t : items) {
|
||||
lines.add("BEGIN");
|
||||
lines.add("INFO," + t.getIsin() + "," + t.getCustomer());
|
||||
lines.add("AMNT," + t.getQuantity() + "," + t.getPrice());
|
||||
lines.add("END");
|
||||
}
|
||||
|
||||
this.delegate.write(lines);
|
||||
}
|
||||
|
||||
@@ -49,14 +51,17 @@ public class MultiLineTradeItemWriter implements ItemWriter<Trade>, ItemStream {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws ItemStreamException {
|
||||
this.delegate.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(ExecutionContext executionContext) throws ItemStreamException {
|
||||
this.delegate.open(executionContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(ExecutionContext executionContext) throws ItemStreamException {
|
||||
this.delegate.update(executionContext);
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.iosample.internal;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.domain.trade.CustomerCredit;
|
||||
import org.springframework.batch.sample.domain.trade.Trade;
|
||||
import org.springframework.batch.sample.domain.trade.TradeDao;
|
||||
|
||||
/**
|
||||
* @author Dan Garrette
|
||||
* @since 2.0
|
||||
*/
|
||||
public class TradeCustomerItemWriter implements ItemWriter<CustomerCredit> {
|
||||
private TradeDao dao;
|
||||
private int count;
|
||||
|
||||
public void write(List<? extends CustomerCredit> items) throws Exception {
|
||||
for (CustomerCredit c : items) {
|
||||
Trade t = new Trade("ISIN" + count++, 100, new BigDecimal("1.50"), c.getName());
|
||||
this.dao.writeTrade(t);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDao(TradeDao dao) {
|
||||
this.dao = dao;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2008 the original author or authors.
|
||||
* Copyright 2006-2014 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,21 +33,22 @@ import org.springframework.jmx.export.notification.UnableToSendNotificationExcep
|
||||
*
|
||||
*/
|
||||
public class JobExecutionNotificationPublisherTests {
|
||||
|
||||
JobExecutionNotificationPublisher publisher = new JobExecutionNotificationPublisher();
|
||||
|
||||
@Test
|
||||
public void testRepeatOperationsOpenUsed() throws Exception {
|
||||
final List<Notification> list = new ArrayList<Notification>();
|
||||
|
||||
publisher.setNotificationPublisher(new NotificationPublisher() {
|
||||
@Override
|
||||
public void sendNotification(Notification notification) throws UnableToSendNotificationException {
|
||||
list.add(notification);
|
||||
}
|
||||
});
|
||||
|
||||
publisher.onApplicationEvent(new SimpleMessageApplicationEvent(this, "foo"));
|
||||
assertEquals(1, list.size());
|
||||
String message = list.get(0).getMessage();
|
||||
assertTrue("Message does not contain 'foo': ", message.indexOf("foo") > 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2014 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,7 +24,6 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.management.MBeanServerConnection;
|
||||
import javax.management.MalformedObjectNameException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -44,23 +43,20 @@ import org.springframework.jmx.support.MBeanServerConnectionFactoryBean;
|
||||
*
|
||||
*/
|
||||
public class RemoteLauncherTests {
|
||||
|
||||
private static Log logger = LogFactory.getLog(RemoteLauncherTests.class);
|
||||
|
||||
private static List<Exception> errors = new ArrayList<Exception>();
|
||||
|
||||
private static JobOperator launcher;
|
||||
|
||||
private static JobLoader loader;
|
||||
|
||||
static private Thread thread;
|
||||
|
||||
@Test
|
||||
public void testConnect() throws Exception {
|
||||
String message = errors.isEmpty() ? "" : errors.get(0).getMessage();
|
||||
|
||||
if (!errors.isEmpty()) {
|
||||
fail(message);
|
||||
}
|
||||
|
||||
assertTrue(isConnected());
|
||||
}
|
||||
|
||||
@@ -68,12 +64,12 @@ public class RemoteLauncherTests {
|
||||
public void testLaunchBadJob() throws Exception {
|
||||
assertEquals(0, errors.size());
|
||||
assertTrue(isConnected());
|
||||
|
||||
try {
|
||||
launcher.start("foo", "time=" + (new Date().getTime()));
|
||||
fail("Expected RuntimeException");
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
// expected;
|
||||
String message = e.getMessage();
|
||||
assertTrue("Wrong message: " + message, message.contains("NoSuchJobException"));
|
||||
}
|
||||
@@ -89,18 +85,20 @@ public class RemoteLauncherTests {
|
||||
@Test
|
||||
public void testPauseJob() throws Exception {
|
||||
final int SLEEP_INTERVAL = 600;
|
||||
|
||||
assertTrue(isConnected());
|
||||
assertTrue(launcher.getJobNames().contains("loopJob"));
|
||||
|
||||
long executionId = launcher.start("loopJob", "");
|
||||
|
||||
// sleep long enough to avoid race conditions (serializable tx isolation
|
||||
// doesn't work with HSQL)
|
||||
Thread.sleep(SLEEP_INTERVAL);
|
||||
// assertEquals(1, launcher.getRunningExecutions("loopJob").size());
|
||||
|
||||
launcher.stop(executionId);
|
||||
|
||||
Thread.sleep(SLEEP_INTERVAL);
|
||||
// assertEquals(0, launcher.getRunningExecutions("loopJob").size());
|
||||
|
||||
logger.debug(launcher.getSummary(executionId));
|
||||
long resumedId = launcher.restart(executionId);
|
||||
assertNotSame("Picked up the same execution after pause and resume", executionId, resumedId);
|
||||
@@ -109,14 +107,12 @@ public class RemoteLauncherTests {
|
||||
launcher.stop(resumedId);
|
||||
Thread.sleep(SLEEP_INTERVAL);
|
||||
|
||||
// assertEquals(0, launcher.getRunningExecutions("loopJob").size());
|
||||
logger.debug(launcher.getSummary(resumedId));
|
||||
long resumeId2 = launcher.restart(resumedId);
|
||||
assertNotSame("Picked up the same execution after pause and resume", executionId, resumeId2);
|
||||
|
||||
Thread.sleep(SLEEP_INTERVAL);
|
||||
launcher.stop(resumeId2);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -127,20 +123,23 @@ public class RemoteLauncherTests {
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
System.setProperty("com.sun.management.jmxremote", "");
|
||||
|
||||
thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
JobRegistryBackgroundJobRunner.main("adhoc-job-launcher-context.xml", "jobs/adhocLoopJob.xml");
|
||||
}
|
||||
catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
logger.error(e);
|
||||
errors.add(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
thread.start();
|
||||
int count = 0;
|
||||
|
||||
while (!isConnected() && count++ < 10) {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
@@ -153,21 +152,24 @@ public class RemoteLauncherTests {
|
||||
|
||||
private static boolean isConnected() throws Exception {
|
||||
boolean connected = false;
|
||||
|
||||
if (!JobRegistryBackgroundJobRunner.getErrors().isEmpty()) {
|
||||
throw JobRegistryBackgroundJobRunner.getErrors().get(0);
|
||||
}
|
||||
|
||||
if (launcher == null) {
|
||||
MBeanServerConnectionFactoryBean connectionFactory = new MBeanServerConnectionFactoryBean();
|
||||
|
||||
try {
|
||||
launcher = (JobOperator) getMBean(connectionFactory, "spring:service=batch,bean=jobOperator",
|
||||
JobOperator.class);
|
||||
loader = (JobLoader) getMBean(connectionFactory, "spring:service=batch,bean=jobLoader", JobLoader.class);
|
||||
}
|
||||
catch (MBeanServerNotFoundException e) {
|
||||
// ignore
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
launcher.getJobNames();
|
||||
connected = loader.getConfigurations().size() > 0;
|
||||
@@ -184,9 +186,8 @@ public class RemoteLauncherTests {
|
||||
MBeanProxyFactoryBean factory = new MBeanProxyFactoryBean();
|
||||
factory.setObjectName(objectName);
|
||||
factory.setProxyInterface(interfaceType);
|
||||
factory.setServer((MBeanServerConnection) connectionFactory.getObject());
|
||||
factory.setServer(connectionFactory.getObject());
|
||||
factory.afterPropertiesSet();
|
||||
return factory.getObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2014 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.
|
||||
@@ -46,23 +46,23 @@ import org.springframework.batch.core.repository.JobRestartException;
|
||||
*
|
||||
*/
|
||||
public class JobLauncherDetailsTests {
|
||||
|
||||
private JobLauncherDetails details = new JobLauncherDetails();
|
||||
|
||||
private TriggerFiredBundle firedBundle;
|
||||
|
||||
private List<Serializable> list = new ArrayList<Serializable>();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
details.setJobLauncher(new JobLauncher() {
|
||||
@Override
|
||||
public JobExecution run(org.springframework.batch.core.Job job, JobParameters jobParameters)
|
||||
throws JobExecutionAlreadyRunningException, JobRestartException {
|
||||
list.add(jobParameters);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
details.setJobLocator(new JobLocator() {
|
||||
@Override
|
||||
public org.springframework.batch.core.Job getJob(String name) throws NoSuchJobException {
|
||||
list.add(name);
|
||||
return new StubJob("foo");
|
||||
@@ -154,39 +154,40 @@ public class JobLauncherDetailsTests {
|
||||
}
|
||||
|
||||
private final class StubJobExecutionContext extends JobExecutionContext {
|
||||
|
||||
private StubJobExecutionContext() {
|
||||
super(mock(Scheduler.class), firedBundle, mock(Job.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class StubJob implements org.springframework.batch.core.Job {
|
||||
|
||||
private final String name;
|
||||
|
||||
public StubJob(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JobExecution execution) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobParametersIncrementer getJobParametersIncrementer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobParametersValidator getJobParametersValidator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRestartable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<context:annotation-config/>
|
||||
<bean class="org.springframework.batch.test.JobLauncherTestUtils"/>
|
||||
|
||||
<bean class="org.springframework.batch.test.JobLauncherTestUtils"/>
|
||||
</beans>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<import resource="classpath:/simple-job-launcher-context.xml" />
|
||||
<import resource="classpath:/jobs/jobStepSample.xml" />
|
||||
@@ -9,5 +8,4 @@
|
||||
<bean class="org.springframework.batch.test.JobLauncherTestUtils">
|
||||
<property name="job" ref="jobStepJob"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<import resource="classpath:data-source-context.xml"/>
|
||||
|
||||
</beans>
|
||||
@@ -1,10 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<import resource="classpath:staging-test-context.xml"/>
|
||||
|
||||
</beans>
|
||||
</beans>
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<import resource="classpath:staging-test-context.xml"/>
|
||||
|
||||
</beans>
|
||||
@@ -1,11 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<import resource="classpath:data-source-context.xml"/>
|
||||
|
||||
<bean class="org.springframework.batch.sample.domain.trade.internal.JdbcCustomerDebitDao"/>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user