Skip to content

Commit 44cae22

Browse files
committed
Added test for chunk-optional-processor project.
1 parent 1efc18b commit 44cae22

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

batch/chunk-optional-processor/pom.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
<version>1.0-SNAPSHOT</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
10-
11-
<groupId>org.javaee7.batch</groupId>
10+
1211
<artifactId>chunk-optional-processor</artifactId>
13-
<version>1.0-SNAPSHOT</version>
1412
<packaging>war</packaging>
1513

1614
<name>${project.artifactId}</name>
1715

16+
<dependencies>
17+
<dependency>
18+
<groupId>org.javaee7</groupId>
19+
<artifactId>util-samples</artifactId>
20+
</dependency>
21+
</dependencies>
1822
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.javaee7.batch.chunk.optional.processor;
2+
3+
import org.javaee7.util.BatchTestHelper;
4+
import org.jboss.arquillian.container.test.api.Deployment;
5+
import org.jboss.arquillian.junit.Arquillian;
6+
import org.jboss.shrinkwrap.api.ArchivePaths;
7+
import org.jboss.shrinkwrap.api.ShrinkWrap;
8+
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
9+
import org.jboss.shrinkwrap.api.spec.WebArchive;
10+
import org.junit.Assert;
11+
import org.junit.Test;
12+
import org.junit.runner.RunWith;
13+
14+
import javax.batch.operations.JobOperator;
15+
import javax.batch.runtime.*;
16+
import java.util.List;
17+
import java.util.Map;
18+
import java.util.Properties;
19+
20+
import static org.junit.Assert.assertEquals;
21+
22+
/**
23+
* @author Roberto Cortez
24+
*/
25+
@RunWith(Arquillian.class)
26+
public class BatchChunkOptionalProcessorTest {
27+
@Deployment
28+
public static WebArchive createDeployment() {
29+
WebArchive war = ShrinkWrap.create(WebArchive.class)
30+
.addClass(BatchTestHelper.class)
31+
.addPackage("org.javaee7.batch.chunk.optional.processor")
32+
.addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"))
33+
.addAsResource("META-INF/batch-jobs/myJob.xml");
34+
System.out.println(war.toString(true));
35+
return war;
36+
}
37+
38+
@Test
39+
public void testBatchChunkMapper() throws Exception {
40+
JobOperator jobOperator = BatchRuntime.getJobOperator();
41+
Long executionId = jobOperator.start("myJob", new Properties());
42+
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
43+
44+
BatchTestHelper.keepTestAlive(jobExecution);
45+
46+
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
47+
for (StepExecution stepExecution : stepExecutions) {
48+
if (stepExecution.getStepName().equals("myStep")) {
49+
Map<Metric.MetricType, Long> metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics());
50+
Assert.assertEquals(10L, metricsMap.get(Metric.MetricType.READ_COUNT).longValue());
51+
Assert.assertEquals(10L, metricsMap.get(Metric.MetricType.WRITE_COUNT).longValue());
52+
Assert.assertEquals(10L/3 + 10%3, metricsMap.get(Metric.MetricType.COMMIT_COUNT).longValue());
53+
}
54+
}
55+
56+
assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
57+
}
58+
}

0 commit comments

Comments
 (0)