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 +step+ element, it's possible to configure a job that runs multiple steps.
26+ *
27+ * One Chunk oriented Step and a Batchlet are configured in the file +myJob.xml+. They both execute in order of
28+ * declaration. First the Chunk oriented Step and finally the Batchlet Step.
29+ *
2430 * @author Roberto Cortez
2531 */
2632@ RunWith (Arquillian .class )
2733public class BatchMultipleStepsTest {
34+ /**
35+ * We're just going to deploy the application as a +web archive+. Note the inclusion of the following files:
36+ *
37+ * [source,file]
38+ * ----
39+ * /META-INF/batch-jobs/myjob.xml
40+ * ----
41+ *
42+ * The +myjob.xml+ file is needed for running the batch definition.
43+ */
2844 @ Deployment
2945 public static WebArchive createDeployment () {
3046 WebArchive war = ShrinkWrap .create (WebArchive .class )
@@ -36,6 +52,13 @@ public static WebArchive createDeployment() {
3652 return war ;
3753 }
3854
55+ /**
56+ * In the test, we're just going to invoke the batch execution and wait for completion. To validate the test
57+ * expected behaviour we need to query +JobOperator#getStepExecutions+ and the +Metric[]+ object available in the
58+ * step execution.
59+ *
60+ * @throws Exception an exception if the batch could not complete successfully.
61+ */
3962 @ Test
4063 public void testBatchMultipleSteps () throws Exception {
4164 JobOperator jobOperator = BatchRuntime .getJobOperator ();
@@ -51,14 +74,17 @@ public void testBatchMultipleSteps() throws Exception {
5174
5275 if (stepExecution .getStepName ().equals ("step1" )) {
5376 Map <Metric .MetricType , Long > metricsMap = BatchTestHelper .getMetricsMap (stepExecution .getMetrics ());
54- System .out .println (metricsMap );
5577 assertEquals (10L , metricsMap .get (Metric .MetricType .READ_COUNT ).longValue ());
5678 assertEquals (10L / 2 , metricsMap .get (Metric .MetricType .WRITE_COUNT ).longValue ());
5779 assertEquals (10L / 3 + (10L % 3 > 0 ? 1 : 0 ), metricsMap .get (Metric .MetricType .COMMIT_COUNT ).longValue ());
5880 }
5981 }
82+
83+ // <1> Make sure all the steps were executed.
6084 assertEquals (2 , stepExecutions .size ());
85+ // <2> Make sure all the steps were executed in order of declaration.
6186 assertArrayEquals (new String []{"step1" , "step2" }, executedSteps .toArray ());
87+ // <3> Job should be completed.
6288 assertEquals (BatchStatus .COMPLETED , jobExecution .getBatchStatus ());
6389 }
6490}
0 commit comments