2121import 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 )
2737public 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