|
| 1 | +package org.javaee7.batch.split; |
| 2 | + |
| 3 | +import org.javaee7.util.BatchTestHelper; |
| 4 | +import org.jboss.arquillian.container.test.api.Deployment; |
| 5 | +import org.jboss.arquillian.junit.Arquillian; |
| 6 | +import org.jboss.shrinkwrap.api.ArchivePaths; |
| 7 | +import org.jboss.shrinkwrap.api.ShrinkWrap; |
| 8 | +import org.jboss.shrinkwrap.api.asset.EmptyAsset; |
| 9 | +import org.jboss.shrinkwrap.api.spec.WebArchive; |
| 10 | +import org.junit.Test; |
| 11 | +import org.junit.runner.RunWith; |
| 12 | + |
| 13 | +import javax.batch.operations.JobOperator; |
| 14 | +import javax.batch.runtime.BatchRuntime; |
| 15 | +import javax.batch.runtime.BatchStatus; |
| 16 | +import javax.batch.runtime.JobExecution; |
| 17 | +import javax.batch.runtime.StepExecution; |
| 18 | +import java.util.ArrayList; |
| 19 | +import java.util.List; |
| 20 | +import java.util.Properties; |
| 21 | + |
| 22 | +import static org.junit.Assert.assertEquals; |
| 23 | +import static org.junit.Assert.assertTrue; |
| 24 | + |
| 25 | +/** |
| 26 | + * @author Roberto Cortez |
| 27 | + */ |
| 28 | +@RunWith(Arquillian.class) |
| 29 | +public class BatchSplitTest { |
| 30 | + @Deployment |
| 31 | + public static WebArchive createDeployment() { |
| 32 | + WebArchive war = ShrinkWrap.create(WebArchive.class) |
| 33 | + .addClass(BatchTestHelper.class) |
| 34 | + .addPackage("org.javaee7.batch.split") |
| 35 | + .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")) |
| 36 | + .addAsResource("META-INF/batch-jobs/myJob.xml"); |
| 37 | + System.out.println(war.toString(true)); |
| 38 | + return war; |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testBatchSplit() throws Exception { |
| 43 | + JobOperator jobOperator = BatchRuntime.getJobOperator(); |
| 44 | + Long executionId = jobOperator.start("myJob", new Properties()); |
| 45 | + JobExecution jobExecution = jobOperator.getJobExecution(executionId); |
| 46 | + |
| 47 | + BatchTestHelper.keepTestAlive(jobExecution); |
| 48 | + |
| 49 | + List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId); |
| 50 | + List<String> executedSteps = new ArrayList<>(); |
| 51 | + for (StepExecution stepExecution : stepExecutions) { |
| 52 | + executedSteps.add(stepExecution.getStepName()); |
| 53 | + } |
| 54 | + |
| 55 | + assertEquals(3, stepExecutions.size()); |
| 56 | + assertTrue(executedSteps.contains("step1")); |
| 57 | + assertTrue(executedSteps.contains("step2")); |
| 58 | + assertTrue(executedSteps.contains("step3")); |
| 59 | + assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus()); |
| 60 | + } |
| 61 | +} |
0 commit comments