diff --git a/build.gradle b/build.gradle index 17cd5fffc..ea3282ad7 100644 --- a/build.gradle +++ b/build.gradle @@ -447,6 +447,7 @@ project('spring-batch-test') { testCompile "org.hsqldb:hsqldb:$hsqldbVersion" optional "org.aspectj:aspectjrt:$aspectjVersion" + optional "javax.batch:javax.batch-api:$javaxBatchApiVersion" } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/AbstractJsrTestCase.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/AbstractJsrTestCase.java new file mode 100644 index 000000000..8220363c0 --- /dev/null +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/AbstractJsrTestCase.java @@ -0,0 +1,120 @@ +/* + * Copyright 2014 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.jsr; + +import javax.batch.operations.JobOperator; +import javax.batch.runtime.BatchRuntime; +import javax.batch.runtime.BatchStatus; +import javax.batch.runtime.JobExecution; +import javax.batch.runtime.Metric; +import javax.batch.runtime.StepExecution; +import java.util.Date; +import java.util.Properties; +import java.util.concurrent.TimeoutException; + +/** + * @author mminella + */ +public abstract class AbstractJsrTestCase { + + private static JobOperator operator; + + static { + operator = BatchRuntime.getJobOperator(); + } + + /** + * Executes a job and waits for it's status to be any of {@link javax.batch.runtime.BatchStatus#STOPPED}, + * {@link javax.batch.runtime.BatchStatus#COMPLETED}, or {@link javax.batch.runtime.BatchStatus#FAILED}. If the job does not + * reach one of those statuses within the given timeout, a {@link java.util.concurrent.TimeoutException} is + * thrown. + * + * @param jobName + * @param properties + * @param timeout + * @return the {@link javax.batch.runtime.JobExecution} for the final state of the job + * @throws java.util.concurrent.TimeoutException if the timeout occurs + */ + public static JobExecution runJob(String jobName, Properties properties, long timeout) throws TimeoutException { + long executionId = operator.start(jobName, properties); + JobExecution execution = operator.getJobExecution(executionId); + + Date curDate = new Date(); + BatchStatus curBatchStatus = execution.getBatchStatus(); + + while(true) { + if(curBatchStatus == BatchStatus.STOPPED || curBatchStatus == BatchStatus.COMPLETED || curBatchStatus == BatchStatus.FAILED) { + break; + } + + if(new Date().getTime() - curDate.getTime() > timeout) { + throw new TimeoutException("Job processing did not complete in time"); + } + + execution = operator.getJobExecution(executionId); + curBatchStatus = execution.getBatchStatus(); + } + return execution; + } + + /** + * Restarts a job and waits for it's status to be any of {@link BatchStatus#STOPPED}, + * {@link BatchStatus#COMPLETED}, or {@link BatchStatus#FAILED}. If the job does not + * reach one of those statuses within the given timeout, a {@link java.util.concurrent.TimeoutException} is + * thrown. + * + * @param executionId + * @param properties + * @param timeout + * @return the {@link JobExecution} for the final state of the job + * @throws java.util.concurrent.TimeoutException if the timeout occurs + */ + public static JobExecution restartJob(long executionId, Properties properties, long timeout) throws TimeoutException { + long restartId = operator.restart(executionId, properties); + JobExecution execution = operator.getJobExecution(restartId); + + Date curDate = new Date(); + BatchStatus curBatchStatus = execution.getBatchStatus(); + + while(true) { + if(curBatchStatus == BatchStatus.STOPPED || curBatchStatus == BatchStatus.COMPLETED || curBatchStatus == BatchStatus.FAILED) { + break; + } + + if(new Date().getTime() - curDate.getTime() > timeout) { + throw new TimeoutException("Job processing did not complete in time"); + } + + execution = operator.getJobExecution(restartId); + curBatchStatus = execution.getBatchStatus(); + } + return execution; + } + + public static Metric getMetric(StepExecution stepExecution, Metric.MetricType type) { + Metric[] metrics = stepExecution.getMetrics(); + + for (Metric metric : metrics) { + if(metric.getType() == type) { + return metric; + } + } + + return null; + } + + +} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/ExceptionHandlingParsingTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/ExceptionHandlingParsingTests.java index 16ef9085d..4db7ba4d2 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/ExceptionHandlingParsingTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/ExceptionHandlingParsingTests.java @@ -16,8 +16,7 @@ package org.springframework.batch.core.jsr.configuration.xml; import org.junit.Test; -import org.springframework.batch.core.JobParametersBuilder; -import org.springframework.batch.core.jsr.JsrTestUtils; +import org.springframework.batch.core.jsr.AbstractJsrTestCase; import javax.batch.api.BatchProperty; import javax.batch.api.chunk.ItemProcessor; @@ -28,13 +27,12 @@ import javax.batch.runtime.JobExecution; import javax.batch.runtime.Metric; import javax.batch.runtime.StepExecution; import javax.inject.Inject; -import java.util.ArrayList; import java.util.List; import java.util.Properties; import static org.junit.Assert.assertEquals; -public class ExceptionHandlingParsingTests { +public class ExceptionHandlingParsingTests extends AbstractJsrTestCase { @Test public void testSkippable() throws Exception { @@ -42,32 +40,32 @@ public class ExceptionHandlingParsingTests { Properties jobParameters = new Properties(); jobParameters.setProperty("run", "1"); - JobExecution execution1 = JsrTestUtils.runJob("ExceptionHandlingParsingTests-context", jobParameters, 10000l); + JobExecution execution1 = runJob("ExceptionHandlingParsingTests-context", jobParameters, 10000l); List stepExecutions = jobOperator.getStepExecutions(execution1.getExecutionId()); assertEquals(BatchStatus.FAILED, execution1.getBatchStatus()); assertEquals(1, stepExecutions.size()); - assertEquals(1, JsrTestUtils.getMetric(stepExecutions.get(0), Metric.MetricType.PROCESS_SKIP_COUNT).getValue()); + assertEquals(1, getMetric(stepExecutions.get(0), Metric.MetricType.PROCESS_SKIP_COUNT).getValue()); jobParameters = new Properties(); jobParameters.setProperty("run", "2"); - JobExecution execution2 = JsrTestUtils.restartJob(execution1.getExecutionId(), jobParameters, 10000l); + JobExecution execution2 = restartJob(execution1.getExecutionId(), jobParameters, 10000l); stepExecutions = jobOperator.getStepExecutions(execution2.getExecutionId()); assertEquals(BatchStatus.FAILED, execution2.getBatchStatus()); assertEquals(2, stepExecutions.size()); jobParameters = new Properties(); jobParameters.setProperty("run", "3"); - JobExecution execution3 = JsrTestUtils.restartJob(execution2.getExecutionId(), jobParameters, 10000l); + JobExecution execution3 = restartJob(execution2.getExecutionId(), jobParameters, 10000l); stepExecutions = jobOperator.getStepExecutions(execution3.getExecutionId()); assertEquals(BatchStatus.COMPLETED, execution3.getBatchStatus()); assertEquals(2, stepExecutions.size()); - assertEquals(0, JsrTestUtils.getMetric(stepExecutions.get(1), Metric.MetricType.ROLLBACK_COUNT).getValue()); + assertEquals(0, getMetric(stepExecutions.get(1), Metric.MetricType.ROLLBACK_COUNT).getValue()); jobParameters = new Properties(); jobParameters.setProperty("run", "4"); - JobExecution execution4 = JsrTestUtils.runJob("ExceptionHandlingParsingTests-context", jobParameters, 10000l); + JobExecution execution4 = runJob("ExceptionHandlingParsingTests-context", jobParameters, 10000l); stepExecutions = jobOperator.getStepExecutions(execution4.getExecutionId()); assertEquals(BatchStatus.COMPLETED, execution4.getBatchStatus()); assertEquals(3, stepExecutions.size()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/FlowParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/FlowParserTests.java index 48bd656ca..1ca0160d1 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/FlowParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/FlowParserTests.java @@ -15,13 +15,9 @@ */ package org.springframework.batch.core.jsr.configuration.xml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.springframework.batch.core.jsr.JsrTestUtils.restartJob; -import static org.springframework.batch.core.jsr.JsrTestUtils.runJob; - -import java.util.List; -import java.util.Properties; +import org.junit.Test; +import org.springframework.batch.core.ExitStatus; +import org.springframework.batch.core.jsr.AbstractJsrTestCase; import javax.batch.api.AbstractBatchlet; import javax.batch.operations.JobOperator; @@ -30,9 +26,11 @@ import javax.batch.runtime.JobExecution; import javax.batch.runtime.StepExecution; import javax.batch.runtime.context.StepContext; import javax.inject.Inject; +import java.util.List; +import java.util.Properties; -import org.junit.Test; -import org.springframework.batch.core.ExitStatus; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** *

@@ -42,7 +40,7 @@ import org.springframework.batch.core.ExitStatus; * @author Chris Schaefer * @since 3.0 */ -public class FlowParserTests { +public class FlowParserTests extends AbstractJsrTestCase { @Test public void testDuplicateTransitionPatternsAllowed() throws Exception { JobExecution stoppedExecution = runJob("FlowParserTests-context", new Properties(), 10000L); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/ItemSkipParsingTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/ItemSkipParsingTests.java index d86092854..511badcbb 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/ItemSkipParsingTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/ItemSkipParsingTests.java @@ -16,7 +16,7 @@ package org.springframework.batch.core.jsr.configuration.xml; import org.junit.Test; -import org.springframework.batch.core.jsr.JsrTestUtils; +import org.springframework.batch.core.jsr.AbstractJsrTestCase; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; @@ -35,46 +35,46 @@ import java.util.Properties; import static org.junit.Assert.assertEquals; -public class ItemSkipParsingTests { +public class ItemSkipParsingTests extends AbstractJsrTestCase { @Test public void test() throws Exception { - javax.batch.runtime.JobExecution execution = JsrTestUtils.runJob("ItemSkipParsingTests-context", new Properties(), 10000l); + javax.batch.runtime.JobExecution execution = runJob("ItemSkipParsingTests-context", new Properties(), 10000l); JobOperator jobOperator = BatchRuntime.getJobOperator(); assertEquals(BatchStatus.FAILED, execution.getBatchStatus()); List stepExecutions = jobOperator.getStepExecutions(execution.getExecutionId()); - assertEquals(1, JsrTestUtils.getMetric(stepExecutions.get(0), Metric.MetricType.READ_SKIP_COUNT).getValue()); + assertEquals(1, getMetric(stepExecutions.get(0), Metric.MetricType.READ_SKIP_COUNT).getValue()); assertEquals(1, TestSkipListener.readSkips); assertEquals(0, TestSkipListener.processSkips); assertEquals(0, TestSkipListener.writeSkips); // Process skip and fail - execution = JsrTestUtils.restartJob(execution.getExecutionId(), new Properties(), 10000l); + execution = restartJob(execution.getExecutionId(), new Properties(), 10000l); assertEquals(BatchStatus.FAILED, execution.getBatchStatus()); stepExecutions = jobOperator.getStepExecutions(execution.getExecutionId()); - assertEquals(1, JsrTestUtils.getMetric(stepExecutions.get(0), Metric.MetricType.PROCESS_SKIP_COUNT).getValue()); + assertEquals(1, getMetric(stepExecutions.get(0), Metric.MetricType.PROCESS_SKIP_COUNT).getValue()); assertEquals(0, TestSkipListener.readSkips); assertEquals(1, TestSkipListener.processSkips); assertEquals(0, TestSkipListener.writeSkips); // Write skip and fail - execution = JsrTestUtils.restartJob(execution.getExecutionId(), new Properties(), 10000l); + execution = restartJob(execution.getExecutionId(), new Properties(), 10000l); assertEquals(BatchStatus.FAILED, execution.getBatchStatus()); stepExecutions = jobOperator.getStepExecutions(execution.getExecutionId()); - assertEquals(1, JsrTestUtils.getMetric(stepExecutions.get(0), Metric.MetricType.WRITE_SKIP_COUNT).getValue()); + assertEquals(1, getMetric(stepExecutions.get(0), Metric.MetricType.WRITE_SKIP_COUNT).getValue()); assertEquals(0, TestSkipListener.readSkips); assertEquals(0, TestSkipListener.processSkips); assertEquals(1, TestSkipListener.writeSkips); // Complete - execution = JsrTestUtils.restartJob(execution.getExecutionId(), new Properties(), 10000l); + execution = restartJob(execution.getExecutionId(), new Properties(), 10000l); assertEquals(BatchStatus.COMPLETED, execution.getBatchStatus()); stepExecutions = jobOperator.getStepExecutions(execution.getExecutionId()); - assertEquals(0, JsrTestUtils.getMetric(stepExecutions.get(0), Metric.MetricType.WRITE_SKIP_COUNT).getValue()); + assertEquals(0, getMetric(stepExecutions.get(0), Metric.MetricType.WRITE_SKIP_COUNT).getValue()); assertEquals(0, TestSkipListener.readSkips); assertEquals(0, TestSkipListener.processSkips); assertEquals(0, TestSkipListener.writeSkips); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JobPropertyTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JobPropertyTests.java index 3ddcd2f63..42acaae6e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JobPropertyTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JobPropertyTests.java @@ -15,9 +15,12 @@ */ package org.springframework.batch.core.jsr.configuration.xml; -import java.io.Serializable; -import java.util.List; -import java.util.Properties; +import org.junit.Test; +import org.springframework.batch.core.StepContribution; +import org.springframework.batch.core.jsr.AbstractJsrTestCase; +import org.springframework.batch.core.scope.context.ChunkContext; +import org.springframework.batch.core.step.tasklet.Tasklet; +import org.springframework.batch.repeat.RepeatStatus; import javax.batch.api.BatchProperty; import javax.batch.api.Batchlet; @@ -31,13 +34,9 @@ import javax.batch.runtime.BatchStatus; import javax.batch.runtime.JobExecution; import javax.batch.runtime.context.JobContext; import javax.inject.Inject; - -import org.junit.Test; -import org.springframework.batch.core.StepContribution; -import org.springframework.batch.core.jsr.JsrTestUtils; -import org.springframework.batch.core.scope.context.ChunkContext; -import org.springframework.batch.core.step.tasklet.Tasklet; -import org.springframework.batch.repeat.RepeatStatus; +import java.io.Serializable; +import java.util.List; +import java.util.Properties; import static junit.framework.Assert.assertEquals; @@ -49,7 +48,7 @@ import static junit.framework.Assert.assertEquals; * @author Chris Schaefer * @since 3.0 */ -public class JobPropertyTests { +public class JobPropertyTests extends AbstractJsrTestCase { @Test public void testJobPropertyConfiguration() throws Exception { Properties jobParameters = new Properties(); @@ -57,7 +56,7 @@ public class JobPropertyTests { jobParameters.setProperty("deciderName", "stepDecider"); jobParameters.setProperty("deciderNumber", "1"); - JobExecution jobExecution = JsrTestUtils.runJob("jsrJobPropertyTestsContext", jobParameters, 5000L); + JobExecution jobExecution = runJob("jsrJobPropertyTestsContext", jobParameters, 5000L); assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus()); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JsrBeanDefinitionDocumentReaderTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JsrBeanDefinitionDocumentReaderTests.java index 2b6f9ef98..f080475c9 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JsrBeanDefinitionDocumentReaderTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JsrBeanDefinitionDocumentReaderTests.java @@ -15,13 +15,10 @@ */ package org.springframework.batch.core.jsr.configuration.xml; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Test; -import org.springframework.batch.core.jsr.JsrTestUtils; +import org.springframework.batch.core.jsr.AbstractJsrTestCase; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.xml.DefaultDocumentLoader; import org.springframework.beans.factory.xml.DelegatingEntityResolver; @@ -35,6 +32,9 @@ import org.xml.sax.InputSource; import javax.batch.api.Batchlet; import javax.batch.runtime.JobExecution; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; @@ -47,7 +47,7 @@ import static junit.framework.Assert.assertTrue; * * @author Chris Schaefer */ -public class JsrBeanDefinitionDocumentReaderTests { +public class JsrBeanDefinitionDocumentReaderTests extends AbstractJsrTestCase { private static final String JOB_PARAMETERS_BEAN_DEFINITION_NAME = "jsr_jobParameters"; private Log logger = LogFactory.getLog(getClass()); @@ -173,7 +173,7 @@ public class JsrBeanDefinitionDocumentReaderTests { @Test public void testArtifactUniqueness() throws Exception { - JobExecution jobExecution = JsrTestUtils.runJob("jsrUniqueInstanceTests", new Properties(), 10000L); + JobExecution jobExecution = runJob("jsrUniqueInstanceTests", new Properties(), 10000L); String exitStatus = jobExecution.getExitStatus(); assertTrue("Exit status must contain listener3", exitStatus.contains("listener3")); @@ -234,7 +234,7 @@ public class JsrBeanDefinitionDocumentReaderTests { @Test public void testSpringArtifactUniqueness() throws Exception { - JobExecution jobExecution = JsrTestUtils.runJob("jsrSpringInstanceTests", new Properties(), 10000L); + JobExecution jobExecution = runJob("jsrSpringInstanceTests", new Properties(), 10000L); String exitStatus = jobExecution.getExitStatus(); assertTrue("Exit status must contain listener1", exitStatus.contains("listener1")); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JsrSplitParsingTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JsrSplitParsingTests.java index d04540ef2..b2d2af677 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JsrSplitParsingTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/JsrSplitParsingTests.java @@ -15,23 +15,11 @@ */ package org.springframework.batch.core.jsr.configuration.xml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.springframework.batch.core.jsr.JsrTestUtils.runJob; - -import java.util.List; - -import javax.batch.api.AbstractBatchlet; -import javax.batch.runtime.BatchRuntime; -import javax.batch.runtime.StepExecution; -import javax.batch.runtime.context.JobContext; -import javax.inject.Inject; - import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.springframework.batch.core.jsr.AbstractJsrTestCase; import org.springframework.beans.PropertyValue; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; @@ -39,7 +27,18 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.task.SimpleAsyncTaskExecutor; -public class JsrSplitParsingTests { +import javax.batch.api.AbstractBatchlet; +import javax.batch.runtime.BatchRuntime; +import javax.batch.runtime.StepExecution; +import javax.batch.runtime.context.JobContext; +import javax.inject.Inject; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class JsrSplitParsingTests extends AbstractJsrTestCase { @Rule public ExpectedException expectedException = ExpectedException.none(); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/PartitionParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/PartitionParserTests.java index c5ce44646..0833a46a1 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/PartitionParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/PartitionParserTests.java @@ -15,20 +15,10 @@ */ package org.springframework.batch.core.jsr.configuration.xml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.springframework.batch.core.jsr.JsrTestUtils.runJob; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Properties; -import java.util.Set; -import java.util.Vector; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import org.junit.Before; +import org.junit.Test; +import org.springframework.batch.core.jsr.AbstractJsrTestCase; +import org.springframework.util.Assert; import javax.batch.api.BatchProperty; import javax.batch.api.Batchlet; @@ -41,12 +31,21 @@ import javax.batch.runtime.JobExecution; import javax.batch.runtime.context.JobContext; import javax.batch.runtime.context.StepContext; import javax.inject.Inject; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; +import java.util.Vector; +import java.util.regex.Matcher; +import java.util.regex.Pattern; -import org.junit.Before; -import org.junit.Test; -import org.springframework.util.Assert; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -public class PartitionParserTests { +public class PartitionParserTests extends AbstractJsrTestCase { private Pattern caPattern = Pattern.compile("ca"); private Pattern asPattern = Pattern.compile("AS"); private static final long TIMEOUT = 10000L; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/ThreadLocalClassloaderBeanPostProcessorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/ThreadLocalClassloaderBeanPostProcessorTests.java index 2e8aa292f..462849b30 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/ThreadLocalClassloaderBeanPostProcessorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/configuration/xml/ThreadLocalClassloaderBeanPostProcessorTests.java @@ -15,15 +15,15 @@ */ package org.springframework.batch.core.jsr.configuration.xml; -import static org.junit.Assert.assertEquals; -import static org.springframework.batch.core.jsr.JsrTestUtils.runJob; +import org.junit.Test; +import org.springframework.batch.core.jsr.AbstractJsrTestCase; import javax.batch.runtime.BatchStatus; import javax.batch.runtime.JobExecution; -import org.junit.Test; +import static org.junit.Assert.assertEquals; -public class ThreadLocalClassloaderBeanPostProcessorTests { +public class ThreadLocalClassloaderBeanPostProcessorTests extends AbstractJsrTestCase { @Test public void test() throws Exception { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/job/flow/support/state/JsrEndStateTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/job/flow/support/state/JsrEndStateTests.java index 0d472220e..42f08a7fc 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/job/flow/support/state/JsrEndStateTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/job/flow/support/state/JsrEndStateTests.java @@ -15,26 +15,26 @@ */ package org.springframework.batch.core.jsr.job.flow.support.state; -import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.springframework.batch.core.jsr.AbstractJsrTestCase; import javax.batch.api.AbstractBatchlet; import javax.batch.runtime.BatchRuntime; import javax.batch.runtime.BatchStatus; import javax.batch.runtime.JobExecution; -import org.junit.Test; -import org.springframework.batch.core.jsr.JsrTestUtils; +import static org.junit.Assert.assertEquals; /** * Tests for the JSR-352 version of {@link JsrEndState} * * @author Michael Minella */ -public class JsrEndStateTests { +public class JsrEndStateTests extends AbstractJsrTestCase { @Test public void test() throws Exception { - JobExecution jobExecution = JsrTestUtils.runJob("jobWithEndTransition", null, 10000L); + JobExecution jobExecution = runJob("jobWithEndTransition", null, 10000L); assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus()); assertEquals("SUCCESS", jobExecution.getExitStatus()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/launch/JsrJobOperatorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/launch/JsrJobOperatorTests.java index 090ff5401..b61e9db83 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/launch/JsrJobOperatorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/launch/JsrJobOperatorTests.java @@ -28,6 +28,7 @@ import org.springframework.batch.core.converter.JobParametersConverter; import org.springframework.batch.core.converter.JobParametersConverterSupport; import org.springframework.batch.core.explore.JobExplorer; import org.springframework.batch.core.explore.support.SimpleJobExplorer; +import org.springframework.batch.core.jsr.AbstractJsrTestCase; import org.springframework.batch.core.jsr.JsrJobParametersConverter; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.step.JobRepositorySupport; @@ -60,10 +61,8 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.springframework.batch.core.jsr.JsrTestUtils.restartJob; -import static org.springframework.batch.core.jsr.JsrTestUtils.runJob; -public class JsrJobOperatorTests { +public class JsrJobOperatorTests extends AbstractJsrTestCase { private JobOperator jsrJobOperator; @Mock diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/partition/JsrPartitionHandlerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/partition/JsrPartitionHandlerTests.java index b7315365e..75edd840f 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/partition/JsrPartitionHandlerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/partition/JsrPartitionHandlerTests.java @@ -15,14 +15,20 @@ */ package org.springframework.batch.core.jsr.partition; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.io.Serializable; -import java.util.Collection; -import java.util.Properties; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; +import org.junit.Before; +import org.junit.Test; +import org.springframework.batch.core.ExitStatus; +import org.springframework.batch.core.JobExecution; +import org.springframework.batch.core.JobInstance; +import org.springframework.batch.core.JobInterruptedException; +import org.springframework.batch.core.StepExecution; +import org.springframework.batch.core.jsr.AbstractJsrTestCase; +import org.springframework.batch.core.jsr.configuration.support.BatchPropertyContext; +import org.springframework.batch.core.jsr.step.batchlet.BatchletSupport; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.step.JobRepositorySupport; +import org.springframework.batch.core.step.StepSupport; import javax.batch.api.BatchProperty; import javax.batch.api.partition.PartitionAnalyzer; @@ -33,23 +39,16 @@ import javax.batch.api.partition.PartitionPlanImpl; import javax.batch.api.partition.PartitionReducer; import javax.batch.runtime.BatchStatus; import javax.inject.Inject; +import java.io.Serializable; +import java.util.Collection; +import java.util.Properties; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; -import org.junit.Before; -import org.junit.Test; -import org.springframework.batch.core.ExitStatus; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobInstance; -import org.springframework.batch.core.JobInterruptedException; -import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.jsr.JsrTestUtils; -import org.springframework.batch.core.jsr.configuration.support.BatchPropertyContext; -import org.springframework.batch.core.jsr.step.batchlet.BatchletSupport; -import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; -import org.springframework.batch.core.step.JobRepositorySupport; -import org.springframework.batch.core.step.StepSupport; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; -public class JsrPartitionHandlerTests { +public class JsrPartitionHandlerTests extends AbstractJsrTestCase { private JsrPartitionHandler handler; private JobRepository repository = new JobRepositorySupport(); @@ -222,7 +221,7 @@ public class JsrPartitionHandlerTests { @Test public void testRestartNoOverride() throws Exception { - javax.batch.runtime.JobExecution execution1 = JsrTestUtils.runJob("jsrPartitionHandlerRestartWithOverrideJob", null, 1000000L); + javax.batch.runtime.JobExecution execution1 = runJob("jsrPartitionHandlerRestartWithOverrideJob", null, 1000000L); assertEquals(BatchStatus.FAILED, execution1.getBatchStatus()); assertEquals(1, MyPartitionReducer.beginCount); assertEquals(0, MyPartitionReducer.beforeCount); @@ -233,7 +232,7 @@ public class JsrPartitionHandlerTests { MyPartitionReducer.reset(); CountingPartitionCollector.reset(); - javax.batch.runtime.JobExecution execution2 = JsrTestUtils.restartJob(execution1.getExecutionId(), null, 1000000L); + javax.batch.runtime.JobExecution execution2 = restartJob(execution1.getExecutionId(), null, 1000000L); assertEquals(BatchStatus.COMPLETED, execution2.getBatchStatus()); assertEquals(1, MyPartitionReducer.beginCount); assertEquals(1, MyPartitionReducer.beforeCount); @@ -248,7 +247,7 @@ public class JsrPartitionHandlerTests { Properties jobParameters = new Properties(); jobParameters.put("mapper.override", "true"); - javax.batch.runtime.JobExecution execution1 = JsrTestUtils.runJob("jsrPartitionHandlerRestartWithOverrideJob", jobParameters, 1000000L); + javax.batch.runtime.JobExecution execution1 = runJob("jsrPartitionHandlerRestartWithOverrideJob", jobParameters, 1000000L); assertEquals(BatchStatus.FAILED, execution1.getBatchStatus()); assertEquals(1, MyPartitionReducer.beginCount); assertEquals(0, MyPartitionReducer.beforeCount); @@ -259,7 +258,7 @@ public class JsrPartitionHandlerTests { MyPartitionReducer.reset(); CountingPartitionCollector.reset(); - javax.batch.runtime.JobExecution execution2 = JsrTestUtils.restartJob(execution1.getExecutionId(), jobParameters, 1000000L); + javax.batch.runtime.JobExecution execution2 = restartJob(execution1.getExecutionId(), jobParameters, 1000000L); assertEquals(BatchStatus.COMPLETED, execution2.getBatchStatus()); assertEquals(1, MyPartitionReducer.beginCount); assertEquals(1, MyPartitionReducer.beforeCount); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/DecisionStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/DecisionStepTests.java index 5742c9e24..76823fa63 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/DecisionStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/DecisionStepTests.java @@ -15,22 +15,10 @@ */ package org.springframework.batch.core.jsr.step; -import static org.junit.Assert.assertEquals; -import static org.springframework.batch.core.jsr.JsrTestUtils.restartJob; -import static org.springframework.batch.core.jsr.JsrTestUtils.runJob; - -import java.util.List; -import java.util.Properties; - -import javax.batch.api.Decider; -import javax.batch.runtime.BatchRuntime; -import javax.batch.runtime.BatchStatus; -import javax.batch.runtime.JobExecution; -import javax.batch.runtime.StepExecution; - import org.junit.Before; import org.junit.Test; import org.springframework.batch.core.explore.JobExplorer; +import org.springframework.batch.core.jsr.AbstractJsrTestCase; import org.springframework.beans.factory.access.BeanFactoryLocator; import org.springframework.beans.factory.access.BeanFactoryReference; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; @@ -38,7 +26,17 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.access.ContextSingletonBeanFactoryLocator; import org.springframework.util.Assert; -public class DecisionStepTests { +import javax.batch.api.Decider; +import javax.batch.runtime.BatchRuntime; +import javax.batch.runtime.BatchStatus; +import javax.batch.runtime.JobExecution; +import javax.batch.runtime.StepExecution; +import java.util.List; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; + +public class DecisionStepTests extends AbstractJsrTestCase { private static ApplicationContext baseContext; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JsrTestUtils.java b/spring-batch-test/src/main/java/org/springframework/batch/test/JsrTestUtils.java similarity index 93% rename from spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JsrTestUtils.java rename to spring-batch-test/src/main/java/org/springframework/batch/test/JsrTestUtils.java index 038db1eff..4b5749155 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JsrTestUtils.java +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/JsrTestUtils.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.batch.core.jsr; +package org.springframework.batch.test; import javax.batch.operations.JobOperator; import javax.batch.runtime.BatchRuntime; @@ -45,14 +45,14 @@ public class JsrTestUtils { /** * Executes a job and waits for it's status to be any of {@link BatchStatus#STOPPED}, * {@link BatchStatus#COMPLETED}, or {@link BatchStatus#FAILED}. If the job does not - * reach one of those statuses within the given timeout, a {@link TimeoutException} is + * reach one of those statuses within the given timeout, a {@link java.util.concurrent.TimeoutException} is * thrown. * * @param jobName * @param properties * @param timeout * @return the {@link JobExecution} for the final state of the job - * @throws TimeoutException if the timeout occurs + * @throws java.util.concurrent.TimeoutException if the timeout occurs */ public static JobExecution runJob(String jobName, Properties properties, long timeout) throws TimeoutException{ long executionId = operator.start(jobName, properties); @@ -79,14 +79,14 @@ public class JsrTestUtils { /** * Restarts a job and waits for it's status to be any of {@link BatchStatus#STOPPED}, * {@link BatchStatus#COMPLETED}, or {@link BatchStatus#FAILED}. If the job does not - * reach one of those statuses within the given timeout, a {@link TimeoutException} is + * reach one of those statuses within the given timeout, a {@link java.util.concurrent.TimeoutException} is * thrown. * * @param executionId * @param properties * @param timeout * @return the {@link JobExecution} for the final state of the job - * @throws TimeoutException if the timeout occurs + * @throws java.util.concurrent.TimeoutException if the timeout occurs */ public static JobExecution restartJob(long executionId, Properties properties, long timeout) throws TimeoutException { long restartId = operator.restart(executionId, properties);