Fix batch update job sample
This commit is contained in:
@@ -125,16 +125,16 @@ public class TransactionAwareProxyFactory {
|
||||
return factory.getProxy();
|
||||
}
|
||||
|
||||
public static Map createTransactionalMap() {
|
||||
return (Map) new TransactionAwareProxyFactory(new HashMap()).createInstance();
|
||||
public static <K,V> Map<K,V> createTransactionalMap() {
|
||||
return (Map<K,V>) new TransactionAwareProxyFactory(new HashMap<K,V>()).createInstance();
|
||||
}
|
||||
|
||||
public static Set createTransactionalSet() {
|
||||
return (Set) new TransactionAwareProxyFactory(new HashSet()).createInstance();
|
||||
public static <T> Set<T> createTransactionalSet() {
|
||||
return (Set<T>) new TransactionAwareProxyFactory(new HashSet<T>()).createInstance();
|
||||
}
|
||||
|
||||
public static List createTransactionalList() {
|
||||
return (List) new TransactionAwareProxyFactory(new ArrayList()).createInstance();
|
||||
public static <T> List<T> createTransactionalList() {
|
||||
return (List<T>) new TransactionAwareProxyFactory(new ArrayList<T>()).createInstance();
|
||||
}
|
||||
|
||||
private class TargetSynchronization extends TransactionSynchronizationAdapter {
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
<config>src/main/resources/jobs/retrySample.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/jobs/batchUpdateJob.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/sample/item/writer/staging-test-context.xml</config>
|
||||
<config>src/main/resources/adhoc-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/alt-data-source-context.xml</config>
|
||||
<config>src/main/resources/quartz-job-launcher-context.xml</config>
|
||||
@@ -40,6 +39,8 @@
|
||||
<config>src/main/resources/jobs/multiResourceJob.xml</config>
|
||||
<config>src/main/resources/jobs/jobExecutionContextSample.xml</config>
|
||||
<config>src/main/resources/hibernate-context.xml</config>
|
||||
<config>src/main/resources/staging-test-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
<configSets>
|
||||
<configSet>
|
||||
@@ -50,17 +51,6 @@
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
<name><![CDATA[adhocLoop]]></name>
|
||||
<allowBeanDefinitionOverriding>true</allowBeanDefinitionOverriding>
|
||||
<incomplete>false</incomplete>
|
||||
<configs>
|
||||
<config>src/main/resources/jobs/adhocLoopJob.xml</config>
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
<name><![CDATA[beanWrapper]]></name>
|
||||
<allowBeanDefinitionOverriding>true</allowBeanDefinitionOverriding>
|
||||
@@ -70,6 +60,7 @@
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -80,6 +71,7 @@
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/jobs/delegatingJob.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -91,6 +83,7 @@
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -101,6 +94,7 @@
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/jobs/footballJob.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -111,6 +105,7 @@
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/jobs/ibatisJob.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -122,6 +117,7 @@
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -133,6 +129,7 @@
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/jobs/multilineJob.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -143,6 +140,7 @@
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/jobs/parallelJob.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -154,6 +152,7 @@
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/jobs/restartSample.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -165,6 +164,7 @@
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -174,6 +174,7 @@
|
||||
<configs>
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -186,6 +187,7 @@
|
||||
<config>src/main/resources/jobs/tradeJob.xml</config>
|
||||
<config>src/main/resources/jobs/tradeJobIo.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -197,6 +199,7 @@
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/jobs/xmlStaxJob.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -208,6 +211,7 @@
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/jobs/batchUpdateJob.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -216,7 +220,6 @@
|
||||
<incomplete>false</incomplete>
|
||||
<configs>
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/sample/item/writer/staging-test-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -227,6 +230,7 @@
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/quartz-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -237,6 +241,7 @@
|
||||
<config>src/main/resources/adhoc-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -247,6 +252,7 @@
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/jobs/skipSampleJob.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/jobs/tradeJobIo.xml</config>
|
||||
</configs>
|
||||
@@ -261,6 +267,7 @@
|
||||
<config>src/main/resources/jobs/multilineOrderIo.xml</config>
|
||||
<config>src/main/resources/jobs/multilineOrderJob.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
<config>src/main/resources/jobs/multilineOrderInputTokenizers.xml</config>
|
||||
<config>src/main/resources/jobs/multilineOrderOutputAggregators.xml</config>
|
||||
</configs>
|
||||
@@ -274,6 +281,7 @@
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/jobs/taskletJob.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -284,6 +292,7 @@
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
<config>src/main/resources/jobs/compositeItemWriterSampleJob.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
@@ -296,6 +305,7 @@
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/jobs/multiResourceJob.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -307,6 +317,7 @@
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/jobs/jobExecutionContextSample.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -317,8 +328,21 @@
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/jobs/hibernateJob.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
<config>src/main/resources/hibernate-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
<name><![CDATA[adhocLoop]]></name>
|
||||
<allowBeanDefinitionOverriding>true</allowBeanDefinitionOverriding>
|
||||
<incomplete>false</incomplete>
|
||||
<configs>
|
||||
<config>src/main/resources/jobs/adhocLoopJob.xml</config>
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
</configSets>
|
||||
</beansProjectDescription>
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.springframework.batch.sample.item.reader;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemRecoverer;
|
||||
import org.springframework.batch.item.MarkFailedException;
|
||||
import org.springframework.batch.item.ResetFailedException;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
@@ -13,7 +12,7 @@ import org.springframework.batch.sample.domain.Trade;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class GeneratingItemReader implements ItemReader<Trade>, ItemRecoverer {
|
||||
public class GeneratingItemReader implements ItemReader<Trade> {
|
||||
|
||||
private int limit = 1;
|
||||
|
||||
@@ -49,13 +48,6 @@ public class GeneratingItemReader implements ItemReader<Trade>, ItemRecoverer {
|
||||
return limit;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemRecoverer#recover(java.lang.Object, java.lang.Throwable)
|
||||
*/
|
||||
public Object recover(Object data, Throwable cause) {
|
||||
return data;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemStream#mark()
|
||||
*/
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.springframework.batch.item.ClearFailedException;
|
||||
import org.springframework.batch.item.FlushFailedException;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.database.BatchSqlUpdateItemWriter;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Increases customer's credit by fixed amount, delegating to a
|
||||
* {@link BatchSqlUpdateItemWriter} to push the result out to persistent
|
||||
* storage.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class BatchSqlCustomerCreditIncreaseWriter implements ItemWriter<CustomerCredit>, InitializingBean {
|
||||
|
||||
private ItemWriter<CustomerCredit> delegate;
|
||||
|
||||
public static final BigDecimal FIXED_AMOUNT = new BigDecimal(1000);
|
||||
|
||||
/**
|
||||
* Public setter for the {@link ItemWriter}, which must be an instance of
|
||||
* {@link BatchSqlUpdateItemWriter}.
|
||||
* @param delegate the delegate to set
|
||||
*/
|
||||
public void setDelegate(ItemWriter<CustomerCredit> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.state(delegate instanceof BatchSqlUpdateItemWriter, "Delegate must be set and must be an instance of BatchSqlUpdateItemWriter");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.processor.DelegatingItemWriter#doProcess(java.lang.Object)
|
||||
*/
|
||||
public void write(CustomerCredit customerCredit) throws Exception {
|
||||
delegate.write(customerCredit);
|
||||
}
|
||||
|
||||
public void clear() throws ClearFailedException {
|
||||
delegate.clear();
|
||||
}
|
||||
|
||||
public void flush() throws FlushFailedException {
|
||||
delegate.flush();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@@ -27,12 +28,14 @@ import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
*/
|
||||
public class CustomerCreditUpdatePreparedStatementSetter implements ItemPreparedStatementSetter {
|
||||
|
||||
public static final BigDecimal FIXED_AMOUNT = new BigDecimal(1000);
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.io.support.ItemPreparedStatementSetter#setValues(java.lang.Object, java.sql.PreparedStatement)
|
||||
*/
|
||||
public void setValues(Object item, PreparedStatement ps) throws SQLException {
|
||||
CustomerCredit customerCredit = (CustomerCredit) item;
|
||||
ps.setBigDecimal(1, customerCredit.getCredit());
|
||||
ps.setBigDecimal(1, customerCredit.getCredit().add(FIXED_AMOUNT));
|
||||
ps.setLong(2, customerCredit.getId());
|
||||
}
|
||||
|
||||
|
||||
@@ -22,15 +22,13 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="itemWriter" class="org.springframework.batch.sample.item.writer.BatchSqlCustomerCreditIncreaseWriter">
|
||||
<property name="delegate">
|
||||
<bean class="org.springframework.batch.item.database.BatchSqlUpdateItemWriter">
|
||||
<property name="jdbcTemplate" ref="jdbcTemplate" />
|
||||
<property name="sql"><value><![CDATA[UPDATE CUSTOMER SET CREDIT=? WHERE ID=?]]></value></property>
|
||||
<property name="itemPreparedStatementSetter">
|
||||
<bean class="org.springframework.batch.sample.item.writer.CustomerCreditUpdatePreparedStatementSetter"/>
|
||||
</property>
|
||||
</bean>
|
||||
<bean id="itemWriter" class="org.springframework.batch.item.database.BatchSqlUpdateItemWriter">
|
||||
<property name="jdbcTemplate" ref="jdbcTemplate" />
|
||||
<property name="sql">
|
||||
<value><![CDATA[UPDATE CUSTOMER SET CREDIT=? WHERE ID=?]]></value>
|
||||
</property>
|
||||
<property name="itemPreparedStatementSetter">
|
||||
<bean class="org.springframework.batch.sample.item.writer.CustomerCreditUpdatePreparedStatementSetter" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="orderWriter"
|
||||
<bean id="orderWriter"
|
||||
class="org.springframework.batch.item.transform.ItemTransformerItemWriter">
|
||||
<property name="delegate" ref="flatFileTransformerWriter" />
|
||||
<property name="itemTransformer">
|
||||
@@ -61,7 +61,6 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="headerFieldSetMapper"
|
||||
class="org.springframework.batch.sample.mapping.HeaderFieldSetMapper" />
|
||||
<bean id="customerFieldSetMapper"
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration()
|
||||
@ContextConfiguration
|
||||
public class BatchSqlUpdateJobFunctionalTests extends AbstractCustomerCreditIncreaseTests {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,104 +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.item.writer;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class BatchSqlCustomerCreditIncreaseWriterTests {
|
||||
|
||||
private BatchSqlCustomerCreditIncreaseWriter writer = new BatchSqlCustomerCreditIncreaseWriter();
|
||||
|
||||
private ItemWriter delegate;
|
||||
|
||||
private MockControl control = MockControl.createControl(ItemWriter.class);
|
||||
|
||||
private CustomerCredit customerCredit;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
delegate = (ItemWriter) control.getMock();
|
||||
writer.setDelegate(delegate);
|
||||
customerCredit = new CustomerCredit();
|
||||
customerCredit.setId(13);
|
||||
customerCredit.setCredit(new BigDecimal(1000));
|
||||
customerCredit.setName("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterPropertiesSet() throws Exception {
|
||||
try {
|
||||
writer.afterPropertiesSet();
|
||||
fail("Expected IllegalStateException");
|
||||
} catch (IllegalStateException e) {
|
||||
// expected: wrong class
|
||||
String message = e.getMessage();
|
||||
assertTrue("Message does not contain 'instance'"+message, message.indexOf("instance")>=0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.sample.item.writer.BatchSqlCustomerCreditIncreaseWriter#write(CustomerCredit)}.
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testWrite() throws Exception {
|
||||
delegate.write(customerCredit);
|
||||
control.setVoidCallable();
|
||||
control.replay();
|
||||
writer.write(customerCredit);
|
||||
control.verify();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.sample.item.writer.BatchSqlCustomerCreditIncreaseWriter#clear()}.
|
||||
*/
|
||||
@Test
|
||||
public void testClear() {
|
||||
delegate.clear();
|
||||
control.setVoidCallable();
|
||||
control.replay();
|
||||
writer.clear();
|
||||
control.verify();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.sample.item.writer.BatchSqlCustomerCreditIncreaseWriter#flush()}.
|
||||
*/
|
||||
@Test
|
||||
public void testFlush() {
|
||||
delegate.flush();
|
||||
control.setVoidCallable();
|
||||
control.replay();
|
||||
writer.flush();
|
||||
control.verify();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,10 +19,10 @@ import java.math.BigDecimal;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -36,11 +36,9 @@ public class CustomerCreditUpdatePreparedStatementSetterTests {
|
||||
|
||||
private PreparedStatement ps;
|
||||
|
||||
private MockControl control = MockControl.createControl(PreparedStatement.class);
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ps = (PreparedStatement) control.getMock();
|
||||
ps = EasyMock.createMock(PreparedStatement.class);
|
||||
credit = new CustomerCredit();
|
||||
credit.setId(13);
|
||||
credit.setCredit(new BigDecimal(12000));
|
||||
@@ -52,13 +50,13 @@ public class CustomerCreditUpdatePreparedStatementSetterTests {
|
||||
*/
|
||||
@Test
|
||||
public void testSetValues() throws SQLException {
|
||||
ps.setBigDecimal(1, credit.getCredit());
|
||||
control.setVoidCallable();
|
||||
ps.setBigDecimal(1, credit.getCredit().add(CustomerCreditUpdatePreparedStatementSetter.FIXED_AMOUNT));
|
||||
EasyMock.expectLastCall();
|
||||
ps.setLong(2, credit.getId());
|
||||
control.setVoidCallable();
|
||||
control.replay();
|
||||
EasyMock.expectLastCall();
|
||||
EasyMock.replay(ps);
|
||||
setter.setValues(credit, ps);
|
||||
control.verify();
|
||||
EasyMock.verify(ps);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user