|
| 1 | +package org.javaee7.batch.decision; |
| 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.*; |
| 23 | + |
| 24 | +/** |
| 25 | + * @author Roberto Cortez |
| 26 | + */ |
| 27 | +@RunWith(Arquillian.class) |
| 28 | +public class BatchDecisionTest { |
| 29 | + @Deployment |
| 30 | + public static WebArchive createDeployment() { |
| 31 | + WebArchive war = ShrinkWrap.create(WebArchive.class) |
| 32 | + .addClass(BatchTestHelper.class) |
| 33 | + .addPackage("org.javaee7.batch.decision") |
| 34 | + .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")) |
| 35 | + .addAsResource("META-INF/batch-jobs/myJob.xml"); |
| 36 | + System.out.println(war.toString(true)); |
| 37 | + return war; |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testBatchDecision() throws Exception { |
| 42 | + JobOperator jobOperator = BatchRuntime.getJobOperator(); |
| 43 | + Long executionId = jobOperator.start("myJob", new Properties()); |
| 44 | + JobExecution jobExecution = jobOperator.getJobExecution(executionId); |
| 45 | + |
| 46 | + BatchTestHelper.keepTestAlive(jobExecution); |
| 47 | + |
| 48 | + List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId); |
| 49 | + List<String> executedSteps = new ArrayList<>(); |
| 50 | + for (StepExecution stepExecution : stepExecutions) { |
| 51 | + executedSteps.add(stepExecution.getStepName()); |
| 52 | + } |
| 53 | + |
| 54 | + assertEquals(2, stepExecutions.size()); |
| 55 | + assertArrayEquals(new String[] {"step1", "step3"}, executedSteps.toArray()); |
| 56 | + assertFalse(executedSteps.contains("step2")); |
| 57 | + assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus()); |
| 58 | + } |
| 59 | +} |
0 commit comments