RESOLVED - BATCH-29: All domain entities and scoping abstractions (RepeatContext in particular) need to be Serializable
This commit is contained in:
@@ -19,6 +19,7 @@ import java.util.Date;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
import org.springframework.batch.core.step.StepSupport;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
|
||||
@@ -153,4 +154,10 @@ public class JobExecutionTests extends TestCase {
|
||||
assertTrue("JobExecution string does not contain id", execution.toString().indexOf("id=") >= 0);
|
||||
assertTrue("JobExecution string does not contain job: " + execution, execution.toString().indexOf("job=") >= 0);
|
||||
}
|
||||
|
||||
public void testSerialization() {
|
||||
byte[] serialized = SerializationUtils.serialize(execution);
|
||||
|
||||
assertEquals(execution, SerializationUtils.deserialize(serialized));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,38 +15,51 @@
|
||||
*/
|
||||
package org.springframework.batch.core;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author dsyer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class JobInstanceTests extends TestCase {
|
||||
|
||||
private JobInstance instance = new JobInstance(new Long(11), new JobParameters(), "job");
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.core.JobInstance#getJobName()}.
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.JobInstance#getJobName()}.
|
||||
*/
|
||||
public void testGetName() {
|
||||
instance = new JobInstance(new Long(1), new JobParameters(), "foo");
|
||||
assertEquals("foo", instance.getJobName());
|
||||
}
|
||||
|
||||
public void testGetJob(){
|
||||
|
||||
public void testGetJob() {
|
||||
assertEquals("job", instance.getJobName());
|
||||
}
|
||||
|
||||
public void testCreateWithNulls(){
|
||||
public void testCreateWithNulls() {
|
||||
try {
|
||||
new JobInstance(null, null, null);
|
||||
fail("job instance can't exist without job specified");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
// expected
|
||||
}
|
||||
instance = new JobInstance(null, null, "testJob");
|
||||
assertEquals("testJob", instance.getJobName());
|
||||
assertEquals(0, instance.getJobParameters().getParameters().size());
|
||||
}
|
||||
|
||||
public void testSerialization() {
|
||||
instance = new JobInstance(new Long(1), new JobParametersBuilder().addDouble("doubleKey", Double.valueOf(5.1))
|
||||
.toJobParameters(), "jobName");
|
||||
|
||||
byte[] serialized = SerializationUtils.serialize(instance);
|
||||
|
||||
assertEquals(instance, SerializationUtils.deserialize(serialized));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
@@ -245,4 +247,12 @@ public class JobParametersTests extends TestCase {
|
||||
int code = getNewParameters().hashCode();
|
||||
assertEquals(code, parameters.hashCode());
|
||||
}
|
||||
|
||||
public void testSerialization() {
|
||||
JobParameters params = getNewParameters();
|
||||
|
||||
byte[] serialized = SerializationUtils.serialize(params);
|
||||
|
||||
assertEquals(params, SerializationUtils.deserialize(serialized));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
import org.springframework.batch.core.step.StepSupport;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
@@ -221,6 +222,19 @@ public class StepExecutionTests extends TestCase {
|
||||
execution.setExecutionContext(new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar")));
|
||||
assertTrue(set.contains(execution));
|
||||
}
|
||||
|
||||
public void testSerialization() throws Exception {
|
||||
|
||||
ExitStatus status = ExitStatus.NOOP;
|
||||
execution.setExitStatus(status);
|
||||
execution.setExecutionContext(new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar")));
|
||||
|
||||
byte[] serialized = SerializationUtils.serialize(execution);
|
||||
StepExecution deserialized = (StepExecution) SerializationUtils.deserialize(serialized);
|
||||
|
||||
assertEquals(execution, deserialized);
|
||||
assertEquals(status, deserialized.getExitStatus());
|
||||
}
|
||||
|
||||
private StepExecution newStepExecution(Step step, Long long2) {
|
||||
JobInstance job = new JobInstance(new Long(3), new JobParameters(), "testJob");
|
||||
|
||||
Reference in New Issue
Block a user