Skip to content

Commit 2d82c99

Browse files
committed
Added documentation to decision project.
1 parent e546d6c commit 2d82c99

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

batch/decision/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
<artifactId>decision</artifactId>
1212
<packaging>war</packaging>
13+
<name>Batch Decision</name>
14+
<description>Batch DSL - Decision</description>
1315

14-
<name>${project.artifactId}</name>
1516

1617
<dependencies>
1718
<dependency>

batch/decision/src/test/java/org/javaee7/batch/decision/BatchDecisionTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,33 @@
2222
import static org.junit.Assert.*;
2323

2424
/**
25+
* The Batch specification allows you to implement process workflows using a Job Specification Language (JSL). In this
26+
* sample, by using the +decision+ element, it's possible to configure a job that follows different paths of execution
27+
* based on your own criteria by implementing a +javax.batch.api.Decider+
28+
*
29+
* The +javax.batch.api.Decider+ just needs to return a meaningful value, to use in the +myJob.xml+ file to be able to
30+
* reference the next step that must be executed.
31+
*
32+
* include::myJob.xml[]
33+
*
34+
* Three Steps and one Decider are configured in the file +myJob.xml+. We start by executing one +step1+ and
35+
* hand over the control to the Decider, which will execute +step2+, since the Decider is always returning the value
36+
* +foobar+ which forwards the execution to +step2+.
37+
*
2538
* @author Roberto Cortez
2639
*/
2740
@RunWith(Arquillian.class)
2841
public class BatchDecisionTest {
42+
/**
43+
* We're just going to deploy the application as a +web archive+. Note the inclusion of the following files:
44+
*
45+
* [source,file]
46+
* ----
47+
* /META-INF/batch-jobs/myJob.xml
48+
* ----
49+
*
50+
* The +myJob.xml+ file is needed for running the batch definition.
51+
*/
2952
@Deployment
3053
public static WebArchive createDeployment() {
3154
WebArchive war = ShrinkWrap.create(WebArchive.class)
@@ -37,6 +60,13 @@ public static WebArchive createDeployment() {
3760
return war;
3861
}
3962

63+
/**
64+
* In the test, we're just going to invoke the batch execution and wait for completion. To validate the test
65+
* expected behaviour we need to query +JobOperator#getStepExecutions+ and the +Metric[]+ object available in the
66+
* step execution.
67+
*
68+
* @throws Exception an exception if the batch could not complete successfully.
69+
*/
4070
@Test
4171
public void testBatchDecision() throws Exception {
4272
JobOperator jobOperator = BatchRuntime.getJobOperator();
@@ -51,9 +81,13 @@ public void testBatchDecision() throws Exception {
5181
executedSteps.add(stepExecution.getStepName());
5282
}
5383

84+
// <1> Make sure that only two steps were executed.
5485
assertEquals(2, stepExecutions.size());
86+
// <2> Make sure that only the expected steps were executed an in order.
5587
assertArrayEquals(new String[] {"step1", "step3"}, executedSteps.toArray());
88+
// <3> Make sure that this step was never executed.
5689
assertFalse(executedSteps.contains("step2"));
90+
// <3> Job should be completed.
5791
assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
5892
}
5993
}

0 commit comments

Comments
 (0)