Skip to content

Commit 2993c8f

Browse files
committed
Added documentation to batchlet-simple project.
1 parent 2b287cf commit 2993c8f

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

batch/batchlet-simple/pom.xml

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

1212
<artifactId>batchlet-simple</artifactId>
1313
<packaging>war</packaging>
14+
<name>Batchlet Simple</name>
15+
<description>Batchlet Simple - Execute a task oriented step</description>
1416

1517
<dependencies>
1618
<dependency>

batch/batchlet-simple/src/main/java/org/javaee7/batch/batchlet/simple/MyBatchlet.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,21 @@
3737
* only if the new code is made subject to such option by the copyright
3838
* holder.
3939
*/
40-
4140
package org.javaee7.batch.batchlet.simple;
4241

4342
import javax.batch.api.AbstractBatchlet;
43+
import javax.batch.runtime.BatchStatus;
4444
import javax.inject.Named;
4545

4646
/**
4747
* @author Arun Gupta
4848
*/
4949
@Named
5050
public class MyBatchlet extends AbstractBatchlet {
51-
5251
@Override
5352
public String process() {
5453
System.out.println("Running inside a batchlet");
55-
56-
return "COMPLETED";
57-
}
5854

55+
return BatchStatus.COMPLETED.toString();
56+
}
5957
}

batch/batchlet-simple/src/test/java/org/javaee7/batch/batchlet/simple/MyBatchletTest.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.jboss.shrinkwrap.api.ShrinkWrap;
88
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
99
import org.jboss.shrinkwrap.api.spec.WebArchive;
10-
import org.junit.Assert;
1110
import org.junit.Test;
1211
import org.junit.runner.RunWith;
1312

@@ -17,11 +16,37 @@
1716
import javax.batch.runtime.JobExecution;
1817
import 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)
2439
public 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

Comments
 (0)