OPEN - issue BATCH-304: BatchCommandLineLauncher simplified and rename

http://jira.springframework.org/browse/BATCH-304

Allow BatchStatus to be null in Dao (why not?)
This commit is contained in:
dsyer
2008-01-24 08:11:23 +00:00
parent 5a8635a32e
commit 13bce7b1e1
2 changed files with 27 additions and 29 deletions

View File

@@ -18,8 +18,6 @@ package org.springframework.batch.core.domain;
import java.io.Serializable;
import org.springframework.util.Assert;
/**
* Typesafe enumeration representing the status of an artifact within the
* batch environment. See Effective Java Programming by Joshua Bloch for more
@@ -67,11 +65,13 @@ public class BatchStatus implements Serializable{
* Given a string representation of a status, return the appropriate BatchStatus.
*
* @param statusAsString: string representation of a status
* @return Valid BatchStatus
* @return a valid BatchStatus or null if the input is null
* @throws IllegalArgumentException if no status matches provided string.
*/
public static BatchStatus getStatus(String statusAsString) {
Assert.notNull(statusAsString, "Cannot match null to valid status.");
if (statusAsString==null) {
return null;
}
final String upperCaseStatusAsString = statusAsString.toUpperCase();
for (int i = 0; i < VALUES.length; i++) {
if (VALUES[i].toString().equals(upperCaseStatusAsString)) {

View File

@@ -24,62 +24,60 @@ import junit.framework.TestCase;
/**
* @author Dave Syer
*
*
*/
public class BatchStatusTests extends TestCase {
/**
* Test method for {@link org.springframework.batch.core.domain.BatchStatus#toString()}.
* Test method for
* {@link org.springframework.batch.core.domain.BatchStatus#toString()}.
*/
public void testToString() {
assertEquals("FAILED", BatchStatus.FAILED.toString());
}
/**
* Test method for {@link org.springframework.batch.core.domain.BatchStatus#getStatus(java.lang.String)}.
* Test method for
* {@link org.springframework.batch.core.domain.BatchStatus#getStatus(java.lang.String)}.
*/
public void testGetStatus() {
assertEquals(BatchStatus.FAILED, BatchStatus.getStatus(BatchStatus.FAILED.toString()));
}
/**
* Test method for {@link org.springframework.batch.core.domain.BatchStatus#getStatus(java.lang.String)}.
* Test method for
* {@link org.springframework.batch.core.domain.BatchStatus#getStatus(java.lang.String)}.
*/
public void testGetStatusWrongCode() {
try{
try {
BatchStatus.getStatus("foo");
fail();
}
catch(IllegalArgumentException ex){
//expected
catch (IllegalArgumentException ex) {
// expected
}
}
/**
* Test method for {@link org.springframework.batch.core.domain.BatchStatus#getStatus(java.lang.String)}.
* Test method for
* {@link org.springframework.batch.core.domain.BatchStatus#getStatus(java.lang.String)}.
*/
public void testGetStatusNullCode() {
try{
BatchStatus.getStatus(null);
fail();
}
catch(IllegalArgumentException ex){
//expected
}
assertNull(BatchStatus.getStatus(null));
}
public void testSerialization() throws Exception{
public void testSerialization() throws Exception {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream (bout);
ObjectOutputStream out = new ObjectOutputStream(bout);
out.writeObject (BatchStatus.COMPLETED);
out.flush ();
out.writeObject(BatchStatus.COMPLETED);
out.flush();
ByteArrayInputStream bin = new ByteArrayInputStream (bout.toByteArray());
ObjectInputStream in = new ObjectInputStream(bin);
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
ObjectInputStream in = new ObjectInputStream(bin);
BatchStatus status = (BatchStatus) in.readObject ();
assertEquals(BatchStatus.COMPLETED, status);
BatchStatus status = (BatchStatus) in.readObject();
assertEquals(BatchStatus.COMPLETED, status);
}
}