RESOLVED - BATCH-29: All domain entities and scoping abstractions (RepeatContext in particular) need to be Serializable

This commit is contained in:
robokaso
2008-04-28 14:15:19 +00:00
parent 58375f3198
commit 203f4a0e4d
7 changed files with 97 additions and 8 deletions

View File

@@ -15,8 +15,14 @@
*/
package org.springframework.batch.item;
import java.io.Serializable;
import junit.framework.TestCase;
import org.apache.commons.lang.SerializationUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
/**
* @author Lucas Ward
*
@@ -103,4 +109,42 @@ public class ExecutionContextTests extends TestCase{
context.put("1", null);
}
public void testSerialization() {
TestSerializable s = new TestSerializable();
s.value = 7;
context.putString("1", "testString1");
context.putString("2", "testString2");
context.putLong("3", 3);
context.putDouble("4", 4.4);
context.put("5", s);
byte[] serialized = SerializationUtils.serialize(context);
ExecutionContext deserialized = (ExecutionContext) SerializationUtils.deserialize(serialized);
assertEquals(context, deserialized);
assertEquals(7, ((TestSerializable)deserialized.get("5")).value);
}
/**
* Value object for testing serialization
*/
private static class TestSerializable implements Serializable {
int value;
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
}
}