BATCH-960: Removed unnecessary test classes
This commit is contained in:
@@ -1,64 +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 static junit.framework.Assert.assertEquals;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor;
|
||||
import org.springframework.batch.item.file.transform.DelimitedLineAggregator;
|
||||
import org.springframework.batch.sample.domain.trade.CustomerCredit;
|
||||
import org.springframework.batch.sample.domain.trade.Trade;
|
||||
|
||||
/**
|
||||
* @author Dan Garrette
|
||||
* @since 2.0
|
||||
*/
|
||||
public class DelegatingTradeLineAggregatorTests {
|
||||
|
||||
@Test
|
||||
public void testAggregateTrade() {
|
||||
BeanWrapperFieldExtractor<Trade> tradeExtractor = new BeanWrapperFieldExtractor<Trade>();
|
||||
tradeExtractor.setNames(new String[] { "isin", "quantity", "price", "customer" });
|
||||
|
||||
DelimitedLineAggregator<Trade> tradeAggregator = new DelimitedLineAggregator<Trade>();
|
||||
tradeAggregator.setFieldExtractor(tradeExtractor);
|
||||
|
||||
BeanWrapperFieldExtractor<CustomerCredit> customerExtractor = new BeanWrapperFieldExtractor<CustomerCredit>();
|
||||
customerExtractor.setNames(new String[] { "id", "name", "credit" });
|
||||
|
||||
DelimitedLineAggregator<CustomerCredit> customerAggregator = new DelimitedLineAggregator<CustomerCredit>();
|
||||
customerAggregator.setFieldExtractor(customerExtractor);
|
||||
|
||||
DelegatingTradeLineAggregator aggregator = new DelegatingTradeLineAggregator();
|
||||
aggregator.setTradeLineAggregator(tradeAggregator);
|
||||
aggregator.setCustomerLineAggregator(customerAggregator);
|
||||
|
||||
Trade t = new Trade("ISIN001", 500, new BigDecimal("4.50"), "Customer1");
|
||||
assertEquals("ISIN001,500,4.50,Customer1", aggregator.aggregate(t));
|
||||
|
||||
CustomerCredit c = new CustomerCredit(256, "customer1", new BigDecimal("3200.00"));
|
||||
assertEquals("256,customer1,3200.00", aggregator.aggregate(c));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAggregateCustomer(){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,110 +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 static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.item.file.FlatFileItemReader;
|
||||
import org.springframework.batch.item.file.transform.DefaultFieldSet;
|
||||
import org.springframework.batch.item.file.transform.FieldSet;
|
||||
import org.springframework.batch.sample.domain.trade.Trade;
|
||||
|
||||
/**
|
||||
* @author Dan Garrette
|
||||
* @since 2.0
|
||||
*/
|
||||
public class MultiLineTradeItemReaderTests {
|
||||
|
||||
private MultiLineTradeItemReader reader = new MultiLineTradeItemReader();
|
||||
|
||||
@Test
|
||||
public void testRead_complete() throws Exception {
|
||||
String isin = "ISIN001";
|
||||
String customer = "customer1";
|
||||
long quantity = (long) 300;
|
||||
BigDecimal price = new BigDecimal("4.50");
|
||||
|
||||
final FieldSet[] data = { new DefaultFieldSet(new String[] { "BEGIN" }),
|
||||
new DefaultFieldSet(new String[] { "INFO", isin, customer }),
|
||||
new DefaultFieldSet(new String[] { "AMNT", "" + quantity, price.toString() }),
|
||||
new DefaultFieldSet(new String[] { "END" }) };
|
||||
|
||||
Trade t = this.readData(data);
|
||||
assertEquals(isin, t.getIsin());
|
||||
assertEquals(customer, t.getCustomer());
|
||||
assertEquals(quantity, t.getQuantity());
|
||||
assertEquals(price, t.getPrice());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRead_noBegin() throws Exception {
|
||||
String isin = "ISIN001";
|
||||
String customer = "customer1";
|
||||
long quantity = (long) 300;
|
||||
BigDecimal price = new BigDecimal("4.50");
|
||||
|
||||
final FieldSet[] data = { new DefaultFieldSet(new String[] { "INFO", isin, customer }),
|
||||
new DefaultFieldSet(new String[] { "AMNT", "" + quantity, price.toString() }),
|
||||
new DefaultFieldSet(new String[] { "END" }) };
|
||||
|
||||
try {
|
||||
this.readData(data);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("No 'BEGIN' was found.", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRead_noEnd() throws Exception {
|
||||
String isin = "ISIN001";
|
||||
String customer = "customer1";
|
||||
long quantity = (long) 300;
|
||||
BigDecimal price = new BigDecimal("4.50");
|
||||
|
||||
final FieldSet[] data = { new DefaultFieldSet(new String[] { "BEGIN" }),
|
||||
new DefaultFieldSet(new String[] { "INFO", isin, customer }),
|
||||
new DefaultFieldSet(new String[] { "AMNT", "" + quantity, price.toString() }) };
|
||||
|
||||
try {
|
||||
this.readData(data);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("No 'END' was found.", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private Trade readData(final FieldSet[] data) throws Exception {
|
||||
this.reader.setDelegate(new FlatFileItemReader<FieldSet>() {
|
||||
private int i = 0;
|
||||
|
||||
public FieldSet read() {
|
||||
if (i < data.length) {
|
||||
return data[i++];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return this.reader.read();
|
||||
}
|
||||
}
|
||||
@@ -1,55 +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.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.item.file.FlatFileItemWriter;
|
||||
import org.springframework.batch.sample.domain.trade.Trade;
|
||||
|
||||
/**
|
||||
* @author Dan Garrette
|
||||
* @since 2.0
|
||||
*/
|
||||
public class MultiLineTradeItemWriterTests {
|
||||
|
||||
private MultiLineTradeItemWriter writer;
|
||||
|
||||
public MultiLineTradeItemWriterTests() {
|
||||
FlatFileItemWriter<String> delegate = new FlatFileItemWriter<String>() {
|
||||
List<String> allItems = new ArrayList<String>();
|
||||
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
this.allItems.addAll(items);
|
||||
}
|
||||
};
|
||||
|
||||
this.writer = new MultiLineTradeItemWriter();
|
||||
this.writer.setDelegate(delegate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrite() throws Exception {
|
||||
Trade t1 = new Trade("ISIN001", 400, new BigDecimal("5.75"), "Customer1");
|
||||
Trade t2 = new Trade("ISIN002", 200, new BigDecimal("6.25"), "Customer2");
|
||||
this.writer.write(Arrays.asList(t1, t2));
|
||||
}
|
||||
}
|
||||
@@ -1,63 +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 static junit.framework.Assert.assertEquals;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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.trade.CustomerCredit;
|
||||
import org.springframework.batch.sample.domain.trade.Trade;
|
||||
import org.springframework.batch.sample.domain.trade.internal.CustomerCreditFieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.trade.internal.TradeFieldSetMapper;
|
||||
|
||||
/**
|
||||
* @author Dan Garrette
|
||||
* @since 2.0
|
||||
*/
|
||||
public class PrefixMatchingCompositeFieldSetMapperTests {
|
||||
|
||||
@Test
|
||||
public void testMapFieldSet() {
|
||||
Map<String, FieldSetMapper<? extends Object>> mappers = new HashMap<String, FieldSetMapper<? extends Object>>();
|
||||
mappers.put("TRAD", new TradeFieldSetMapper());
|
||||
mappers.put("CUST", new CustomerCreditFieldSetMapper());
|
||||
|
||||
PrefixMatchingCompositeFieldSetMapper<Object> mapper = new PrefixMatchingCompositeFieldSetMapper<Object>();
|
||||
mapper.setMappers(mappers);
|
||||
|
||||
String[] tradeNames = new String[] { "isin", "quantity", "price", "customer", "prefix" };
|
||||
String[] tradeValues = new String[] { "ISIN001", "500", "4.50", "Customer1", "TRAD" };
|
||||
FieldSet tradeFS = new DefaultFieldSet(tradeValues, tradeNames);
|
||||
|
||||
String[] customerNames = new String[] { "id", "name", "credit", "prefix" };
|
||||
String[] customerValues = new String[] { "256", "customer1", "3200.00", "CUST" };
|
||||
FieldSet customerFS = new DefaultFieldSet(customerValues, customerNames);
|
||||
|
||||
Trade trade = new Trade("ISIN001", 500, new BigDecimal("4.50"), "Customer1");
|
||||
assertEquals(trade, mapper.mapFieldSet(tradeFS));
|
||||
|
||||
CustomerCredit customer = new CustomerCredit(256, "customer1", new BigDecimal("3200.00"));
|
||||
assertEquals(customer, mapper.mapFieldSet(customerFS));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user