BATCH-959: applied patch
This commit is contained in:
@@ -1,59 +1,55 @@
|
||||
/*
|
||||
* 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 items) throws Exception {
|
||||
this.allItems.addAll(items);
|
||||
}
|
||||
|
||||
public List<String> getAllItems() {
|
||||
return this.allItems;
|
||||
}
|
||||
};
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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,44 +1,44 @@
|
||||
/*
|
||||
* 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.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.batch.item.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.item.file.transform.FieldSet;
|
||||
|
||||
/**
|
||||
* This class is used to delegate to a {@link FieldSetMapper} based on one field
|
||||
* in the {@link FieldSet}.
|
||||
*
|
||||
* @author Dan Garrette
|
||||
* @since 2.0
|
||||
*/
|
||||
public class PrefixMatchingCompositeFieldSetMapper<T> implements FieldSetMapper<T> {
|
||||
|
||||
private Map<String, FieldSetMapper<T>> mappers = new HashMap<String, FieldSetMapper<T>>();
|
||||
|
||||
public T mapFieldSet(FieldSet fieldSet) {
|
||||
String prefix = fieldSet.readString("prefix");
|
||||
return this.mappers.get(prefix).mapFieldSet(fieldSet);
|
||||
}
|
||||
|
||||
public void setMappers(Map<String, FieldSetMapper<T>> mappers) {
|
||||
this.mappers = mappers;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.batch.item.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.item.file.transform.FieldSet;
|
||||
|
||||
/**
|
||||
* This class is used to delegate to a {@link FieldSetMapper} based on one field
|
||||
* in the {@link FieldSet}.
|
||||
*
|
||||
* @author Dan Garrette
|
||||
* @since 2.0
|
||||
*/
|
||||
public class PrefixMatchingCompositeFieldSetMapper<T> implements FieldSetMapper<T> {
|
||||
|
||||
private Map<String, FieldSetMapper<? extends T>> mappers = new HashMap<String, FieldSetMapper<? extends T>>();
|
||||
|
||||
public T mapFieldSet(FieldSet fieldSet) {
|
||||
String prefix = fieldSet.readString("prefix");
|
||||
return this.mappers.get(prefix).mapFieldSet(fieldSet);
|
||||
}
|
||||
|
||||
public void setMappers(Map<String, FieldSetMapper<? extends T>> mappers) {
|
||||
this.mappers = mappers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
/*
|
||||
* 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> mappers = new HashMap<String, FieldSetMapper>();
|
||||
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));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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