Skip to content

Commit 6c724a5

Browse files
committed
Added test for chunk-csv-database project.
Needs wildfly 8.0.0.CR1, because of https://issues.jboss.org/browse/WFLY-2027.
1 parent dd3b379 commit 6c724a5

File tree

5 files changed

+86
-5
lines changed

5 files changed

+86
-5
lines changed

batch/chunk-csv-database/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

12-
<groupId>org.javaee7.batch</groupId>
1312
<artifactId>chunk-csv-database</artifactId>
14-
<version>1.0-SNAPSHOT</version>
1513
<packaging>war</packaging>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.javaee7</groupId>
18+
<artifactId>util-samples</artifactId>
19+
</dependency>
20+
</dependencies>
1621
</project>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
CREATE TABLE CHUNK_CSV_DATABASE ("ID" INTEGER not null primary key, "NAME" VARCHAR(50) not null primary key, "HIREDATE" VARCHAR(50) not null)
1+
CREATE SEQUENCE HIBERNATE_SEQUENCE
2+
CREATE TABLE CHUNK_CSV_DATABASE ("ID" INTEGER not null primary key, "NAME" VARCHAR(50) not null, "HIREDATE" VARCHAR(50) not null)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
DROP TABLE CHUNK_CSV_DATABASE
1+
DROP TABLE CHUNK_CSV_DATABASE
2+
DROP SEQUENCE HIBERNATE_SEQUENCE

batch/chunk-csv-database/src/main/resources/META-INF/mydata.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Penny, 12/1/12
2-
Leonard Hofstadter, 14/6/08
2+
Leonard Hofstadter, 12/6/08
33
Howard Wolowitz, 8/27/7
44
Bernadette Rostenkowski-Wolowitz, 8/14/13
55
Sheldon Cooper, 3/18/9
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package org.javaee7.batch.chunk.csv.database;
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.Test;
11+
import org.junit.runner.RunWith;
12+
13+
import javax.batch.operations.JobOperator;
14+
import javax.batch.runtime.*;
15+
import javax.persistence.EntityManager;
16+
import javax.persistence.PersistenceContext;
17+
import javax.persistence.Query;
18+
import java.util.List;
19+
import java.util.Map;
20+
import java.util.Properties;
21+
22+
import static org.junit.Assert.assertEquals;
23+
24+
/**
25+
* @author Roberto Cortez
26+
*/
27+
@RunWith(Arquillian.class)
28+
public class BatchCSVDatabaseTest {
29+
@PersistenceContext
30+
private EntityManager entityManager;
31+
32+
@Deployment
33+
public static WebArchive createDeployment() {
34+
WebArchive war = ShrinkWrap.create(WebArchive.class)
35+
.addClass(BatchTestHelper.class)
36+
.addPackage("org.javaee7.batch.chunk.csv.database")
37+
.addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"))
38+
.addAsResource("META-INF/batch-jobs/myJob.xml")
39+
.addAsResource("META-INF/persistence.xml")
40+
.addAsResource("META-INF/create.sql")
41+
.addAsResource("META-INF/drop.sql")
42+
.addAsResource("META-INF/mydata.csv");
43+
System.out.println(war.toString(true));
44+
return war;
45+
}
46+
47+
@Test
48+
public void testBatchCSVDatabase() throws Exception {
49+
JobOperator jobOperator = BatchRuntime.getJobOperator();
50+
Long executionId = jobOperator.start("myJob", new Properties());
51+
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
52+
53+
BatchTestHelper.keepTestAlive(jobExecution);
54+
55+
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
56+
for (StepExecution stepExecution : stepExecutions) {
57+
if (stepExecution.getStepName().equals("myStep")) {
58+
Map<Metric.MetricType, Long> metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics());
59+
System.out.println(metricsMap);
60+
61+
assertEquals(7L, (long) metricsMap.get(Metric.MetricType.READ_COUNT));
62+
assertEquals(7L, (long) metricsMap.get(Metric.MetricType.WRITE_COUNT));
63+
assertEquals(3L, (long) metricsMap.get(Metric.MetricType.COMMIT_COUNT));
64+
}
65+
}
66+
67+
Query query = entityManager.createQuery("SELECT p FROM Person p");
68+
@SuppressWarnings("unchecked")
69+
List<Person> persons = query.getResultList();
70+
71+
assertEquals(7L, persons.size());
72+
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
73+
}
74+
}

0 commit comments

Comments
 (0)