77import org .jboss .shrinkwrap .api .ShrinkWrap ;
88import org .jboss .shrinkwrap .api .asset .EmptyAsset ;
99import org .jboss .shrinkwrap .api .spec .WebArchive ;
10- import org .junit .Assert ;
1110import org .junit .Test ;
1211import org .junit .runner .RunWith ;
1312
1716import javax .batch .runtime .JobExecution ;
1817import java .util .Properties ;
1918
19+ import static org .junit .Assert .assertEquals ;
20+
2021/**
22+ * Batchlet is the simplest processing style available in the Batch specification. It's a task oriented step where the
23+ * task is invoked once, executes, and returns an exit status.
24+ *
25+ * A Batchlet need to implement +javax.batch.api.Batchlet+ interface or in alternative extend
26+ * +javax.batch.api.AbstractBatchlet+ that already provides empty implementations for all methods.
27+ *
28+ * include::MyBatchlet[]
29+ *
30+ * We are mostly interested in overriding +javax.batch.api.AbstractBatchlet#process+ to provide the behaviour that we
31+ * want to achieve with the Batchlet itself. Common cases include: copy files to process with a chunk oriented step,
32+ * startup and cleanup, or validations to your processing workflow.
33+ *
34+ * To run your Batchlet, just add it to the job xml file (+myjob.xml+).
35+ *
2136 * @author Roberto Cortez
2237 */
2338@ RunWith (Arquillian .class )
2439public class MyBatchletTest {
40+ /**
41+ * We're just going to deploy the application as a +web archive+. Note the inclusion of the following files:
42+ *
43+ * [source,file]
44+ * ----
45+ * /META-INF/batch-jobs/myjob.xml
46+ * ----
47+ *
48+ * The +myjob.xml+ file is needed for running the batch definition.
49+ */
2550 @ Deployment
2651 public static WebArchive createDeployment () {
2752 WebArchive war = ShrinkWrap .create (WebArchive .class )
@@ -33,6 +58,13 @@ public static WebArchive createDeployment() {
3358 return war ;
3459 }
3560
61+ /**
62+ * In the test, we're just going to invoke the batch execution and wait for completion. To validate the test
63+ * expected behaviour we just need to check the Batch Status in the +JbExecution+ object. We should get a
64+ * +BatchStatus.COMPLETED+.
65+ *
66+ * @throws Exception an exception if the batch could not complete successfully.
67+ */
3668 @ Test
3769 public void testBatchletProcess () throws Exception {
3870 JobOperator jobOperator = BatchRuntime .getJobOperator ();
@@ -41,6 +73,6 @@ public void testBatchletProcess() throws Exception {
4173
4274 BatchTestHelper .keepTestAlive (jobExecution );
4375
44- Assert . assertEquals (jobExecution .getBatchStatus (), BatchStatus .COMPLETED );
76+ assertEquals (jobExecution .getBatchStatus (), BatchStatus .COMPLETED );
4577 }
4678}
0 commit comments