BATCH-1247: Clean up multilineOrderJob sample
This commit is contained in:
@@ -16,50 +16,27 @@
|
||||
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.batch.test.AssertFile.assertFileEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.test.AbstractJobTests;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration()
|
||||
public class MultilineOrderJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
public class MultilineOrderJobFunctionalTests extends AbstractJobTests {
|
||||
|
||||
private static final String EXPECTED_OUTPUT =
|
||||
"BEGIN_ORDER:13100345 2007/02/15 "+
|
||||
"CUSTOMER:20014539 Peter Smith "+
|
||||
"ADDRESS:Oak Street 31/A Small Town00235 "+
|
||||
"BILLING:VISA VISA-12345678903 "+
|
||||
"ITEM:104439104137.49 "+
|
||||
"ITEM:2134776319221.99 "+
|
||||
"END_ORDER: 267.34"+
|
||||
"BEGIN_ORDER:13100346 2007/02/15 "+
|
||||
"CUSTOMER:72155919 "+
|
||||
"ADDRESS:St. Andrews Road 31 London 55342 "+
|
||||
"BILLING:AMEX AMEX-72345678903 "+
|
||||
"ITEM:10443191011070.50 "+
|
||||
"ITEM:213472721921.79 "+
|
||||
"ITEM:104433930179.95 "+
|
||||
"ITEM:213474731955.29 "+
|
||||
"ITEM:1044359501339.99 "+
|
||||
"END_ORDER: 14043.74";
|
||||
private static final String ACTUAL = "target/test-outputs/multilineOrderOutput.txt";
|
||||
private static final String EXPECTED = "data/multilineOrderJob/result/multilineOrderOutput.txt";
|
||||
|
||||
|
||||
private Resource fileOutputLocator = new FileSystemResource("target/test-outputs/20070122.teststream.multilineOrderStep.TEMP.txt");
|
||||
|
||||
/**
|
||||
* Read the output file and compare it with expected string
|
||||
* @throws IOException
|
||||
*/
|
||||
protected void validatePostConditions() throws Exception {
|
||||
assertEquals(EXPECTED_OUTPUT, StringUtils.replace(IOUtils.toString(fileOutputLocator.getInputStream()), System.getProperty("line.separator"), ""));
|
||||
@Test
|
||||
public void testJob() throws Exception {
|
||||
this.launchJob();
|
||||
assertFileEquals(new ClassPathResource(EXPECTED), new FileSystemResource(ACTUAL));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,10 +3,9 @@ package org.springframework.batch.sample.domain.order;
|
||||
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.order.internal.AddressFieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.order.internal.mapper.AddressFieldSetMapper;
|
||||
import org.springframework.batch.sample.support.AbstractFieldSetMapperTests;
|
||||
|
||||
|
||||
public class AddressFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
|
||||
private static final String ADDRESSEE = "Jan Hrach";
|
||||
@@ -16,8 +15,6 @@ public class AddressFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
private static final String STATE = "";
|
||||
private static final String COUNTRY = "Slovakia";
|
||||
private static final String ZIP_CODE = "80000";
|
||||
|
||||
|
||||
|
||||
protected Object expectedDomainObject() {
|
||||
Address address = new Address();
|
||||
@@ -32,19 +29,13 @@ public class AddressFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
}
|
||||
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens =
|
||||
new String[]{ADDRESSEE, ADDRESS_LINE_1, ADDRESS_LINE_2, CITY, STATE, COUNTRY, ZIP_CODE};
|
||||
String[] columnNames =
|
||||
new String[]{
|
||||
AddressFieldSetMapper.ADDRESSEE_COLUMN,
|
||||
AddressFieldSetMapper.ADDRESS_LINE1_COLUMN,
|
||||
AddressFieldSetMapper.ADDRESS_LINE2_COLUMN,
|
||||
AddressFieldSetMapper.CITY_COLUMN,
|
||||
AddressFieldSetMapper.STATE_COLUMN,
|
||||
AddressFieldSetMapper.COUNTRY_COLUMN,
|
||||
AddressFieldSetMapper.ZIP_CODE_COLUMN };
|
||||
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
String[] tokens = new String[] { ADDRESSEE, ADDRESS_LINE_1, ADDRESS_LINE_2, CITY, STATE, COUNTRY, ZIP_CODE };
|
||||
String[] columnNames = new String[] { AddressFieldSetMapper.ADDRESSEE_COLUMN,
|
||||
AddressFieldSetMapper.ADDRESS_LINE1_COLUMN, AddressFieldSetMapper.ADDRESS_LINE2_COLUMN,
|
||||
AddressFieldSetMapper.CITY_COLUMN, AddressFieldSetMapper.STATE_COLUMN,
|
||||
AddressFieldSetMapper.COUNTRY_COLUMN, AddressFieldSetMapper.ZIP_CODE_COLUMN };
|
||||
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
protected FieldSetMapper<Address> fieldSetMapper() {
|
||||
|
||||
@@ -3,14 +3,14 @@ package org.springframework.batch.sample.domain.order;
|
||||
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.order.internal.BillingFieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.order.internal.mapper.BillingFieldSetMapper;
|
||||
import org.springframework.batch.sample.support.AbstractFieldSetMapperTests;
|
||||
|
||||
public class BillingFieldSetMapperTests extends AbstractFieldSetMapperTests{
|
||||
public class BillingFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
|
||||
private static final String PAYMENT_ID = "777";
|
||||
private static final String PAYMENT_DESC = "My last penny";
|
||||
|
||||
|
||||
protected Object expectedDomainObject() {
|
||||
BillingInfo bInfo = new BillingInfo();
|
||||
bInfo.setPaymentDesc(PAYMENT_DESC);
|
||||
@@ -19,12 +19,9 @@ public class BillingFieldSetMapperTests extends AbstractFieldSetMapperTests{
|
||||
}
|
||||
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens = new String[]{
|
||||
PAYMENT_ID,
|
||||
PAYMENT_DESC};
|
||||
String[] columnNames = new String[]{
|
||||
BillingFieldSetMapper.PAYMENT_TYPE_ID_COLUMN,
|
||||
BillingFieldSetMapper.PAYMENT_DESC_COLUMN};
|
||||
String[] tokens = new String[] { PAYMENT_ID, PAYMENT_DESC };
|
||||
String[] columnNames = new String[] { BillingFieldSetMapper.PAYMENT_TYPE_ID_COLUMN,
|
||||
BillingFieldSetMapper.PAYMENT_DESC_COLUMN };
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,12 @@ package org.springframework.batch.sample.domain.order;
|
||||
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.order.internal.CustomerFieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.order.internal.mapper.CustomerFieldSetMapper;
|
||||
import org.springframework.batch.sample.support.AbstractFieldSetMapperTests;
|
||||
|
||||
public class CustomerFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
|
||||
private static final boolean BUSINESS_CUSTOMER = false;
|
||||
//private static final String COMPANY_NAME = "Accenture";
|
||||
private static final String FIRST_NAME = "Jan";
|
||||
private static final String LAST_NAME = "Hrach";
|
||||
private static final String MIDDLE_NAME = "";
|
||||
@@ -30,23 +29,13 @@ public class CustomerFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
}
|
||||
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens = new String[]{
|
||||
Customer.LINE_ID_NON_BUSINESS_CUST,
|
||||
FIRST_NAME,
|
||||
LAST_NAME,
|
||||
MIDDLE_NAME,
|
||||
CustomerFieldSetMapper.TRUE_SYMBOL,
|
||||
String.valueOf(REG_ID),
|
||||
CustomerFieldSetMapper.TRUE_SYMBOL};
|
||||
String[] columnNames = new String[]{
|
||||
CustomerFieldSetMapper.LINE_ID_COLUMN,
|
||||
CustomerFieldSetMapper.FIRST_NAME_COLUMN,
|
||||
CustomerFieldSetMapper.LAST_NAME_COLUMN,
|
||||
CustomerFieldSetMapper.MIDDLE_NAME_COLUMN,
|
||||
CustomerFieldSetMapper.REGISTERED_COLUMN,
|
||||
CustomerFieldSetMapper.REG_ID_COLUMN,
|
||||
CustomerFieldSetMapper.VIP_COLUMN};
|
||||
|
||||
String[] tokens = new String[] { Customer.LINE_ID_NON_BUSINESS_CUST, FIRST_NAME, LAST_NAME, MIDDLE_NAME,
|
||||
CustomerFieldSetMapper.TRUE_SYMBOL, String.valueOf(REG_ID), CustomerFieldSetMapper.TRUE_SYMBOL };
|
||||
String[] columnNames = new String[] { CustomerFieldSetMapper.LINE_ID_COLUMN,
|
||||
CustomerFieldSetMapper.FIRST_NAME_COLUMN, CustomerFieldSetMapper.LAST_NAME_COLUMN,
|
||||
CustomerFieldSetMapper.MIDDLE_NAME_COLUMN, CustomerFieldSetMapper.REGISTERED_COLUMN,
|
||||
CustomerFieldSetMapper.REG_ID_COLUMN, CustomerFieldSetMapper.VIP_COLUMN };
|
||||
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2008 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.domain.order;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.item.file.transform.DelimitedLineAggregator;
|
||||
import org.springframework.batch.item.file.transform.LineAggregator;
|
||||
import org.springframework.batch.sample.domain.order.internal.OrderProcessor;
|
||||
|
||||
public class FlatFileOrderAggregatorTests {
|
||||
|
||||
@Test
|
||||
public void testWrite() throws Exception {
|
||||
|
||||
// Create and set-up Order
|
||||
Order order = new Order();
|
||||
|
||||
order.setOrderDate(new GregorianCalendar(2007, GregorianCalendar.JUNE, 1).getTime());
|
||||
order.setCustomer(new Customer());
|
||||
order.setBilling(new BillingInfo());
|
||||
order.setBillingAddress(new Address());
|
||||
List<LineItem> lineItems = new ArrayList<LineItem>();
|
||||
LineItem item = new LineItem();
|
||||
item.setPrice(BigDecimal.valueOf(0));
|
||||
lineItems.add(item);
|
||||
lineItems.add(item);
|
||||
order.setLineItems(lineItems);
|
||||
order.setTotalPrice(BigDecimal.valueOf(0));
|
||||
|
||||
// create aggregator stub
|
||||
LineAggregator<Object[]> aggregator = new DelimitedLineAggregator<Object[]>();
|
||||
|
||||
// create map of aggregators and set it to writer
|
||||
Map<String, LineAggregator<Object[]>> aggregators = new HashMap<String, LineAggregator<Object[]>>();
|
||||
|
||||
OrderProcessor converter = new OrderProcessor();
|
||||
aggregators.put("header", aggregator);
|
||||
aggregators.put("customer", aggregator);
|
||||
aggregators.put("address", aggregator);
|
||||
aggregators.put("billing", aggregator);
|
||||
aggregators.put("item", aggregator);
|
||||
aggregators.put("footer", aggregator);
|
||||
converter.setAggregators(aggregators);
|
||||
|
||||
// call tested method
|
||||
List<String> list = converter.process(order);
|
||||
|
||||
// verify method calls
|
||||
assertEquals(7, list.size());
|
||||
assertEquals("BEGIN_ORDER:,0,2007/06/01", list.get(0));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import java.util.Calendar;
|
||||
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.order.internal.HeaderFieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.order.internal.mapper.HeaderFieldSetMapper;
|
||||
import org.springframework.batch.sample.support.AbstractFieldSetMapperTests;
|
||||
|
||||
public class HeaderFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
@@ -24,14 +24,9 @@ public class HeaderFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
}
|
||||
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens = new String[]{
|
||||
String.valueOf(ORDER_ID),
|
||||
DATE
|
||||
};
|
||||
String[] columnNames = new String[]{
|
||||
HeaderFieldSetMapper.ORDER_ID_COLUMN,
|
||||
HeaderFieldSetMapper.ORDER_DATE_COLUMN
|
||||
};
|
||||
String[] tokens = new String[] { String.valueOf(ORDER_ID), DATE };
|
||||
String[] columnNames = new String[] { HeaderFieldSetMapper.ORDER_ID_COLUMN,
|
||||
HeaderFieldSetMapper.ORDER_DATE_COLUMN };
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ import java.math.BigDecimal;
|
||||
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.order.internal.OrderItemFieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.order.internal.mapper.OrderItemFieldSetMapper;
|
||||
import org.springframework.batch.sample.support.AbstractFieldSetMapperTests;
|
||||
|
||||
public class OrderItemFieldSetMapperTests extends AbstractFieldSetMapperTests{
|
||||
public class OrderItemFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
|
||||
private static final BigDecimal DISCOUNT_AMOUNT = new BigDecimal("1");
|
||||
private static final BigDecimal DISCOUNT_PERC = new BigDecimal("2");
|
||||
@@ -33,26 +33,14 @@ public class OrderItemFieldSetMapperTests extends AbstractFieldSetMapperTests{
|
||||
}
|
||||
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens = new String[]{
|
||||
String.valueOf(DISCOUNT_AMOUNT),
|
||||
String.valueOf(DISCOUNT_PERC),
|
||||
String.valueOf(HANDLING_PRICE),
|
||||
String.valueOf(ITEM_ID),
|
||||
String.valueOf(PRICE),
|
||||
String.valueOf(QUANTITY),
|
||||
String.valueOf(SHIPPING_PRICE),
|
||||
String.valueOf(TOTAL_PRICE)
|
||||
};
|
||||
String[] columnNames = new String[]{
|
||||
OrderItemFieldSetMapper.DISCOUNT_AMOUNT_COLUMN,
|
||||
OrderItemFieldSetMapper.DISCOUNT_PERC_COLUMN,
|
||||
OrderItemFieldSetMapper.HANDLING_PRICE_COLUMN,
|
||||
OrderItemFieldSetMapper.ITEM_ID_COLUMN,
|
||||
OrderItemFieldSetMapper.PRICE_COLUMN,
|
||||
OrderItemFieldSetMapper.QUANTITY_COLUMN,
|
||||
OrderItemFieldSetMapper.SHIPPING_PRICE_COLUMN,
|
||||
OrderItemFieldSetMapper.TOTAL_PRICE_COLUMN
|
||||
};
|
||||
String[] tokens = new String[] { String.valueOf(DISCOUNT_AMOUNT), String.valueOf(DISCOUNT_PERC),
|
||||
String.valueOf(HANDLING_PRICE), String.valueOf(ITEM_ID), String.valueOf(PRICE),
|
||||
String.valueOf(QUANTITY), String.valueOf(SHIPPING_PRICE), String.valueOf(TOTAL_PRICE) };
|
||||
String[] columnNames = new String[] { OrderItemFieldSetMapper.DISCOUNT_AMOUNT_COLUMN,
|
||||
OrderItemFieldSetMapper.DISCOUNT_PERC_COLUMN, OrderItemFieldSetMapper.HANDLING_PRICE_COLUMN,
|
||||
OrderItemFieldSetMapper.ITEM_ID_COLUMN, OrderItemFieldSetMapper.PRICE_COLUMN,
|
||||
OrderItemFieldSetMapper.QUANTITY_COLUMN, OrderItemFieldSetMapper.SHIPPING_PRICE_COLUMN,
|
||||
OrderItemFieldSetMapper.TOTAL_PRICE_COLUMN };
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ package org.springframework.batch.sample.domain.order;
|
||||
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.order.internal.ShippingFieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.order.internal.mapper.ShippingFieldSetMapper;
|
||||
import org.springframework.batch.sample.support.AbstractFieldSetMapperTests;
|
||||
|
||||
public class ShippingFieldSetMapperTests extends AbstractFieldSetMapperTests{
|
||||
public class ShippingFieldSetMapperTests extends AbstractFieldSetMapperTests {
|
||||
|
||||
private static final String SHIPPER_ID = "1";
|
||||
private static final String SHIPPING_INFO = "most interesting and informative shipping info ever";
|
||||
@@ -21,12 +21,9 @@ public class ShippingFieldSetMapperTests extends AbstractFieldSetMapperTests{
|
||||
}
|
||||
|
||||
protected FieldSet fieldSet() {
|
||||
String[] tokens = new String[]{SHIPPER_ID, SHIPPING_INFO, SHIPPING_TYPE_ID};
|
||||
String[] columnNames = new String[]{
|
||||
ShippingFieldSetMapper.SHIPPER_ID_COLUMN,
|
||||
ShippingFieldSetMapper.ADDITIONAL_SHIPPING_INFO_COLUMN,
|
||||
ShippingFieldSetMapper.SHIPPING_TYPE_ID_COLUMN
|
||||
};
|
||||
String[] tokens = new String[] { SHIPPER_ID, SHIPPING_INFO, SHIPPING_TYPE_ID };
|
||||
String[] columnNames = new String[] { ShippingFieldSetMapper.SHIPPER_ID_COLUMN,
|
||||
ShippingFieldSetMapper.ADDITIONAL_SHIPPING_INFO_COLUMN, ShippingFieldSetMapper.SHIPPING_TYPE_ID_COLUMN };
|
||||
return new DefaultFieldSet(tokens, columnNames);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user