BATCH-1313 & BATCH-1314:
*Added assertion to AbstractBatchLauncherTests to ensure that the job's status is COMPLETED. *Fixed broken tests.
This commit is contained in:
@@ -30,17 +30,12 @@ import org.springframework.batch.core.job.flow.JobExecutionDecider;
|
||||
public class LimitDecider implements JobExecutionDecider {
|
||||
|
||||
private int count = 0;
|
||||
|
||||
private int limit = 1;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.core.job.flow.support.state.JobExecutionDecider#decide(org.springframework.batch.core.JobExecution,
|
||||
* org.springframework.batch.core.StepExecution)
|
||||
*/
|
||||
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
|
||||
if (++count >= limit) {
|
||||
return new FlowExecutionStatus("COMPLETE");
|
||||
return new FlowExecutionStatus("COMPLETED");
|
||||
}
|
||||
else {
|
||||
return new FlowExecutionStatus("CONTINUE");
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<tasklet ref="errorLogTasklet"/>
|
||||
</step>
|
||||
|
||||
<step id="step2" parent="secondPass" next="skipCheckingDecision"/>
|
||||
<step id="step2" parent="step2parent" next="skipCheckingDecision"/>
|
||||
|
||||
<decision id="skipCheckingDecision" decider="skipCheckingDecider">
|
||||
<end on="*"/>
|
||||
@@ -38,7 +38,7 @@
|
||||
</step>
|
||||
</job>
|
||||
|
||||
<step id="secondPass" parent="t2" xmlns="http://www.springframework.org/schema/batch">
|
||||
<step id="step2parent" parent="t2" xmlns="http://www.springframework.org/schema/batch">
|
||||
<tasklet>
|
||||
<chunk writer="itemTrackingWriter">
|
||||
<skippable-exception-classes merge="true">
|
||||
@@ -102,17 +102,6 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="customerReportItemWriter" class="org.springframework.batch.sample.domain.trade.internal.FlatFileCustomerCreditDao">
|
||||
<property name="itemWriter">
|
||||
<bean id="customerFlatFileOutputSource" class="org.springframework.batch.item.file.FlatFileItemWriter">
|
||||
<property name="resource" value="target/test-outputs/20070122.testStream.CustomerReportStep.TEMP.txt" />
|
||||
<property name="lineAggregator">
|
||||
<bean class="org.springframework.batch.item.file.transform.PassThroughLineAggregator" />
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="errorLogTasklet" class="org.springframework.batch.sample.common.ErrorLogTasklet">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
<bean id="customerReportItemWriter" class="org.springframework.batch.sample.domain.trade.internal.FlatFileCustomerCreditDao">
|
||||
<property name="itemWriter">
|
||||
<bean class="org.springframework.batch.item.file.FlatFileItemWriter">
|
||||
<property name="resource" value="target/test-outputs/20070122.testStream.CustomerReportStep.TEMP.txt" />
|
||||
<property name="resource" value="file:target/test-outputs/20070122.testStream.CustomerReportStep.TEMP.txt" />
|
||||
<property name="lineAggregator">
|
||||
<bean class="org.springframework.batch.item.file.transform.PassThroughLineAggregator" />
|
||||
</property>
|
||||
|
||||
@@ -18,7 +18,9 @@ package org.springframework.batch.sample;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
@@ -38,20 +40,19 @@ import org.springframework.context.ApplicationContextAware;
|
||||
*/
|
||||
public abstract class AbstractBatchLauncherTests implements ApplicationContextAware {
|
||||
|
||||
/** Logger */
|
||||
/** Logger */
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
protected ApplicationContext applicationContext;
|
||||
|
||||
private JobLauncher launcher;
|
||||
|
||||
|
||||
private JobExecution jobExecution;
|
||||
|
||||
private Job job;
|
||||
|
||||
private JobParameters jobParameters = new JobParameters();
|
||||
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
@@ -65,7 +66,7 @@ public abstract class AbstractBatchLauncherTests implements ApplicationContextAw
|
||||
public void setJob(Job job) {
|
||||
this.job = job;
|
||||
}
|
||||
|
||||
|
||||
public JobExecution getJobExecution() {
|
||||
return jobExecution;
|
||||
}
|
||||
@@ -84,7 +85,8 @@ public abstract class AbstractBatchLauncherTests implements ApplicationContextAw
|
||||
|
||||
@Test
|
||||
public void testLaunchJob() throws Exception {
|
||||
jobExecution = getLauncher().run(job, jobParameters);
|
||||
jobExecution = getLauncher().run(job, jobParameters);
|
||||
Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,6 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.sample.domain.trade.Trade;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -40,7 +39,6 @@ import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration()
|
||||
public class TradeJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
@@ -74,15 +72,8 @@ public class TradeJobFunctionalTests extends AbstractValidatingBatchLauncherTest
|
||||
simpleJdbcTemplate.update("delete from TRADE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLaunchJob() throws Exception{
|
||||
super.testLaunchJob();
|
||||
}
|
||||
|
||||
protected void validatePostConditions() {
|
||||
|
||||
// assertTrue(((Resource)applicationContext.getBean("customerFileLocator")).exists());
|
||||
|
||||
customers = Arrays.asList(new Customer("customer1", (credits.get("customer1") - 98.34)),
|
||||
new Customer("customer2", (credits.get("customer2") - 18.12 - 12.78)),
|
||||
new Customer("customer3", (credits.get("customer3") - 109.25)),
|
||||
@@ -126,9 +117,6 @@ public class TradeJobFunctionalTests extends AbstractValidatingBatchLauncherTest
|
||||
// check content of the output file
|
||||
}
|
||||
|
||||
protected void validatePreConditions() {
|
||||
}
|
||||
|
||||
private static class Customer {
|
||||
private String name;
|
||||
private double credit;
|
||||
@@ -166,9 +154,7 @@ public class TradeJobFunctionalTests extends AbstractValidatingBatchLauncherTest
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int PRIME = 31;
|
||||
int result = 1;
|
||||
@@ -179,9 +165,7 @@ public class TradeJobFunctionalTests extends AbstractValidatingBatchLauncherTest
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user