RESOLVED - issue BATCH-362: Rename ExecutionAttributes to ExecutionContext

http://jira.springframework.org/browse/BATCH-362
This commit is contained in:
robokaso
2008-02-15 12:12:16 +00:00
parent 0d699b80d5
commit 4a40b17002
69 changed files with 523 additions and 545 deletions

View File

@@ -9,7 +9,7 @@ import junit.framework.TestCase;
import org.springframework.batch.io.sample.domain.Foo;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.Assert;
@@ -73,7 +73,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
Foo foo2 = (Foo) source.read();
assertEquals(2, foo2.getValue());
ExecutionAttributes streamContext = getAsRestartable(source).getExecutionAttributes();
ExecutionContext streamContext = getAsRestartable(source).getExecutionContext();
// create new input source
source = createItemReader();
@@ -95,7 +95,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
Foo foo2 = (Foo) source.read();
assertEquals(2, foo2.getValue());
ExecutionAttributes streamContext = getAsRestartable(source).getExecutionAttributes();
ExecutionContext streamContext = getAsRestartable(source).getExecutionContext();
// create new input source
source = createItemReader();
@@ -117,7 +117,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
* @throws Exception
*/
public void testRestoreFromEmptyData() throws Exception {
ExecutionAttributes streamContext = new ExecutionAttributes(new Properties());
ExecutionContext streamContext = new ExecutionContext(new Properties());
getAsRestartable(source).restoreFrom(streamContext);
@@ -164,7 +164,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
private static class MockKeyGenerator implements KeyGenerator{
static ExecutionAttributes streamContext;
static ExecutionContext streamContext;
List keys;
List restartKeys;
@@ -173,7 +173,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
//restart data properties cannot be empty.
props.setProperty("", "");
streamContext = new ExecutionAttributes(props);
streamContext = new ExecutionContext(props);
}
public MockKeyGenerator() {
@@ -191,11 +191,11 @@ public class DrivingQueryItemReaderTests extends TestCase {
restartKeys.add(new Foo(5, "5", 5));
}
public ExecutionAttributes getKeyAsExecutionAttributes(Object key) {
public ExecutionContext getKeyAsExecutionContext(Object key) {
return streamContext;
}
public List restoreKeys(ExecutionAttributes streamContext) {
public List restoreKeys(ExecutionContext streamContext) {
assertEquals(MockKeyGenerator.streamContext, streamContext);
return restartKeys;

View File

@@ -2,7 +2,7 @@ package org.springframework.batch.io.driving;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.reader.AbstractItemReader;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
@@ -29,11 +29,11 @@ class FooItemReader extends AbstractItemReader implements ItemStream, ItemReader
}
}
public ExecutionAttributes getExecutionAttributes() {
return inputSource.getExecutionAttributes();
public ExecutionContext getExecutionContext() {
return inputSource.getExecutionContext();
}
public void restoreFrom(ExecutionAttributes data) {
public void restoreFrom(ExecutionContext data) {
inputSource.restoreFrom(data);
}

View File

@@ -11,18 +11,18 @@ import java.util.Properties;
import junit.framework.TestCase;
import org.easymock.MockControl;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.core.CollectionFactory;
import org.springframework.jdbc.core.PreparedStatementSetter;
/**
* @author Lucas Ward
*/
public class ColumnMapExecutionAttributesRowMapperTests extends TestCase {
public class ColumnMapExecutionContextRowMapperTests extends TestCase {
private static final String KEY = ColumnMapExecutionAttributesRowMapper.KEY_PREFIX;
private static final String KEY = ColumnMapExecutionContextRowMapper.KEY_PREFIX;
private ColumnMapExecutionAttributesRowMapper mapper;
private ColumnMapExecutionContextRowMapper mapper;
private Map key;
@@ -32,43 +32,43 @@ public class ColumnMapExecutionAttributesRowMapperTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
mapper = new ColumnMapExecutionAttributesRowMapper();
mapper = new ColumnMapExecutionContextRowMapper();
key = CollectionFactory.createLinkedCaseInsensitiveMapIfPossible(2);
key.put("1", new Integer(1));
key.put("2", new Integer(2));
}
public void testCreateExecutionAttributesWithInvalidType() throws Exception {
public void testCreateExecutionContextWithInvalidType() throws Exception {
try{
mapper.createExecutionAttributes(new Object());
mapper.createExecutionContext(new Object());
fail();
}catch(IllegalArgumentException ex){
//expected
}
}
public void testCreateExecutionAttributesWithNull(){
public void testCreateExecutionContextWithNull(){
try{
mapper.createExecutionAttributes(null);
mapper.createExecutionContext(null);
fail();
}catch(IllegalArgumentException ex){
//expected
}
}
public void testCreateExecutionAttributes() throws Exception {
ExecutionAttributes streamContext = mapper.createExecutionAttributes(key);
public void testCreateExecutionContext() throws Exception {
ExecutionContext streamContext = mapper.createExecutionContext(key);
Properties props = streamContext.getProperties();
assertEquals("1", props.getProperty(KEY + "0"));
assertEquals("2", props.getProperty(KEY + "1"));
}
public void testCreateExecutionAttributesFromEmptyKeys() throws Exception {
public void testCreateExecutionContextFromEmptyKeys() throws Exception {
ExecutionAttributes streamContext = mapper.createExecutionAttributes(new HashMap());
ExecutionContext streamContext = mapper.createExecutionContext(new HashMap());
assertEquals(0, streamContext.getProperties().size());
}
@@ -77,7 +77,7 @@ public class ColumnMapExecutionAttributesRowMapperTests extends TestCase {
Properties props = new Properties();
props.setProperty(KEY + "0", "1");
props.setProperty(KEY + "1", "2");
ExecutionAttributes streamContext = new ExecutionAttributes();
ExecutionContext streamContext = new ExecutionContext();
streamContext.putString(KEY + "0", "1");
streamContext.putString(KEY + "1", "2");
PreparedStatementSetter setter = mapper.createSetter(streamContext);

View File

@@ -7,7 +7,7 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.core.CollectionFactory;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
@@ -45,9 +45,9 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran
public void testRestoreKeys(){
ExecutionAttributes streamContext = new ExecutionAttributes();
streamContext.putString(ColumnMapExecutionAttributesRowMapper.KEY_PREFIX + "0", "3");
streamContext.putString(ColumnMapExecutionAttributesRowMapper.KEY_PREFIX + "1", "3");
ExecutionContext streamContext = new ExecutionContext();
streamContext.putString(ColumnMapExecutionContextRowMapper.KEY_PREFIX + "0", "3");
streamContext.putString(ColumnMapExecutionContextRowMapper.KEY_PREFIX + "1", "3");
List keys = keyStrategy.restoreKeys(streamContext);
@@ -60,24 +60,24 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran
assertEquals(new Integer(5), key.get("VALUE"));
}
public void testGetKeyAsExecutionAttributes(){
public void testGetKeyAsExecutionContext(){
Map key = CollectionFactory.createLinkedCaseInsensitiveMapIfPossible(1);
key.put("ID", new Long(3));
key.put("VALUE", new Integer(3));
ExecutionAttributes streamContext = keyStrategy.getKeyAsExecutionAttributes(key);
ExecutionContext streamContext = keyStrategy.getKeyAsExecutionContext(key);
Properties props = streamContext.getProperties();
assertEquals(2, props.size());
assertEquals("3", props.get(ColumnMapExecutionAttributesRowMapper.KEY_PREFIX + "0"));
assertEquals("3", props.get(ColumnMapExecutionAttributesRowMapper.KEY_PREFIX + "1"));
assertEquals("3", props.get(ColumnMapExecutionContextRowMapper.KEY_PREFIX + "0"));
assertEquals("3", props.get(ColumnMapExecutionContextRowMapper.KEY_PREFIX + "1"));
}
public void testGetNullKeyAsStreamContext(){
try{
keyStrategy.getKeyAsExecutionAttributes(null);
keyStrategy.getKeyAsExecutionContext(null);
fail();
}catch(IllegalArgumentException ex){
//expected
@@ -87,7 +87,7 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran
public void testRestoreKeysFromNull(){
try{
keyStrategy.getKeyAsExecutionAttributes(null);
keyStrategy.getKeyAsExecutionContext(null);
}catch(IllegalArgumentException ex){
//expected
}

View File

@@ -3,7 +3,7 @@ package org.springframework.batch.io.driving.support;
import java.util.List;
import java.util.Properties;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
/**
@@ -43,7 +43,7 @@ public class SingleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTransa
Properties props = new Properties();
props.setProperty(SingleColumnJdbcKeyGenerator.RESTART_KEY, "3");
ExecutionAttributes streamContext = new ExecutionAttributes(props);
ExecutionContext streamContext = new ExecutionContext(props);
List keys = keyStrategy.restoreKeys(streamContext);
@@ -54,7 +54,7 @@ public class SingleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTransa
public void testGetKeyAsStreamContext(){
ExecutionAttributes streamContext = keyStrategy.getKeyAsExecutionAttributes(new Long(3));
ExecutionContext streamContext = keyStrategy.getKeyAsExecutionContext(new Long(3));
Properties props = streamContext.getProperties();
assertEquals(1, props.size());
@@ -64,7 +64,7 @@ public class SingleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTransa
public void testGetNullKeyAsStreamContext(){
try{
keyStrategy.getKeyAsExecutionAttributes(null);
keyStrategy.getKeyAsExecutionContext(null);
fail();
}catch(IllegalArgumentException ex){
//expected
@@ -74,7 +74,7 @@ public class SingleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTransa
public void testRestoreKeysFromNull(){
try{
keyStrategy.getKeyAsExecutionAttributes(null);
keyStrategy.getKeyAsExecutionContext(null);
}catch(IllegalArgumentException ex){
//expected
}

View File

@@ -24,7 +24,7 @@ import org.springframework.batch.io.file.mapping.DefaultFieldSet;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.io.file.transform.LineTokenizer;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
@@ -153,7 +153,7 @@ public class FlatFileItemReaderAdvancedTests extends TestCase {
reader.setFieldSetMapper(fieldSetMapper);
// do not open the template...
try {
reader.restoreFrom(reader.getExecutionAttributes());
reader.restoreFrom(reader.getExecutionContext());
} catch (StreamException e) {
assertTrue("Message does not contain open: "+e.getMessage(), e.getMessage().contains("open"));
}
@@ -177,7 +177,7 @@ public class FlatFileItemReaderAdvancedTests extends TestCase {
reader.read();
// get restart data
ExecutionAttributes streamContext = reader.getExecutionAttributes();
ExecutionContext streamContext = reader.getExecutionContext();
assertEquals("4", (String) streamContext.getProperties().getProperty(
FlatFileItemReader.READ_STATISTICS_NAME));
// close input
@@ -193,7 +193,7 @@ public class FlatFileItemReaderAdvancedTests extends TestCase {
assertEquals("[testLine5]", reader.read().toString());
assertEquals("[testLine6]", reader.read().toString());
ExecutionAttributes statistics = reader.getExecutionAttributes();
ExecutionContext statistics = reader.getExecutionContext();
assertEquals(6, statistics.getLong(FlatFileItemReader.READ_STATISTICS_NAME));
}

View File

@@ -25,7 +25,7 @@ import java.util.Collections;
import junit.framework.TestCase;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.writer.ItemTransformer;
import org.springframework.core.io.FileSystemResource;
import org.springframework.transaction.support.TransactionSynchronizationManager;
@@ -309,7 +309,7 @@ public class FlatFileItemWriterTests extends TestCase {
commit();
// get restart data
ExecutionAttributes streamContext = inputSource.getExecutionAttributes();
ExecutionContext streamContext = inputSource.getExecutionContext();
// close template
inputSource.close();
@@ -335,7 +335,7 @@ public class FlatFileItemWriterTests extends TestCase {
inputSource.write("testLine8");
// get statistics
ExecutionAttributes statistics = inputSource.getExecutionAttributes();
ExecutionContext statistics = inputSource.getExecutionContext();
// close template
inputSource.close();
@@ -363,7 +363,7 @@ public class FlatFileItemWriterTests extends TestCase {
public void testDefaultStreamContext() throws Exception {
inputSource = new FlatFileItemWriter();
inputSource.open();
ExecutionAttributes streamContext = inputSource.getExecutionAttributes();
ExecutionContext streamContext = inputSource.getExecutionContext();
assertNotNull(streamContext);
assertEquals(3, streamContext.getProperties().size());
assertEquals(0, streamContext.getLong(FlatFileItemWriter.RESTART_DATA_NAME));

View File

@@ -3,7 +3,7 @@ package org.springframework.batch.io.sql;
import org.springframework.batch.io.sample.domain.Foo;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
@@ -76,7 +76,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
Foo foo2 = (Foo) source.read();
assertEquals(2, foo2.getValue());
ExecutionAttributes streamContext = getAsRestartable(source).getExecutionAttributes();
ExecutionContext streamContext = getAsRestartable(source).getExecutionContext();
// create new input source
source = createItemReader();
@@ -98,7 +98,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
Foo foo2 = (Foo) source.read();
assertEquals(2, foo2.getValue());
ExecutionAttributes streamContext = getAsRestartable(source).getExecutionAttributes();
ExecutionContext streamContext = getAsRestartable(source).getExecutionContext();
// create new input source
source = createItemReader();
@@ -120,7 +120,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
* @throws Exception
*/
public void testRestoreFromEmptyData() throws Exception {
ExecutionAttributes streamContext = new ExecutionAttributes();
ExecutionContext streamContext = new ExecutionContext();
getAsRestartable(source).restoreFrom(streamContext);

View File

@@ -2,7 +2,7 @@ package org.springframework.batch.io.support;
import org.springframework.batch.io.Skippable;
import org.springframework.batch.io.sample.domain.Foo;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.beans.factory.InitializingBean;
@@ -85,7 +85,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends
Foo foo2 = (Foo) reader.read();
assertEquals(2, foo2.getValue());
ExecutionAttributes streamContext = getAsItemStream(reader).getExecutionAttributes();
ExecutionContext streamContext = getAsItemStream(reader).getExecutionContext();
// create new input source
reader = createItemReader();
@@ -107,7 +107,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends
Foo foo2 = (Foo) reader.read();
assertEquals(2, foo2.getValue());
ExecutionAttributes streamContext = getAsItemStream(reader).getExecutionAttributes();
ExecutionContext streamContext = getAsItemStream(reader).getExecutionContext();
// create new input source
reader = createItemReader();
@@ -129,7 +129,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends
* @throws Exception
*/
public void testRestoreFromEmptyData() throws Exception {
ExecutionAttributes streamContext = new ExecutionAttributes();
ExecutionContext streamContext = new ExecutionContext();
getAsItemStream(reader).restoreFrom(streamContext);
@@ -212,7 +212,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends
rollback();
ExecutionAttributes streamContext = getAsItemStream(reader).getExecutionAttributes();
ExecutionContext streamContext = getAsItemStream(reader).getExecutionContext();
// create new input source
reader = createItemReader();

View File

@@ -14,7 +14,7 @@ import javax.xml.stream.events.XMLEvent;
import junit.framework.TestCase;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.core.io.AbstractResource;
import org.springframework.core.io.ByteArrayResource;
@@ -113,7 +113,7 @@ public class StaxEventItemReaderTests extends TestCase {
*/
public void testRestart() {
source.read();
ExecutionAttributes streamContext = source.getExecutionAttributes();
ExecutionContext streamContext = source.getExecutionContext();
assertEquals(1, streamContext.getLong(StaxEventItemReader.READ_COUNT_STATISTICS_NAME));
List expectedAfterRestart = (List) source.read();
@@ -128,7 +128,7 @@ public class StaxEventItemReaderTests extends TestCase {
* already initialised when restoring.
*/
public void testInvalidRestore() {
ExecutionAttributes context = new ExecutionAttributes();
ExecutionContext context = new ExecutionContext();
context.putLong(StaxEventItemReader.READ_COUNT_STATISTICS_NAME, 100000);
try {
source.restoreFrom(context);
@@ -143,7 +143,7 @@ public class StaxEventItemReaderTests extends TestCase {
public void testRestoreWorksFromClosedStream() throws Exception {
source.close();
source.restoreFrom(new ExecutionAttributes());
source.restoreFrom(new ExecutionContext());
}
/**
* Skipping marked records after rollback.
@@ -205,7 +205,7 @@ public class StaxEventItemReaderTests extends TestCase {
}
private long extractRecordCount() {
return source.getExecutionAttributes().getLong(StaxEventItemReader.READ_COUNT_STATISTICS_NAME);
return source.getExecutionContext().getLong(StaxEventItemReader.READ_COUNT_STATISTICS_NAME);
}
public void testCloseWithoutOpen() throws Exception {

View File

@@ -12,7 +12,7 @@ import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
import org.springframework.batch.io.xml.oxm.MarshallingEventWriterSerializer;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.oxm.Marshaller;
@@ -88,7 +88,7 @@ public class StaxEventWriterItemWriterTests extends TestCase {
// write record
writer.write(record);
// writer.mark();
ExecutionAttributes streamContext = writer.getExecutionAttributes();
ExecutionContext streamContext = writer.getExecutionContext();
writer.close();
// create new writer from saved restart data and continue writing
@@ -117,7 +117,7 @@ public class StaxEventWriterItemWriterTests extends TestCase {
final int NUMBER_OF_RECORDS = 10;
for (int i = 1; i <= NUMBER_OF_RECORDS; i++) {
writer.write(record);
long writeStatistics = writer.getExecutionAttributes().getLong(StaxEventItemWriter.WRITE_STATISTICS_NAME);
long writeStatistics = writer.getExecutionContext().getLong(StaxEventItemWriter.WRITE_STATISTICS_NAME);
assertEquals(i, writeStatistics);
}

View File

@@ -21,14 +21,14 @@ import junit.framework.TestCase;
* @author Lucas Ward
*
*/
public class ExecutionAttributesTests extends TestCase{
public class ExecutionContextTests extends TestCase{
ExecutionAttributes context;
ExecutionContext context;
protected void setUp() throws Exception {
super.setUp();
context = new ExecutionAttributes();
context = new ExecutionContext();
}
public void testNormalUsage(){
@@ -78,7 +78,7 @@ public class ExecutionAttributesTests extends TestCase{
public void testEquals(){
context.putString("1", "testString");
ExecutionAttributes tempContext = new ExecutionAttributes();
ExecutionContext tempContext = new ExecutionContext();
assertFalse(tempContext.equals(context));
tempContext.putString("1", "testString");
assertTrue(tempContext.equals(context));

View File

@@ -23,7 +23,7 @@ import junit.framework.TestCase;
import org.springframework.batch.io.Skippable;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.support.PropertiesConverter;
/**
@@ -73,7 +73,7 @@ public class DelegatingItemReaderTests extends TestCase {
* Gets restart data from the input template
*/
public void testGetStreamContext() {
Properties props = itemProvider.getExecutionAttributes().getProperties();
Properties props = itemProvider.getExecutionContext().getProperties();
assertEquals("foo", props.getProperty("value"));
}
@@ -82,7 +82,7 @@ public class DelegatingItemReaderTests extends TestCase {
* @throws Exception
*/
public void testRestoreFrom() throws Exception {
itemProvider.restoreFrom(new ExecutionAttributes(PropertiesConverter.stringToProperties("value=bar")));
itemProvider.restoreFrom(new ExecutionContext(PropertiesConverter.stringToProperties("value=bar")));
assertEquals("bar", itemProvider.read());
}
@@ -99,11 +99,11 @@ public class DelegatingItemReaderTests extends TestCase {
return PropertiesConverter.stringToProperties("a=b");
}
public ExecutionAttributes getExecutionAttributes() {
return new ExecutionAttributes(PropertiesConverter.stringToProperties("value=foo"));
public ExecutionContext getExecutionContext() {
return new ExecutionContext(PropertiesConverter.stringToProperties("value=foo"));
}
public void restoreFrom(ExecutionAttributes data) {
public void restoreFrom(ExecutionContext data) {
value = data.getProperties().getProperty("value");
}

View File

@@ -20,7 +20,7 @@ import java.util.List;
import junit.framework.TestCase;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.exception.StreamException;
import org.springframework.batch.support.PropertiesConverter;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
@@ -72,31 +72,31 @@ public class SimpleStreamManagerTests extends TestCase {
/**
* Test method for
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionAttributes(java.lang.Object)}.
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionContext(java.lang.Object)}.
*/
public void testGetStreamContextEmpty() {
ExecutionAttributes streamContext = manager.getExecutionAttributes("foo");
ExecutionContext streamContext = manager.getExecutionContext("foo");
assertEquals(0, streamContext.entrySet().size());
}
/**
* Test method for
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionAttributes(java.lang.Object)}.
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionContext(java.lang.Object)}.
*/
public void testGetStreamContextNotEmpty() {
manager.register("foo", stream, null);
ExecutionAttributes streamContext = manager.getExecutionAttributes("foo");
ExecutionContext streamContext = manager.getExecutionContext("foo");
assertEquals(1, streamContext.entrySet().size());
assertEquals("bar", streamContext.getString(ClassUtils.getQualifiedName(stream.getClass()) + ".foo"));
}
/**
* Test method for
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionAttributes(java.lang.Object)}.
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionContext(java.lang.Object)}.
*/
public void testGetStreamContextNotEmptyAndRestore() {
testGetStreamContextNotEmpty();
ExecutionAttributes context = manager.getExecutionAttributes("foo");
ExecutionContext context = manager.getExecutionContext("foo");
// Register again, now with the context that was created from the same
// stream...
manager.register("foo", stream, context);
@@ -107,10 +107,10 @@ public class SimpleStreamManagerTests extends TestCase {
/**
* Test method for
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionAttributes(java.lang.Object)}.
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionContext(java.lang.Object)}.
*/
public void testGetStreamContextNotEmptyAndRestoreWithNoPrefix() {
ExecutionAttributes context = new ExecutionAttributes(PropertiesConverter.stringToProperties("foo=bar"));
ExecutionContext context = new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar"));
manager.setUseClassNameAsPrefix(false);
manager.register("foo", stream, context);
assertEquals(1, list.size());
@@ -120,12 +120,12 @@ public class SimpleStreamManagerTests extends TestCase {
/**
* Test method for
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionAttributes(java.lang.Object)}.
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionContext(java.lang.Object)}.
*/
public void testGetStreamContextWithNoPrefix() {
manager.setUseClassNameAsPrefix(false);
manager.register("foo", stream, null);
ExecutionAttributes context = manager.getExecutionAttributes("foo");
ExecutionContext context = manager.getExecutionContext("foo");
assertEquals(1, context.entrySet().size());
// The list should have the foo= map value from the sub-context
assertEquals("bar", context.getString("foo"));
@@ -133,20 +133,20 @@ public class SimpleStreamManagerTests extends TestCase {
/**
* Test method for
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionAttributes(java.lang.Object)}.
* {@link org.springframework.batch.item.stream.SimpleStreamManager#getExecutionContext(java.lang.Object)}.
*/
public void testGetStreamContextTwoRegistrations() {
manager.register("foo", new ItemStreamAdapter() {
public ExecutionAttributes getExecutionAttributes() {
return new ExecutionAttributes(PropertiesConverter.stringToProperties("foo=bar"));
public ExecutionContext getExecutionContext() {
return new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar"));
}
}, null);
manager.register("foo", new ItemStreamAdapter() {
public ExecutionAttributes getExecutionAttributes() {
return new ExecutionAttributes(PropertiesConverter.stringToProperties("foo=spam"));
public ExecutionContext getExecutionContext() {
return new ExecutionContext(PropertiesConverter.stringToProperties("foo=spam"));
}
}, null);
ExecutionAttributes streamContext = manager.getExecutionAttributes("foo");
ExecutionContext streamContext = manager.getExecutionContext("foo");
assertEquals(2, streamContext.entrySet().size());
}
@@ -234,11 +234,11 @@ public class SimpleStreamManagerTests extends TestCase {
}
private final class ItemStreamAdapterExtension extends ItemStreamAdapter {
public ExecutionAttributes getExecutionAttributes() {
return new ExecutionAttributes(PropertiesConverter.stringToProperties("foo=bar"));
public ExecutionContext getExecutionContext() {
return new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar"));
}
public void restoreFrom(ExecutionAttributes context) {
public void restoreFrom(ExecutionContext context) {
list.add(context.getString("foo"));
}
}

View File

@@ -21,7 +21,7 @@ import java.util.List;
import junit.framework.TestCase;
import org.springframework.batch.io.Skippable;
import org.springframework.batch.item.ExecutionAttributes;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.support.PropertiesConverter;
@@ -95,11 +95,11 @@ public class ItemWriterItemProcessorTests extends TestCase {
public void open() {
}
public ExecutionAttributes getExecutionAttributes() {
return new ExecutionAttributes(PropertiesConverter.stringToProperties("value=foo"));
public ExecutionContext getExecutionContext() {
return new ExecutionContext(PropertiesConverter.stringToProperties("value=foo"));
}
public void restoreFrom(ExecutionAttributes data) {
public void restoreFrom(ExecutionContext data) {
value = data.getProperties().getProperty("value");
}