diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/DelegatingTradeLineAggregatorTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/DelegatingTradeLineAggregatorTests.java deleted file mode 100644 index 677a00ef1..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/DelegatingTradeLineAggregatorTests.java +++ /dev/null @@ -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 tradeExtractor = new BeanWrapperFieldExtractor(); - tradeExtractor.setNames(new String[] { "isin", "quantity", "price", "customer" }); - - DelimitedLineAggregator tradeAggregator = new DelimitedLineAggregator(); - tradeAggregator.setFieldExtractor(tradeExtractor); - - BeanWrapperFieldExtractor customerExtractor = new BeanWrapperFieldExtractor(); - customerExtractor.setNames(new String[] { "id", "name", "credit" }); - - DelimitedLineAggregator customerAggregator = new DelimitedLineAggregator(); - 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(){ - - } -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/MultiLineTradeItemReaderTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/MultiLineTradeItemReaderTests.java deleted file mode 100644 index 5d813d1c9..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/MultiLineTradeItemReaderTests.java +++ /dev/null @@ -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
() { - private int i = 0; - - public FieldSet read() { - if (i < data.length) { - return data[i++]; - } - return null; - } - }); - return this.reader.read(); - } -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/MultiLineTradeItemWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/MultiLineTradeItemWriterTests.java deleted file mode 100644 index 9ea689cf7..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/MultiLineTradeItemWriterTests.java +++ /dev/null @@ -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 delegate = new FlatFileItemWriter() { - List allItems = new ArrayList(); - - public void write(List 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)); - } -} diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/PrefixMatchingCompositeFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/PrefixMatchingCompositeFieldSetMapperTests.java deleted file mode 100644 index fe21110a1..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/internal/PrefixMatchingCompositeFieldSetMapperTests.java +++ /dev/null @@ -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> mappers = new HashMap>(); - mappers.put("TRAD", new TradeFieldSetMapper()); - mappers.put("CUST", new CustomerCreditFieldSetMapper()); - - PrefixMatchingCompositeFieldSetMapper mapper = new PrefixMatchingCompositeFieldSetMapper(); - 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)); - } -}