Send test coverage in core up to the high 90s.
This commit is contained in:
@@ -57,6 +57,15 @@ public class EntityTests extends TestCase {
|
||||
assertEquals(new Integer(0), entity.getVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.core.domain.Entity#getVersion()}.
|
||||
*/
|
||||
public void testIncrementVersionTwice() {
|
||||
entity.incrementVersion();
|
||||
entity.incrementVersion();
|
||||
assertEquals(new Integer(1), entity.getVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
@@ -27,9 +27,7 @@ import org.springframework.batch.repeat.ExitStatus;
|
||||
*/
|
||||
public class JobExecutionTests extends TestCase {
|
||||
|
||||
private JobExecution execution = new JobExecution(new JobInstance(new Long(11), new JobParameters()), new Long(12));
|
||||
|
||||
private JobExecution context = new JobExecution(new JobInstance(new Long(11), new JobParameters(), new JobSupport("foo")), new Long(12));
|
||||
private JobExecution execution = new JobExecution(new JobInstance(new Long(11), new JobParameters(), new JobSupport("foo")), new Long(12));
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
@@ -117,23 +115,30 @@ public class JobExecutionTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testContextContainsInfo() throws Exception {
|
||||
assertEquals("foo", context.getJobInstance().getJobName());
|
||||
assertEquals("foo", execution.getJobInstance().getJobName());
|
||||
}
|
||||
|
||||
public void testAddAndRemoveStepExecution() throws Exception {
|
||||
assertEquals(0, context.getStepExecutions().size());
|
||||
context.createStepExecution(new StepInstance(null, null));
|
||||
assertEquals(1, context.getStepExecutions().size());
|
||||
assertEquals(0, execution.getStepExecutions().size());
|
||||
execution.createStepExecution(new StepInstance(null, null));
|
||||
assertEquals(1, execution.getStepExecutions().size());
|
||||
}
|
||||
|
||||
public void testStop() throws Exception {
|
||||
StepExecution stepExecution = execution.createStepExecution(null);
|
||||
assertFalse(stepExecution.isTerminateOnly());
|
||||
execution.stop();
|
||||
assertTrue(stepExecution.isTerminateOnly());
|
||||
}
|
||||
|
||||
public void testToString() throws Exception {
|
||||
assertTrue("JobExecution string does not contain id", context.toString().indexOf("id=") >= 0);
|
||||
assertTrue("JobExecution string does not contain name: " + context, context.toString().indexOf("foo") >= 0);
|
||||
assertTrue("JobExecution string does not contain id", execution.toString().indexOf("id=") >= 0);
|
||||
assertTrue("JobExecution string does not contain name: " + execution, execution.toString().indexOf("foo") >= 0);
|
||||
}
|
||||
|
||||
public void testToStringWithNullJob() throws Exception {
|
||||
context = new JobExecution();
|
||||
assertTrue("JobExecution string does not contain id", context.toString().indexOf("id=") >= 0);
|
||||
assertTrue("JobExecution string does not contain job: " + context, context.toString().indexOf("job=") >= 0);
|
||||
execution = new JobExecution();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,12 @@ public class JobInstanceTests extends TestCase {
|
||||
|
||||
public void testGetJob(){
|
||||
assertEquals("job", instance.getJob().getName());
|
||||
instance.setJob(null);
|
||||
assertEquals(null, instance.getJob());
|
||||
}
|
||||
|
||||
public void testCreateJobExecution(){
|
||||
assertNotNull(instance.createJobExecution());
|
||||
}
|
||||
|
||||
public void testCreateWithNulls(){
|
||||
|
||||
@@ -13,151 +13,202 @@ import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class JobParametersTests extends TestCase {
|
||||
|
||||
JobParameters parameters;
|
||||
|
||||
|
||||
Map stringMap;
|
||||
|
||||
|
||||
Map longMap;
|
||||
|
||||
|
||||
Map dateMap;
|
||||
|
||||
Date date1 = new Date(4321431242L);
|
||||
|
||||
Date date2 = new Date(7809089900L);
|
||||
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
parameters = getNewParameters();
|
||||
}
|
||||
|
||||
private JobParameters getNewParameters(){
|
||||
|
||||
|
||||
private JobParameters getNewParameters() {
|
||||
|
||||
stringMap = new HashMap();
|
||||
stringMap.put("string.key1", "value1");
|
||||
stringMap.put("string.key2", "value2");
|
||||
|
||||
|
||||
longMap = new HashMap();
|
||||
longMap.put("long.key1", new Long(1));
|
||||
longMap.put("long.key2", new Long(2));
|
||||
|
||||
|
||||
dateMap = new HashMap();
|
||||
dateMap.put("date.key1", date1 );
|
||||
dateMap.put("date.key2", date2 );
|
||||
|
||||
dateMap.put("date.key1", date1);
|
||||
dateMap.put("date.key2", date2);
|
||||
|
||||
return new JobParameters(stringMap, longMap, dateMap);
|
||||
}
|
||||
|
||||
public void testBadLongConstructorException() throws Exception{
|
||||
|
||||
|
||||
public void testBadLongKeyException() throws Exception {
|
||||
|
||||
Map badLongMap = new HashMap();
|
||||
badLongMap.put("key", "bad long");
|
||||
|
||||
try{
|
||||
badLongMap.put(new Long(0), new Long(1));
|
||||
|
||||
try {
|
||||
new JobParameters(stringMap, badLongMap, dateMap);
|
||||
fail();
|
||||
}
|
||||
catch(IllegalArgumentException ex){
|
||||
//expected
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testBadStringConstructorException() throws Exception{
|
||||
|
||||
|
||||
public void testBadLongConstructorException() throws Exception {
|
||||
|
||||
Map badLongMap = new HashMap();
|
||||
badLongMap.put("key", "bad long");
|
||||
|
||||
try {
|
||||
new JobParameters(stringMap, badLongMap, dateMap);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testBadStringConstructorException() throws Exception {
|
||||
|
||||
Map badMap = new HashMap();
|
||||
badMap.put("key", new Integer(2));
|
||||
|
||||
try{
|
||||
|
||||
try {
|
||||
new JobParameters(badMap, longMap, dateMap);
|
||||
fail();
|
||||
}
|
||||
catch(IllegalArgumentException ex){
|
||||
//expected
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testBadDateConstructorException() throws Exception{
|
||||
|
||||
|
||||
public void testBadDateConstructorException() throws Exception {
|
||||
|
||||
Map badMap = new HashMap();
|
||||
badMap.put("key", new java.sql.Date(System.currentTimeMillis()));
|
||||
|
||||
try{
|
||||
|
||||
try {
|
||||
new JobParameters(stringMap, longMap, badMap);
|
||||
fail();
|
||||
}
|
||||
catch(IllegalArgumentException ex){
|
||||
//expected
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetString(){
|
||||
|
||||
|
||||
public void testGetString() {
|
||||
assertEquals("value1", parameters.getString("string.key1"));
|
||||
assertEquals("value2", parameters.getString("string.key2"));
|
||||
}
|
||||
|
||||
public void testGetLong(){
|
||||
|
||||
|
||||
public void testGetStringParameters() {
|
||||
assertEquals("value1", parameters.getStringParameters().get("string.key1"));
|
||||
assertEquals("value2", parameters.getStringParameters().get("string.key2"));
|
||||
}
|
||||
|
||||
public void testGetLong() {
|
||||
assertEquals(new Long(1), parameters.getLong("long.key1"));
|
||||
assertEquals(new Long(2), parameters.getLong("long.key2"));
|
||||
}
|
||||
|
||||
public void testGetDate(){
|
||||
|
||||
|
||||
public void testGetLongParameters() {
|
||||
assertEquals(new Long(1), parameters.getLongParameters().get("long.key1"));
|
||||
assertEquals(new Long(2), parameters.getLongParameters().get("long.key2"));
|
||||
}
|
||||
|
||||
public void testGetDate() {
|
||||
assertEquals(date1, parameters.getDate("date.key1"));
|
||||
assertEquals(date2, parameters.getDate("date.key2"));
|
||||
}
|
||||
|
||||
public void testEquals(){
|
||||
|
||||
JobParameters testParameters = getNewParameters();
|
||||
|
||||
public void testGetDateParameters() {
|
||||
assertEquals(date1, parameters.getDateParameters().get("date.key1"));
|
||||
assertEquals(date2, parameters.getDateParameters().get("date.key2"));
|
||||
}
|
||||
|
||||
public void testIsEmptyWhenEmpty() throws Exception {
|
||||
assertTrue(new JobParameters().isEmpty());
|
||||
}
|
||||
|
||||
public void testIsEmptyWhenNotEmpty() throws Exception {
|
||||
assertFalse(parameters.isEmpty());
|
||||
}
|
||||
|
||||
public void testEquals() {
|
||||
JobParameters testParameters = getNewParameters();
|
||||
assertTrue(testParameters.equals(parameters));
|
||||
}
|
||||
|
||||
public void testToStringOrder(){
|
||||
|
||||
|
||||
public void testEqualsSelf() {
|
||||
assertTrue(parameters.equals(parameters));
|
||||
}
|
||||
|
||||
public void testEqualsDifferent() {
|
||||
assertFalse(parameters.equals(new JobParameters()));
|
||||
}
|
||||
|
||||
public void testEqualsWrongType() {
|
||||
assertFalse(parameters.equals("foo"));
|
||||
}
|
||||
|
||||
public void testEqualsNull() {
|
||||
assertFalse(parameters.equals(null));
|
||||
}
|
||||
|
||||
public void testToStringOrder() {
|
||||
|
||||
Map props = parameters.getParameters();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for(Iterator it = props.entrySet().iterator();it.hasNext();){
|
||||
Entry entry = (Entry)it.next();
|
||||
for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
|
||||
Entry entry = (Entry) it.next();
|
||||
stringBuilder.append(entry.toString() + ";");
|
||||
}
|
||||
|
||||
|
||||
String string1 = stringBuilder.toString();
|
||||
|
||||
|
||||
stringMap = new HashMap();
|
||||
stringMap.put("string.key2", "value2");
|
||||
stringMap.put("string.key1", "value1");
|
||||
|
||||
|
||||
longMap = new HashMap();
|
||||
longMap.put("long.key2", new Long(2));
|
||||
longMap.put("long.key1", new Long(1));
|
||||
|
||||
|
||||
|
||||
dateMap = new HashMap();
|
||||
dateMap.put("date.key2", date2 );
|
||||
dateMap.put("date.key1", date1 );
|
||||
|
||||
dateMap.put("date.key2", date2);
|
||||
dateMap.put("date.key1", date1);
|
||||
|
||||
JobParameters testProps = new JobParameters(stringMap, longMap, dateMap);
|
||||
|
||||
|
||||
props = testProps.getParameters();
|
||||
stringBuilder = new StringBuilder();
|
||||
for(Iterator it = props.entrySet().iterator();it.hasNext();){
|
||||
Entry entry = (Entry)it.next();
|
||||
for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
|
||||
Entry entry = (Entry) it.next();
|
||||
stringBuilder.append(entry.toString() + ";");
|
||||
}
|
||||
String string2 = stringBuilder.toString();
|
||||
|
||||
|
||||
assertEquals(string1, string2);
|
||||
}
|
||||
|
||||
// Not sure how to properly test this since there is no order garuntee, commenting out for now.
|
||||
//
|
||||
// public void testToString(){
|
||||
//
|
||||
// assertEquals("{string.key1=value1, string.key2=value2}{long.key1=1, long.key2=2}" +
|
||||
// "{date.key2=Wed Apr 01 03:11:29 CST 1970, date.key1=Thu Feb 19 18:23:51 CST 1970}", parameters.toString());
|
||||
// }
|
||||
public void testHashCodeEqualWhenEmpty() throws Exception {
|
||||
int code = new JobParameters().hashCode();
|
||||
assertEquals(code, new JobParameters().hashCode());
|
||||
}
|
||||
|
||||
public void testHashCodeEqualWhenNotEmpty() throws Exception {
|
||||
int code = getNewParameters().hashCode();
|
||||
assertEquals(code, parameters.hashCode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,5 +96,20 @@ public class JobSupportTests extends TestCase {
|
||||
job.setRestartable(true);
|
||||
assertTrue(job.isRestartable());
|
||||
}
|
||||
|
||||
public void testToString() throws Exception {
|
||||
String value = job.toString();
|
||||
assertTrue("Should contain name: "+value, value.indexOf("name=")>=0);
|
||||
}
|
||||
|
||||
public void testRunNotSupported() throws Exception {
|
||||
try {
|
||||
job.run(null);
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// expected
|
||||
String message = e.getMessage();
|
||||
assertTrue("Message should contain JobSupport: "+message, message.contains("JobSupport"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.domain;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class StepContributionTests extends TestCase {
|
||||
|
||||
private StepExecution execution = new StepExecution();
|
||||
private StepContribution contribution = new StepContribution(execution);
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.core.domain.StepContribution#incrementTaskCount()}.
|
||||
*/
|
||||
public void testIncrementTaskCount() {
|
||||
assertEquals(0, contribution.getTaskCount());
|
||||
contribution.incrementTaskCount();
|
||||
assertEquals(1, contribution.getTaskCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.core.domain.StepContribution#setStatistics(java.util.Properties)}.
|
||||
*/
|
||||
public void testSetStatistics() {
|
||||
assertEquals(null, contribution.getStatistics());
|
||||
contribution.setStatistics(PropertiesConverter.stringToProperties("foo=bar"));
|
||||
assertEquals(1, contribution.getStatistics().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.core.domain.StepContribution#incrementCommitCount()}.
|
||||
*/
|
||||
public void testIncrementCommitCount() {
|
||||
assertEquals(0, contribution.getCommitCount());
|
||||
contribution.incrementCommitCount();
|
||||
assertEquals(1, contribution.getCommitCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.core.domain.StepContribution#isTerminateOnly()}.
|
||||
*/
|
||||
public void testIsTerminateOnly() {
|
||||
assertFalse(contribution.isTerminateOnly());
|
||||
execution.setTerminateOnly();
|
||||
assertTrue(contribution.isTerminateOnly());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,6 +39,14 @@ public class StepExecutionTests extends TestCase {
|
||||
assertNull(new StepExecution().getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.domain.JobExecution#JobExecution()}.
|
||||
*/
|
||||
public void testStepExecutionWithNullId() {
|
||||
assertNull(new StepExecution(null, null).getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.domain.JobExecution#getEndTime()}.
|
||||
@@ -154,6 +162,32 @@ public class StepExecutionTests extends TestCase {
|
||||
public void testGetStepId() {
|
||||
assertEquals(11, execution.getStepId().longValue());
|
||||
}
|
||||
|
||||
public void testGetStep() throws Exception {
|
||||
assertNotNull(execution.getStep());
|
||||
}
|
||||
|
||||
public void testGetJobExecution() throws Exception {
|
||||
assertNotNull(execution.getJobExecution());
|
||||
}
|
||||
|
||||
public void testApplyContribution() throws Exception {
|
||||
StepContribution contribution = execution.createStepContribution();
|
||||
contribution.incrementCommitCount();
|
||||
execution.apply(contribution);
|
||||
assertEquals(new Integer(1), execution.getCommitCount());
|
||||
}
|
||||
|
||||
public void testTerminateOnly() throws Exception {
|
||||
assertFalse(execution.isTerminateOnly());
|
||||
execution.setTerminateOnly();
|
||||
assertTrue(execution.isTerminateOnly());
|
||||
}
|
||||
|
||||
public void testToStringWithNullName() throws Exception {
|
||||
String value = new StepExecution().toString();
|
||||
assertTrue("Should contain name=null: "+value, value.indexOf("name=null")>=0);
|
||||
}
|
||||
|
||||
public void testToString() throws Exception {
|
||||
assertTrue("Should contain task count: " + execution.toString(),
|
||||
@@ -200,6 +234,23 @@ public class StepExecutionTests extends TestCase {
|
||||
assertFalse(step.equals(new StepExecution()));
|
||||
}
|
||||
|
||||
public void testEqualsWithSelf() throws Exception {
|
||||
assertTrue(execution.equals(execution));
|
||||
}
|
||||
|
||||
public void testEqualsWithDifferent() throws Exception {
|
||||
StepExecution step = newStepExecution(new Long(43), new Long(13));
|
||||
assertFalse(execution.equals(step));
|
||||
}
|
||||
|
||||
public void testEqualsWithNullStepId() throws Exception {
|
||||
execution = newStepExecution(null, new Long(31));
|
||||
assertEquals(null, execution.getStepId());
|
||||
StepExecution step = newStepExecution(null, new Long(31));
|
||||
assertEquals(step.getJobExecutionId(), execution.getJobExecutionId());
|
||||
assertTrue(execution.equals(step));
|
||||
}
|
||||
|
||||
public void testHashCode() throws Exception {
|
||||
assertTrue("Hash code same as parent", new Entity(execution.getId())
|
||||
.hashCode() != execution.hashCode());
|
||||
@@ -217,4 +268,5 @@ public class StepExecutionTests extends TestCase {
|
||||
StepExecution execution = new StepExecution(step, new JobExecution(job, long2), new Long(4));
|
||||
return execution;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,6 +40,33 @@ public class StepSupportTests extends TestCase {
|
||||
*/
|
||||
public void testGetName() {
|
||||
assertEquals("step", configuration.getName());
|
||||
configuration.setName("bar");
|
||||
assertEquals("bar", configuration.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.core.domain.StepSupport#getName()}.
|
||||
*/
|
||||
public void testBeanNameAlreadySet() {
|
||||
assertEquals("step", configuration.getName());
|
||||
configuration.setBeanName("bar");
|
||||
assertEquals("step", configuration.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.core.domain.StepSupport#getName()}.
|
||||
*/
|
||||
public void testBeanNameOnNew() {
|
||||
configuration = new StepSupport();
|
||||
assertEquals(null, configuration.getName());
|
||||
configuration.setBeanName("bar");
|
||||
assertEquals("bar", configuration.getName());
|
||||
}
|
||||
|
||||
public void testSaveRestartFlag() throws Exception {
|
||||
assertEquals(false, configuration.isSaveRestartData());
|
||||
configuration.setSaveRestartData(true);
|
||||
assertEquals(true, configuration.isSaveRestartData());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user