Skip to content

Commit bb39a59

Browse files
committed
Merge pull request #229 from radcortez/master
Documentation to decision and flow projects
2 parents e546d6c + c78023d commit bb39a59

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
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
}

batch/flow/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
<artifactId>flow</artifactId>
1313
<packaging>war</packaging>
14-
15-
<name>${project.artifactId}</name>
14+
<name>Batch Flow</name>
15+
<description>Batch DSL - Flow</description>
1616

1717
<dependencies>
1818
<dependency>

batch/flow/src/test/java/org/javaee7/batch/flow/BatchFlowTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,30 @@
2121
import static org.junit.Assert.assertEquals;
2222

2323
/**
24+
* The Batch specification allows you to implement process workflows using a Job Specification Language (JSL). In this
25+
* sample, by using the +flow+ element, we define a sequence of elements that execute together as a unit. When the
26+
* flow is finished the flow transitions to the next execution element. The execution elements of a flow cannot
27+
* transition to elements outside the flow.
28+
*
29+
* include::myJob.xml[]
30+
*
31+
* The flow element is usefull to build self contained workflows that you can reference and build as a part of a bigger
32+
* workflow.
33+
*
2434
* @author Roberto Cortez
2535
*/
2636
@RunWith(Arquillian.class)
2737
public class BatchFlowTest {
38+
/**
39+
* We're just going to deploy the application as a +web archive+. Note the inclusion of the following files:
40+
*
41+
* [source,file]
42+
* ----
43+
* /META-INF/batch-jobs/myJob.xml
44+
* ----
45+
*
46+
* The +myJob.xml+ file is needed for running the batch definition.
47+
*/
2848
@Deployment
2949
public static WebArchive createDeployment() {
3050
WebArchive war = ShrinkWrap.create(WebArchive.class)
@@ -36,6 +56,13 @@ public static WebArchive createDeployment() {
3656
return war;
3757
}
3858

59+
/**
60+
* In the test, we're just going to invoke the batch execution and wait for completion. To validate the test
61+
* expected behaviour we need to query +JobOperator#getStepExecutions+ and the +Metric[]+ object available in the
62+
* step execution.
63+
*
64+
* @throws Exception an exception if the batch could not complete successfully.
65+
*/
3966
@Test
4067
public void testBatchFlow() throws Exception {
4168
JobOperator jobOperator = BatchRuntime.getJobOperator();
@@ -58,8 +85,11 @@ public void testBatchFlow() throws Exception {
5885
}
5986
}
6087

88+
// <1> Make sure all the steps were executed.
6189
assertEquals(3, stepExecutions.size());
90+
// <2> Make sure all the steps were executed in order of declaration.
6291
assertArrayEquals(new String[]{"step1", "step2", "step3"}, executedSteps.toArray());
92+
// <3> Job should be completed.
6393
assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
6494
}
6595
}

0 commit comments

Comments
 (0)