RESOLVED - issue BATCH-289: FieldSet should be an interface
http://jira.springframework.org/browse/BATCH-289 Created interface and moved implementation to DefaultFieldSet.
This commit is contained in:
@@ -21,8 +21,9 @@ import java.io.IOException;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.DefaultFlatFileItemReader;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.mapping.DefaultFieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.transform.LineTokenizer;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
@@ -48,7 +49,7 @@ public class DefaultFlatFileItemReaderTests extends TestCase {
|
||||
// simple stub instead of a realistic tokenizer
|
||||
private LineTokenizer tokenizer = new LineTokenizer() {
|
||||
public FieldSet tokenize(String line) {
|
||||
return new FieldSet(new String[]{line});
|
||||
return new DefaultFieldSet(new String[]{line});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.text.ParseException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.DefaultFieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
|
||||
public class FieldSetTests extends TestCase {
|
||||
@@ -38,7 +39,7 @@ public class FieldSetTests extends TestCase {
|
||||
names = new String[] { "String", "Boolean", "Char", "Byte", "Short", "Integer", "Long", "Float", "Double",
|
||||
"BigDecimal", "Null", "Date", "DatePattern", "BlankInput" };
|
||||
|
||||
fieldSet = new FieldSet(tokens, names);
|
||||
fieldSet = new DefaultFieldSet(tokens, names);
|
||||
assertEquals(14, fieldSet.getFieldCount());
|
||||
|
||||
}
|
||||
@@ -48,7 +49,7 @@ public class FieldSetTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testNamesNotKnown() throws Exception {
|
||||
fieldSet = new FieldSet(new String[]{"foo"});
|
||||
fieldSet = new DefaultFieldSet(new String[]{"foo"});
|
||||
try {
|
||||
fieldSet.getNames();
|
||||
fail("Expected IllegalStateException");
|
||||
@@ -162,7 +163,7 @@ public class FieldSetTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testReadBooleanFalse() {
|
||||
fieldSet = new FieldSet(new String[] { "false" });
|
||||
fieldSet = new DefaultFieldSet(new String[] { "false" });
|
||||
assertFalse(fieldSet.readBoolean(0));
|
||||
}
|
||||
|
||||
@@ -217,7 +218,7 @@ public class FieldSetTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testReadLongWithPadding() throws Exception {
|
||||
fieldSet = new FieldSet(new String[] {"000009"});
|
||||
fieldSet = new DefaultFieldSet(new String[] {"000009"});
|
||||
assertEquals(9, fieldSet.readLong(0));
|
||||
}
|
||||
|
||||
@@ -325,12 +326,12 @@ public class FieldSetTests extends TestCase {
|
||||
public void testEquals() {
|
||||
|
||||
assertEquals(fieldSet, fieldSet);
|
||||
assertEquals(fieldSet, new FieldSet(tokens));
|
||||
assertEquals(fieldSet, new DefaultFieldSet(tokens));
|
||||
|
||||
String[] tokens1 = new String[] { "token1" };
|
||||
String[] tokens2 = new String[] { "token1" };
|
||||
FieldSet fs1 = new FieldSet(tokens1);
|
||||
FieldSet fs2 = new FieldSet(tokens2);
|
||||
FieldSet fs1 = new DefaultFieldSet(tokens1);
|
||||
FieldSet fs2 = new DefaultFieldSet(tokens2);
|
||||
assertEquals(fs1, fs2);
|
||||
}
|
||||
|
||||
@@ -343,30 +344,30 @@ public class FieldSetTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testEqualsNullTokens() {
|
||||
assertFalse(new FieldSet(null).equals(fieldSet));
|
||||
assertFalse(new DefaultFieldSet(null).equals(fieldSet));
|
||||
}
|
||||
|
||||
public void testEqualsNotEqual() throws Exception {
|
||||
|
||||
String[] tokens1 = new String[] { "token1" };
|
||||
String[] tokens2 = new String[] { "token1", "token2" };
|
||||
FieldSet fs1 = new FieldSet(tokens1);
|
||||
FieldSet fs2 = new FieldSet(tokens2);
|
||||
FieldSet fs1 = new DefaultFieldSet(tokens1);
|
||||
FieldSet fs2 = new DefaultFieldSet(tokens2);
|
||||
assertFalse(fs1.equals(fs2));
|
||||
|
||||
}
|
||||
|
||||
public void testHashCode() throws Exception {
|
||||
assertEquals(fieldSet.hashCode(), new FieldSet(tokens).hashCode());
|
||||
assertEquals(fieldSet.hashCode(), new DefaultFieldSet(tokens).hashCode());
|
||||
}
|
||||
|
||||
public void testHashCodeWithNullTokens() throws Exception {
|
||||
assertEquals(0, new FieldSet(null).hashCode());
|
||||
assertEquals(0, new DefaultFieldSet(null).hashCode());
|
||||
}
|
||||
|
||||
public void testConstructor() throws Exception {
|
||||
try {
|
||||
new FieldSet(new String[] { "1", "2" }, new String[] { "a" });
|
||||
new DefaultFieldSet(new String[] { "1", "2" }, new String[] { "a" });
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
@@ -375,28 +376,28 @@ public class FieldSetTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testToStringWithNames() throws Exception {
|
||||
fieldSet = new FieldSet(new String[] { "foo", "bar" }, new String[] { "Foo", "Bar" });
|
||||
fieldSet = new DefaultFieldSet(new String[] { "foo", "bar" }, new String[] { "Foo", "Bar" });
|
||||
assertTrue(fieldSet.toString().indexOf("Foo=foo") >= 0);
|
||||
}
|
||||
|
||||
public void testToStringWithoutNames() throws Exception {
|
||||
fieldSet = new FieldSet(new String[] { "foo", "bar" });
|
||||
fieldSet = new DefaultFieldSet(new String[] { "foo", "bar" });
|
||||
assertTrue(fieldSet.toString().indexOf("foo") >= 0);
|
||||
}
|
||||
|
||||
public void testToStringNullTokens() throws Exception {
|
||||
fieldSet = new FieldSet(null);
|
||||
fieldSet = new DefaultFieldSet(null);
|
||||
assertEquals("", fieldSet.toString());
|
||||
}
|
||||
|
||||
public void testProperties() throws Exception {
|
||||
assertEquals("foo", new FieldSet(new String[] { "foo", "bar" }, new String[] { "Foo", "Bar" }).getProperties()
|
||||
assertEquals("foo", new DefaultFieldSet(new String[] { "foo", "bar" }, new String[] { "Foo", "Bar" }).getProperties()
|
||||
.getProperty("Foo"));
|
||||
}
|
||||
|
||||
public void testPropertiesWithNoNames() throws Exception {
|
||||
try {
|
||||
new FieldSet(new String[] { "foo", "bar" }).getProperties();
|
||||
new DefaultFieldSet(new String[] { "foo", "bar" }).getProperties();
|
||||
fail("Expected IllegalStateException");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
@@ -406,19 +407,19 @@ public class FieldSetTests extends TestCase {
|
||||
|
||||
public void testPropertiesWithWhiteSpace() throws Exception{
|
||||
|
||||
assertEquals("bar", new FieldSet(new String[] { "foo", "bar " }, new String[] { "Foo", "Bar"}).getProperties().getProperty("Bar"));
|
||||
assertEquals("bar", new DefaultFieldSet(new String[] { "foo", "bar " }, new String[] { "Foo", "Bar"}).getProperties().getProperty("Bar"));
|
||||
}
|
||||
|
||||
public void testPropertiesWithNullValues() throws Exception{
|
||||
|
||||
fieldSet = new FieldSet(new String[] { null, "bar" }, new String[] { "Foo", "Bar"});
|
||||
fieldSet = new DefaultFieldSet(new String[] { null, "bar" }, new String[] { "Foo", "Bar"});
|
||||
assertEquals("bar", fieldSet.getProperties().getProperty("Bar"));
|
||||
assertEquals(null, fieldSet.getProperties().getProperty("Foo"));
|
||||
}
|
||||
|
||||
public void testAccessByNameWhenNamesMissing() throws Exception {
|
||||
try {
|
||||
new FieldSet(new String[] { "1", "2" }).readInt("a");
|
||||
new DefaultFieldSet(new String[] { "1", "2" }).readInt("a");
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
@@ -435,7 +436,7 @@ public class FieldSetTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testPaddedLong(){
|
||||
FieldSet fs = new FieldSet(new String[]{"00000009"});
|
||||
FieldSet fs = new DefaultFieldSet(new String[]{"00000009"});
|
||||
|
||||
long value = fs.readLong(0);
|
||||
assertEquals(value, 9);
|
||||
|
||||
@@ -25,8 +25,9 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.exception.BatchEnvironmentException;
|
||||
import org.springframework.batch.io.exception.FlatFileParsingException;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.mapping.DefaultFieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.separator.DefaultRecordSeparatorPolicy;
|
||||
import org.springframework.batch.io.file.transform.DelimitedLineTokenizer;
|
||||
import org.springframework.batch.io.file.transform.LineTokenizer;
|
||||
@@ -52,7 +53,7 @@ public class SimpleFlatFileItemReaderTests extends TestCase {
|
||||
// simple stub instead of a realistic tokenizer
|
||||
private LineTokenizer tokenizer = new LineTokenizer() {
|
||||
public FieldSet tokenize(String line) {
|
||||
return new FieldSet(new String[] { line });
|
||||
return new DefaultFieldSet(new String[] { line });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
mapper.setTargetType(TestObject.class);
|
||||
mapper.afterPropertiesSet();
|
||||
|
||||
FieldSet fieldSet = new FieldSet(new String[] { "This is some dummy string", "true", "C" }, new String[] {
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" }, new String[] {
|
||||
"varString", "varBoolean", "varChar" });
|
||||
TestObject result = (TestObject) mapper.mapLine(fieldSet);
|
||||
assertEquals("This is some dummy string", result.getVarString());
|
||||
@@ -79,7 +79,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
context.getBeanFactory().registerSingleton("bean", new TestObject());
|
||||
mapper.setPrototypeBeanName("bean");
|
||||
|
||||
FieldSet fieldSet = new FieldSet(new String[] { "This is some dummy string", "true", "C" }, new String[] {
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" }, new String[] {
|
||||
"varString", "varBoolean", "varChar" });
|
||||
TestObject result = (TestObject) mapper.mapLine(fieldSet);
|
||||
assertEquals("This is some dummy string", result.getVarString());
|
||||
@@ -94,7 +94,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
context.getBeanFactory().registerSingleton("bean", new TestObject());
|
||||
mapper.setPrototypeBeanName("bean");
|
||||
|
||||
FieldSet fieldSet = new FieldSet(new String[] { "This is some dummy string", "true", "C" }, new String[] {
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" }, new String[] {
|
||||
"VarString", "VAR_BOOLEAN", "VAR_CHAR" });
|
||||
TestObject result = (TestObject) mapper.mapLine(fieldSet);
|
||||
assertEquals("This is some dummy string", result.getVarString());
|
||||
@@ -107,7 +107,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
|
||||
BeanWrapperFieldSetMapper mapper = (BeanWrapperFieldSetMapper) context.getBean("fieldSetMapper");
|
||||
|
||||
FieldSet fieldSet = new FieldSet(new String[] { "This is some dummy string", "true", "C" }, new String[] {
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" }, new String[] {
|
||||
"varString", "varBoolean", "varChar" });
|
||||
TestObject result = (TestObject) mapper.mapLine(fieldSet);
|
||||
assertEquals("This is some dummy string", result.getVarString());
|
||||
@@ -128,7 +128,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
context.getBeanFactory().registerSingleton("bean", testNestedA);
|
||||
mapper.setPrototypeBeanName("bean");
|
||||
|
||||
FieldSet fieldSet = new FieldSet(new String[] { "This is some dummy string", "1", "Another dummy", "2" },
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "1", "Another dummy", "2" },
|
||||
new String[] { "valueA", "valueB", "testObjectB.valueA", "testObjectB.testObjectC.value" });
|
||||
|
||||
TestNestedA result = (TestNestedA) mapper.mapLine(fieldSet);
|
||||
@@ -148,7 +148,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
context.getBeanFactory().registerSingleton("bean", testNestedA);
|
||||
mapper.setPrototypeBeanName("bean");
|
||||
|
||||
FieldSet fieldSet = new FieldSet(new String[] { "This is some dummy string", "1" }, new String[] { "VALUE_A",
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "1" }, new String[] { "VALUE_A",
|
||||
"VALUE_B" });
|
||||
|
||||
TestNestedA result = (TestNestedA) mapper.mapLine(fieldSet);
|
||||
@@ -166,7 +166,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
context.getBeanFactory().registerSingleton("bean", testNestedC);
|
||||
mapper.setPrototypeBeanName("bean");
|
||||
|
||||
FieldSet fieldSet = new FieldSet(new String[] { "1" }, new String[] { "foo" });
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "1" }, new String[] { "foo" });
|
||||
|
||||
TestNestedC result = (TestNestedC) mapper.mapLine(fieldSet);
|
||||
|
||||
@@ -187,7 +187,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
context.getBeanFactory().registerSingleton("bean", testNestedA);
|
||||
mapper.setPrototypeBeanName("bean");
|
||||
|
||||
FieldSet fieldSet = new FieldSet(new String[] { "Another dummy", "2" }, new String[] { "TestObjectB.ValueA",
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "Another dummy", "2" }, new String[] { "TestObjectB.ValueA",
|
||||
"TestObjectB.TestObjectC.Value" });
|
||||
|
||||
TestNestedA result = (TestNestedA) mapper.mapLine(fieldSet);
|
||||
@@ -207,7 +207,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
context.getBeanFactory().registerSingleton("bean", testNestedA);
|
||||
mapper.setPrototypeBeanName("bean");
|
||||
|
||||
FieldSet fieldSet = new FieldSet(new String[] { "Another dummy" }, new String[] { "TestObjectB.foo" });
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "Another dummy" }, new String[] { "TestObjectB.foo" });
|
||||
|
||||
try {
|
||||
mapper.mapLine(fieldSet);
|
||||
@@ -229,7 +229,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
context.getBeanFactory().registerSingleton("bean", testNestedA);
|
||||
mapper.setPrototypeBeanName("bean");
|
||||
|
||||
FieldSet fieldSet = new FieldSet(new String[] { "2" }, new String[] { "TestObjectA.garbage" });
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "2" }, new String[] { "TestObjectA.garbage" });
|
||||
|
||||
try {
|
||||
mapper.mapLine(fieldSet);
|
||||
@@ -280,7 +280,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
context.getBeanFactory().registerSingleton("bean", nestedList);
|
||||
mapper.setPrototypeBeanName("bean");
|
||||
|
||||
FieldSet fieldSet = new FieldSet(new String[] { "1", "2", "3" }, new String[] { "NestedC[0].Value",
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "1", "2", "3" }, new String[] { "NestedC[0].Value",
|
||||
"NestedC[1].Value", "NestedC[2].Value" });
|
||||
|
||||
mapper.mapLine(fieldSet);
|
||||
@@ -296,7 +296,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
|
||||
mapper.setTargetType(TestObject.class);
|
||||
|
||||
FieldSet fieldSet = new FieldSet(new String[] { "00009" }, new String[] { "varLong" });
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "00009" }, new String[] { "varLong" });
|
||||
|
||||
try {
|
||||
mapper.mapLine(fieldSet);
|
||||
@@ -343,7 +343,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
|
||||
mapper.setTargetType(TestObject.class);
|
||||
|
||||
FieldSet fieldSet = new FieldSet(new String[] { "00009" }, new String[] { "varLong" });
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "00009" }, new String[] { "varLong" });
|
||||
|
||||
mapper.setCustomEditors(Collections.singletonMap(Long.TYPE, new CustomNumberEditor(Long.class, NumberFormat
|
||||
.getNumberInstance(), true)));
|
||||
@@ -357,7 +357,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
|
||||
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
|
||||
mapper.setTargetType(TestObject.class);
|
||||
|
||||
FieldSet fieldSet = new FieldSet(new String[] { "00009", "78" }, new String[] { "varLong", "varInt" });
|
||||
FieldSet fieldSet = new DefaultFieldSet(new String[] { "00009", "78" }, new String[] { "varLong", "varInt" });
|
||||
|
||||
mapper.setCustomEditors(Collections.singletonMap(Long.TYPE, new CustomNumberEditor(Long.class, NumberFormat
|
||||
.getNumberInstance(), true)));
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.DefaultFieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.transform.DelimitedLineTokenizer;
|
||||
import org.springframework.batch.io.file.transform.PrefixMatchingCompositeLineTokenizer;
|
||||
@@ -86,7 +87,7 @@ public class PrefixMatchingCompositeLineTokenizerTests extends TestCase {
|
||||
public void testMatchWithPrefix() throws Exception {
|
||||
tokenizer.setTokenizers(Collections.singletonMap("foo", new LineTokenizer() {
|
||||
public FieldSet tokenize(String line) {
|
||||
return new FieldSet(new String[] {line});
|
||||
return new DefaultFieldSet(new String[] {line});
|
||||
}
|
||||
}));
|
||||
FieldSet fields = tokenizer.tokenize("foo bar");
|
||||
|
||||
@@ -19,8 +19,8 @@ package org.springframework.batch.repeat.support;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.SimpleFlatFileItemReader;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.reader.DelegatingItemReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
Reference in New Issue
Block a user