RESOLVED - BATCH-893: Remove the HibernateAwareItemWriter?

-removed HibernateAwareItemWriter and fixed sample
-moved business logic from CustomerCreditIncreaseItemWriter into processor
This commit is contained in:
robokaso
2008-10-30 11:11:10 +00:00
parent 4718f0f006
commit a5c6347e89
7 changed files with 104 additions and 57 deletions

View File

@@ -10,11 +10,11 @@ import java.util.List;
import javax.sql.DataSource;
import org.springframework.batch.sample.domain.trade.internal.CustomerCreditIncreaseWriter;
import org.springframework.batch.sample.domain.trade.internal.CustomerCreditIncreaseProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
@@ -33,7 +33,7 @@ public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValida
protected PlatformTransactionManager transactionManager;
private static final BigDecimal CREDIT_INCREASE = CustomerCreditIncreaseWriter.FIXED_AMOUNT;
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)",

View File

@@ -1,22 +1,20 @@
package org.springframework.batch.sample.domain.trade.internal;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import java.math.BigDecimal;
import java.util.Collections;
import org.junit.Test;
import org.springframework.batch.sample.domain.trade.CustomerCredit;
import org.springframework.batch.sample.domain.trade.CustomerCreditDao;
/**
* Tests for {@link CustomerCreditIncreaseWriter}.
* Tests for {@link CustomerCreditItemWriter}.
*
* @author Robert Kasanicky
*/
public class CustomerCreditIncreaseProcessorTests {
private CustomerCreditIncreaseWriter writer = new CustomerCreditIncreaseWriter();
private CustomerCreditIncreaseProcessor tested = new CustomerCreditIncreaseProcessor();
/*
* Increases customer's credit by fixed value
@@ -25,23 +23,9 @@ public class CustomerCreditIncreaseProcessorTests {
public void testProcess() throws Exception {
final BigDecimal oldCredit = new BigDecimal(10.54);
class CustomerDaoStub implements CustomerCreditDao {
public void writeCredit(CustomerCredit customerCredit) throws Exception {
BigDecimal expectedCredit = oldCredit.add(CustomerCreditIncreaseWriter.FIXED_AMOUNT);
assertTrue(customerCredit.getCredit().compareTo(expectedCredit) == 0);
}
}
CustomerCredit customerCredit = new CustomerCredit();
customerCredit.setId(1);
customerCredit.setName("testCustomer");
writer.setCustomerCreditDao(new CustomerDaoStub());
customerCredit.setCredit(oldCredit);
writer.write(Collections.singletonList(customerCredit));
assertEquals(oldCredit.add(CustomerCreditIncreaseProcessor.FIXED_AMOUNT),tested.process(customerCredit).getCredit());
}
}