diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java new file mode 100644 index 000000000..dae2c43f5 --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java @@ -0,0 +1,57 @@ +/* + * 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.launch; + +import java.util.Collection; +import java.util.Map; + +import org.springframework.batch.core.repository.JobInstanceAlreadyExistsException; +import org.springframework.batch.core.repository.JobRestartException; +import org.springframework.batch.core.repository.NoSuchJobException; +import org.springframework.batch.core.repository.NoSuchJobExecutionException; +import org.springframework.batch.core.repository.NoSuchJobInstanceException; + +/** + * A really low level interface for inspecting and controlling jobs with access + * only to primitive and collection types. Suitable for a command-line client + * (e.g. that launches a new process for each operation), or a remote launcher + * like a JMX console. + * + * @author Dave Syer + * + */ +public interface JobOperator { + + String getParameters(Long instanceId) throws NoSuchJobInstanceException; + + Long getLastInstance(String jobName) throws NoSuchJobException; + + Long start(String jobName, String parameters) throws NoSuchJobException, JobInstanceAlreadyExistsException, + JobRestartException; + + Long resume(Long instanceId) throws LastExecutionNotFailedException, NoSuchJobInstanceException; + + Long startNextInstance(String jobName) throws NoSuchJobException, JobParametersIncrementerNotFoundException; + + boolean stop(Long executionId) throws NoSuchJobExecutionException; + + Map status(Long executionId) throws NoSuchJobExecutionException; + + Collection getRunningExecutions(String jobName) throws NoSuchJobException; + + Collection getJobNames(); + +} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobParametersIncrementer.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobParametersIncrementer.java new file mode 100644 index 000000000..693df68d9 --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobParametersIncrementer.java @@ -0,0 +1,30 @@ +/* + * 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.launch; + +import org.springframework.batch.core.JobParameters; + +/** + * Interface for obtaining the next {@link JobParameters} in a sequence. + * + * @author Dave Syer + * + */ +public interface JobParametersIncrementer { + + JobParameters getNext(JobParameters parameters); + +} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobParametersIncrementerNotFoundException.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobParametersIncrementerNotFoundException.java new file mode 100644 index 000000000..35135647d --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobParametersIncrementerNotFoundException.java @@ -0,0 +1,44 @@ +/* + * 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.launch; + +import org.springframework.batch.core.JobExecutionException; + + +/** + * Checked exception to indicate that a required {@link JobParametersIncrementer} is not + * available. + * + * @author Dave Syer + * + */ +public class JobParametersIncrementerNotFoundException extends JobExecutionException { + + /** + * Create an exception with the given message. + */ + public JobParametersIncrementerNotFoundException(String msg) { + super(msg); + } + + /** + * @param msg The message to send to caller + * @param e the cause of the exception + */ + public JobParametersIncrementerNotFoundException(String msg, Throwable e) { + super(msg, e); + } +} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/LastExecutionNotFailedException.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/LastExecutionNotFailedException.java new file mode 100644 index 000000000..9a4159e6d --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/LastExecutionNotFailedException.java @@ -0,0 +1,43 @@ +/* + * 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.launch; + +import org.springframework.batch.core.JobExecutionException; + +/** + * Checked exception to indicate that user asked for a job execution to be + * resumed when actually it didn't fail. + * + * @author Dave Syer + * + */ +public class LastExecutionNotFailedException extends JobExecutionException { + + /** + * Create an exception with the given message. + */ + public LastExecutionNotFailedException(String msg) { + super(msg); + } + + /** + * @param msg The message to send to caller + * @param e the cause of the exception + */ + public LastExecutionNotFailedException(String msg, Throwable e) { + super(msg, e); + } +} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobInstanceAlreadyExistsException.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobInstanceAlreadyExistsException.java new file mode 100644 index 000000000..f1114c329 --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobInstanceAlreadyExistsException.java @@ -0,0 +1,45 @@ +/* + * 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.repository; + +import org.springframework.batch.core.Job; +import org.springframework.batch.core.JobExecutionException; + + +/** + * Checked exception to indicate that a required {@link Job} is not + * available. + * + * @author Dave Syer + * + */ +public class JobInstanceAlreadyExistsException extends JobExecutionException { + + /** + * Create an exception with the given message. + */ + public JobInstanceAlreadyExistsException(String msg) { + super(msg); + } + + /** + * @param msg The message to send to caller + * @param e the cause of the exception + */ + public JobInstanceAlreadyExistsException(String msg, Throwable e) { + super(msg, e); + } +} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/NoSuchJobExecutionException.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/NoSuchJobExecutionException.java new file mode 100644 index 000000000..dd7393321 --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/NoSuchJobExecutionException.java @@ -0,0 +1,44 @@ +/* + * 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.repository; + +import org.springframework.batch.core.JobExecution; +import org.springframework.batch.core.JobExecutionException; + +/** + * Checked exception to indicate that a required {@link JobExecution} is not + * available. + * + * @author Dave Syer + * + */ +public class NoSuchJobExecutionException extends JobExecutionException { + + /** + * Create an exception with the given message. + */ + public NoSuchJobExecutionException(String msg) { + super(msg); + } + + /** + * @param msg The message to send to caller + * @param e the cause of the exception + */ + public NoSuchJobExecutionException(String msg, Throwable e) { + super(msg, e); + } +} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/NoSuchJobInstanceException.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/NoSuchJobInstanceException.java new file mode 100644 index 000000000..fb680915c --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/NoSuchJobInstanceException.java @@ -0,0 +1,45 @@ +/* + * 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.repository; + +import org.springframework.batch.core.JobExecutionException; +import org.springframework.batch.core.JobInstance; + +/** + * Exception that signals that the user requested an operation on a non-existent + * {@link JobInstance}. + * + * @author Dave Syer + * + */ +public class NoSuchJobInstanceException extends JobExecutionException { + + /** + * Create an exception with the given message. + */ + public NoSuchJobInstanceException(String msg) { + super(msg); + } + + /** + * @param msg The message to send to caller + * @param e the cause of the exception + */ + public NoSuchJobInstanceException(String msg, Throwable e) { + super(msg, e); + } + +} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java index dbfd02be7..845760dfe 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import org.springframework.batch.core.Job; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameter; import org.springframework.batch.core.JobParameters; @@ -51,24 +50,23 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements * jobIncrementer (which is likely a sequence) for the nextLong, and then * passing the Id and parameter values into an INSERT statement. * - * @see JobInstanceDao#createJobInstance(Job, JobParameters) + * @see JobInstanceDao#createJobInstance(String, JobParameters) * @throws IllegalArgumentException if any {@link JobParameters} fields are * null. */ - public JobInstance createJobInstance(Job job, JobParameters jobParameters) { + public JobInstance createJobInstance(String jobName, JobParameters jobParameters) { - Assert.notNull(job, "Job must not be null."); - Assert.hasLength(job.getName(), "Job must have a name"); + Assert.notNull(jobName, "Job name must not be null."); Assert.notNull(jobParameters, "JobParameters must not be null."); - Assert.state(getJobInstance(job, jobParameters) == null, "JobInstance must not already exist"); + Assert.state(getJobInstance(jobName, jobParameters) == null, "JobInstance must not already exist"); Long jobId = new Long(jobIncrementer.nextLongValue()); - JobInstance jobInstance = new JobInstance(jobId, jobParameters, job.getName()); + JobInstance jobInstance = new JobInstance(jobId, jobParameters, jobName); jobInstance.incrementVersion(); - Object[] parameters = new Object[] { jobId, job.getName(), createJobKey(jobParameters), + Object[] parameters = new Object[] { jobId, jobName, createJobKey(jobParameters), jobInstance.getVersion() }; getJdbcTemplate().update(getQuery(CREATE_JOB_INSTANCE), parameters, new int[] { Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER }); @@ -132,24 +130,23 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements * The job table is queried for any jobs that match the * given identifier, adding them to a list via the RowMapper callback. * - * @see JobInstanceDao#getJobInstance(Job, JobParameters) + * @see JobInstanceDao#getJobInstance(String, JobParameters) * @throws IllegalArgumentException if any {@link JobParameters} fields are * null. */ @SuppressWarnings("unchecked") - public JobInstance getJobInstance(final Job job, final JobParameters jobParameters) { + public JobInstance getJobInstance(final String jobName, final JobParameters jobParameters) { - Assert.notNull(job, "Job must not be null."); - Assert.hasLength(job.getName(), "Job must have a name"); + Assert.notNull(jobName, "Job name must not be null."); Assert.notNull(jobParameters, "JobParameters must not be null."); String jobKey = createJobKey(jobParameters); - Object[] parameters = new Object[] { job.getName(), jobKey }; + Object[] parameters = new Object[] { jobName, jobKey }; RowMapper rowMapper = new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { - JobInstance jobInstance = new JobInstance(new Long(rs.getLong(1)), jobParameters, job.getName()); + JobInstance jobInstance = new JobInstance(new Long(rs.getLong(1)), jobParameters, jobName); return jobInstance; } }; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobInstanceDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobInstanceDao.java index 765344127..a3e6dbdae 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobInstanceDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobInstanceDao.java @@ -21,22 +21,22 @@ public interface JobInstanceDao { * PostConditions: A valid job instance will be returned which has been persisted and * contains an unique Id. * - * @param job + * @param jobName * @param jobParameters * @return JobInstance */ - JobInstance createJobInstance(Job job, JobParameters jobParameters); + JobInstance createJobInstance(String jobName, JobParameters jobParameters); /** * Find all job instances that match the given name and parameters. If no * matching job instances are found, then a list of size 0 will be * returned. * - * @param job + * @param jobName * @param jobParameters * @return {@link JobInstance} object matching * {@link Job} and {@link JobParameters} */ - JobInstance getJobInstance(Job job, JobParameters jobParameters); + JobInstance getJobInstance(String jobName, JobParameters jobParameters); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobInstanceDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobInstanceDao.java index 0be6b28b5..61901c23d 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobInstanceDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobInstanceDao.java @@ -2,7 +2,6 @@ package org.springframework.batch.core.repository.dao; import java.util.Collection; -import org.springframework.batch.core.Job; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.support.transaction.TransactionAwareProxyFactory; @@ -21,21 +20,21 @@ public class MapJobInstanceDao implements JobInstanceDao { jobInstances.clear(); } - public JobInstance createJobInstance(Job job, JobParameters jobParameters) { + public JobInstance createJobInstance(String jobName, JobParameters jobParameters) { - Assert.state(getJobInstance(job, jobParameters) == null, "JobInstance must not already exist"); + Assert.state(getJobInstance(jobName, jobParameters) == null, "JobInstance must not already exist"); - JobInstance jobInstance = new JobInstance(new Long(currentId++), jobParameters, job.getName()); + JobInstance jobInstance = new JobInstance(new Long(currentId++), jobParameters, jobName); jobInstance.incrementVersion(); jobInstances.add(jobInstance); return jobInstance; } - public JobInstance getJobInstance(Job job, JobParameters jobParameters) { + public JobInstance getJobInstance(String jobName, JobParameters jobParameters) { for (JobInstance instance : jobInstances) { - if (instance.getJobName().equals(job.getName()) && instance.getJobParameters().equals(jobParameters)) { + if (instance.getJobName().equals(jobName) && instance.getJobParameters().equals(jobParameters)) { return instance; } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java index d98d90a60..c04b0495b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java @@ -154,7 +154,7 @@ public class SimpleJobRepository implements JobRepository { * has finished. */ - JobInstance jobInstance = jobInstanceDao.getJobInstance(job, jobParameters); + JobInstance jobInstance = jobInstanceDao.getJobInstance(job.getName(), jobParameters); ExecutionContext executionContext; // existing job instance found @@ -181,7 +181,7 @@ public class SimpleJobRepository implements JobRepository { } else { // no job found, create one - jobInstance = jobInstanceDao.createJobInstance(job, jobParameters); + jobInstance = jobInstanceDao.createJobInstance(job.getName(), jobParameters); executionContext = new ExecutionContext(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java index 919b73ebf..b53d369d3 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java @@ -445,7 +445,7 @@ public class SimpleJobTests extends TestCase { * Check JobRepository to ensure status is being saved. */ private void checkRepository(BatchStatus status, ExitStatus exitStatus) { - assertEquals(jobInstance, jobInstanceDao.getJobInstance(job, jobParameters)); + assertEquals(jobInstance, jobInstanceDao.getJobInstance(job.getName(), jobParameters)); // because map dao stores in memory, it can be checked directly JobExecution jobExecution = (JobExecution) jobExecutionDao.findJobExecutions(jobInstance).get(0); assertEquals(jobInstance.getId(), jobExecution.getJobId()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobDaoTests.java index 31d5f80d5..6c07b849a 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobDaoTests.java @@ -16,27 +16,29 @@ package org.springframework.batch.core.repository.dao; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.util.Date; import java.util.List; import java.util.Map; +import javax.sql.DataSource; + +import org.junit.Before; +import org.junit.Test; import org.springframework.batch.core.BatchStatus; -import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; -import org.springframework.batch.core.job.JobSupport; import org.springframework.batch.repeat.ExitStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.transaction.annotation.Transactional; -import org.junit.Before; -import org.junit.Test; - -import javax.sql.DataSource; /** * @author Dave Syer @@ -53,7 +55,7 @@ public abstract class AbstractJobDaoTests { protected JobInstance jobInstance; - protected Job job; + protected String jobName = "Job1"; protected JobExecution jobExecution; @@ -83,10 +85,8 @@ public abstract class AbstractJobDaoTests { @Before public void onSetUpInTransaction() throws Exception { - job = new JobSupport("Job1"); - // Create job. - jobInstance = jobInstanceDao.createJobInstance(job, jobParameters); + jobInstance = jobInstanceDao.createJobInstance(jobName, jobParameters); // Create an execution jobExecutionStartTime = new Date(System.currentTimeMillis()); @@ -113,14 +113,14 @@ public abstract class AbstractJobDaoTests { @Transactional @Test public void testFindNonExistentJob() { // No job should be found since it hasn't been created. - JobInstance jobInstance = jobInstanceDao.getJobInstance(new JobSupport("nonexistentJob"), jobParameters); + JobInstance jobInstance = jobInstanceDao.getJobInstance("nonexistentJob", jobParameters); assertNull(jobInstance); } @Transactional @Test public void testFindJob() { - JobInstance instance = jobInstanceDao.getJobInstance(job, jobParameters); + JobInstance instance = jobInstanceDao.getJobInstance(jobName, jobParameters); assertNotNull(instance); assertTrue(jobInstance.equals(instance)); assertEquals(jobParameters, instance.getJobParameters()); @@ -146,7 +146,7 @@ public abstract class AbstractJobDaoTests { @Transactional @Test public void testCreateJobWithExistingName() { - Job scheduledJob = new JobSupport("ScheduledJob"); + String scheduledJob = "ScheduledJob"; jobInstanceDao.createJobInstance(scheduledJob, jobParameters); // Modifying the key should bring back a completely different @@ -216,7 +216,7 @@ public abstract class AbstractJobDaoTests { @Transactional @Test public void testJobWithSimpleJobIdentifier() throws Exception { - Job testJob = new JobSupport("test"); + String testJob = "test"; // Create job. jobInstance = jobInstanceDao.createJobInstance(testJob, jobParameters); @@ -231,7 +231,7 @@ public abstract class AbstractJobDaoTests { @Transactional @Test public void testJobWithDefaultJobIdentifier() throws Exception { - Job testDefaultJob = new JobSupport("testDefault"); + String testDefaultJob = "testDefault"; // Create job. jobInstance = jobInstanceDao.createJobInstance(testDefaultJob, jobParameters); @@ -286,10 +286,10 @@ public abstract class AbstractJobDaoTests { jobParameters = new JobParameters(); - jobInstanceDao.createJobInstance(job, jobParameters); + jobInstanceDao.createJobInstance(jobName, jobParameters); try { - jobInstanceDao.createJobInstance(job, jobParameters); + jobInstanceDao.createJobInstance(jobName, jobParameters); fail(); } catch (IllegalStateException e) { @@ -300,7 +300,7 @@ public abstract class AbstractJobDaoTests { @Transactional @Test public void testCreationAddsVersion() { - jobInstance = jobInstanceDao.createJobInstance(new JobSupport("testCreationAddsVersion"), new JobParameters()); + jobInstance = jobInstanceDao.createJobInstance("testCreationAddsVersion", new JobParameters()); assertNotNull(jobInstance.getVersion()); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobInstanceDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobInstanceDaoTests.java index 718415cc4..c8b25a95f 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobInstanceDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobInstanceDaoTests.java @@ -1,16 +1,17 @@ package org.springframework.batch.core.repository.dao; -import static org.junit.Assert.*; -import org.junit.Before; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; import java.util.Date; -import org.springframework.batch.core.Job; +import org.junit.Before; +import org.junit.Test; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; -import org.springframework.batch.core.job.JobSupport; import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; import org.springframework.transaction.annotation.Transactional; @@ -20,7 +21,7 @@ public abstract class AbstractJobInstanceDaoTests extends AbstractTransactionalJ private JobInstanceDao dao = new MapJobInstanceDao(); - private Job fooJob = new JobSupport("foo"); + private String fooJob = "foo"; private JobParameters fooParams = new JobParametersBuilder().addString("stringKey", "stringValue").addLong( "longKey", Long.MAX_VALUE).addDouble("doubleKey", Double.MAX_VALUE).addDate( @@ -41,13 +42,13 @@ public abstract class AbstractJobInstanceDaoTests extends AbstractTransactionalJ JobInstance fooInstance = dao.createJobInstance(fooJob, fooParams); assertNotNull(fooInstance.getId()); - assertEquals(fooJob.getName(), fooInstance.getJobName()); + assertEquals(fooJob, fooInstance.getJobName()); assertEquals(fooParams, fooInstance.getJobParameters()); JobInstance retrievedInstance = dao.getJobInstance(fooJob, fooParams); JobParameters retrievedParams = retrievedInstance.getJobParameters(); assertEquals(fooInstance, retrievedInstance); - assertEquals(fooJob.getName(), retrievedInstance.getJobName()); + assertEquals(fooJob, retrievedInstance.getJobName()); assertEquals(fooParams, retrievedParams); assertEquals(Long.MAX_VALUE, retrievedParams.getLong("longKey")); @@ -80,7 +81,7 @@ public abstract class AbstractJobInstanceDaoTests extends AbstractTransactionalJ assertNull(jobInstance.getVersion()); - jobInstance = dao.createJobInstance(new JobSupport("testVersion"), new JobParameters()); + jobInstance = dao.createJobInstance("testVersion", new JobParameters()); assertNotNull(jobInstance.getVersion()); } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/order/internal/OrderTransformer.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/order/internal/OrderTransformer.java index 6fa8989c3..ed0b20c83 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/order/internal/OrderTransformer.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/order/internal/OrderTransformer.java @@ -38,7 +38,7 @@ public class OrderTransformer implements ItemTransformer> { /** * Aggregators for all types of lines in the output file */ - private Map> aggregators; + private Map> aggregators; /** * Converts information from an Order object to a collection of Strings for @@ -64,11 +64,11 @@ public class OrderTransformer implements ItemTransformer> { return result; } - public void setAggregators(Map> aggregators) { + public void setAggregators(Map> aggregators) { this.aggregators = aggregators; } - private LineAggregator getAggregator(String name) { + private LineAggregator getAggregator(String name) { return aggregators.get(name); } @@ -80,36 +80,36 @@ public class OrderTransformer implements ItemTransformer> { private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); - static String[] headerArgs(Order order) { - return new String[] { "BEGIN_ORDER:", String.valueOf(order.getOrderId()), + static Object[] headerArgs(Order order) { + return new Object[] { "BEGIN_ORDER:", String.valueOf(order.getOrderId()), dateFormat.format(order.getOrderDate()) }; } - static String[] footerArgs(Order order) { - return new String[] { "END_ORDER:", order.getTotalPrice().toString() }; + static Object[] footerArgs(Order order) { + return new Object[] { "END_ORDER:", order.getTotalPrice().toString() }; } - static String[] customerArgs(Order order) { + static Object[] customerArgs(Order order) { Customer customer = order.getCustomer(); - return new String[] { "CUSTOMER:", String.valueOf(customer.getRegistrationId()), customer.getFirstName(), + return new Object[] { "CUSTOMER:", String.valueOf(customer.getRegistrationId()), customer.getFirstName(), customer.getMiddleName(), customer.getLastName() }; } - static String[] lineItemArgs(LineItem item) { - return new String[] { "ITEM:", String.valueOf(item.getItemId()), item.getPrice().toString() }; + static Object[] lineItemArgs(LineItem item) { + return new Object[] { "ITEM:", String.valueOf(item.getItemId()), item.getPrice().toString() }; } - static String[] billingAddressArgs(Order order) { + static Object[] billingAddressArgs(Order order) { Address address = order.getBillingAddress(); - return new String[] { "ADDRESS:", address.getAddrLine1(), address.getCity(), address.getZipCode() }; + return new Object[] { "ADDRESS:", address.getAddrLine1(), address.getCity(), address.getZipCode() }; } - static String[] billingInfoArgs(Order order) { + static Object[] billingInfoArgs(Order order) { BillingInfo billingInfo = order.getBilling(); - return new String[] { "BILLING:", billingInfo.getPaymentId(), billingInfo.getPaymentDesc() }; + return new Object[] { "BILLING:", billingInfo.getPaymentId(), billingInfo.getPaymentDesc() }; } } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/FlatFileOrderAggregatorTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/FlatFileOrderAggregatorTests.java index 4db61e862..b0c2d4e4c 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/FlatFileOrderAggregatorTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/FlatFileOrderAggregatorTests.java @@ -50,10 +50,10 @@ public class FlatFileOrderAggregatorTests { order.setTotalPrice(BigDecimal.valueOf(0)); // create aggregator stub - LineAggregator aggregator = new DelimitedLineAggregator(); + LineAggregator aggregator = new DelimitedLineAggregator(); // create map of aggregators and set it to writer - Map> aggregators = new HashMap>(); + Map> aggregators = new HashMap>(); OrderTransformer converter = new OrderTransformer(); aggregators.put("header", aggregator); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/OrderTransformerTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/OrderTransformerTests.java deleted file mode 100644 index a074b8953..000000000 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/order/OrderTransformerTests.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2006-2008 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.sample.domain.order; - -import static org.junit.Assert.assertTrue; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; - -import org.junit.Test; -import org.springframework.batch.item.file.transform.LineAggregator; -import org.springframework.batch.item.file.transform.PassThroughLineAggregator; -import org.springframework.batch.sample.domain.order.internal.OrderTransformer; - -/** - * @author Dave Syer - * - */ -public class OrderTransformerTests { - - private OrderTransformer converter = new OrderTransformer(); - - @Test - public void testConvert() throws Exception { - converter.setAggregators(new HashMap>() { - { - put("header", new PassThroughLineAggregator()); - put("customer", new PassThroughLineAggregator()); - put("address", new PassThroughLineAggregator()); - put("billing", new PassThroughLineAggregator()); - put("item", new PassThroughLineAggregator()); - put("footer", new PassThroughLineAggregator()); - } - }); - Order order = new Order(); - order.setOrderDate(new Date()); - order.setCustomer(new Customer()); - order.setBillingAddress(new Address()); - order.setBilling(new BillingInfo()); - order.setLineItems(new ArrayList()); - order.setTotalPrice(new BigDecimal(10)); - Object result = converter.transform(order); - assertTrue(result instanceof Collection); - } - -}