Skip to content

Commit 459846b

Browse files
committed
Merge pull request javaee-samples#175 from radcortez/master
More tests for batch and upgrade to Wildfly CR1
2 parents 93516fd + cd6f856 commit 459846b

File tree

22 files changed

+111
-38
lines changed

22 files changed

+111
-38
lines changed

batch/chunk-csv-database/pom.xml

+7-2
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>

batch/chunk-csv-database/src/main/java/org/javaee7/batch/chunk/csv/database/MyItemProcessor.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
*/
5151
@Named
5252
public class MyItemProcessor implements ItemProcessor {
53-
SimpleDateFormat format = new SimpleDateFormat("M/dd/yy");
53+
private static int id = 1;
54+
private SimpleDateFormat format = new SimpleDateFormat("M/dd/yy");
5455

5556
@Override
5657
public Person processItem(Object t) {
@@ -69,6 +70,6 @@ public Person processItem(Object t) {
6970
return null;
7071
}
7172

72-
return new Person(name, date);
73+
return new Person(id++, name, date);
7374
}
7475
}

batch/chunk-csv-database/src/main/java/org/javaee7/batch/chunk/csv/database/Person.java

+10-16
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,11 @@
3939
*/
4040
package org.javaee7.batch.chunk.csv.database;
4141

42-
import java.io.Serializable;
43-
import javax.persistence.Basic;
44-
import javax.persistence.Column;
45-
import javax.persistence.Entity;
46-
import javax.persistence.GeneratedValue;
47-
import javax.persistence.GenerationType;
48-
import javax.persistence.Id;
49-
import javax.persistence.NamedQueries;
50-
import javax.persistence.NamedQuery;
51-
import javax.persistence.Table;
42+
import javax.persistence.*;
5243
import javax.validation.constraints.NotNull;
5344
import javax.validation.constraints.Size;
5445
import javax.xml.bind.annotation.XmlRootElement;
46+
import java.io.Serializable;
5547

5648
/**
5749
* @author Arun Gupta
@@ -66,7 +58,6 @@
6658
public class Person implements Serializable {
6759

6860
@Id
69-
@GeneratedValue(strategy = GenerationType.AUTO)
7061
private int id;
7162

7263
private static final long serialVersionUID = 1L;
@@ -94,6 +85,12 @@ public Person(String name, String hiredate) {
9485
this.hiredate = hiredate;
9586
}
9687

88+
public Person(int id, String name, String hiredate) {
89+
this.id = id;
90+
this.name = name;
91+
this.hiredate = hiredate;
92+
}
93+
9794
public int getId() {
9895
return id;
9996
}
@@ -132,15 +129,12 @@ public boolean equals(Object object) {
132129
return false;
133130
}
134131
Person other = (Person) object;
135-
if ((this.name == null && other.name != null) || (this.name != null && !this.name.equals(other.name))) {
136-
return false;
137-
}
138-
return true;
132+
return !((this.name == null && other.name != null) || (this.name != null && !this.name.equals(other.name)));
139133
}
140134

141135
@Override
142136
public String toString() {
143-
return name;
137+
return name + id;
144138
}
145139

146140
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
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 TABLE CHUNK_CSV_DATABASE ("ID" INTEGER not null primary key, "NAME" VARCHAR(50) not null, "HIREDATE" VARCHAR(50) not null)

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

+1-1
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
60+
assertEquals(7L, (long) metricsMap.get(Metric.MetricType.READ_COUNT));
61+
assertEquals(7L, (long) metricsMap.get(Metric.MetricType.WRITE_COUNT));
62+
assertEquals(3L, (long) metricsMap.get(Metric.MetricType.COMMIT_COUNT));
63+
}
64+
}
65+
66+
Query query = entityManager.createNamedQuery("Person.findAll");
67+
@SuppressWarnings("unchecked")
68+
List<Person> persons = query.getResultList();
69+
70+
assertEquals(7L, persons.size());
71+
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
72+
}
73+
}

cdi/alternatives/src/test/resources/arquillian.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<container qualifier="test" default="true">
88
<configuration>
9-
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.Beta1}</property>
9+
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.CR1}</property>
1010
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
1111
</configuration>
1212
</container>

cdi/bean-discovery-all/src/test/resources/arquillian.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<container qualifier="test" default="true">
88
<configuration>
9-
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.Beta1}</property>
9+
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.CR1}</property>
1010
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
1111
</configuration>
1212
</container>

cdi/bean-discovery-annotated/src/test/resources/arquillian.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<container qualifier="test" default="true">
88
<configuration>
9-
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.Beta1}</property>
9+
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.CR1}</property>
1010
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
1111
</configuration>
1212
</container>

cdi/bean-discovery-none/src/test/resources/arquillian.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<container qualifier="test" default="true">
88
<configuration>
9-
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.Beta1}</property>
9+
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.CR1}</property>
1010
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
1111
</configuration>
1212
</container>

cdi/beansxml-noversion/src/test/resources/arquillian.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<container qualifier="test" default="true">
88
<configuration>
9-
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.Beta1}</property>
9+
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.CR1}</property>
1010
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
1111
</configuration>
1212
</container>

cdi/nobeans-xml/src/test/resources/arquillian.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<container qualifier="test" default="true">
88
<configuration>
9-
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.Beta1}</property>
9+
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.CR1}</property>
1010
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
1111
</configuration>
1212
</container>

concurrency/managedexecutor/src/test/resources/arquillian.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<container qualifier="test" default="true">
88
<configuration>
9-
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.Beta1}</property>
9+
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.CR1}</property>
1010
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
1111
</configuration>
1212
</container>

el/standalone/src/test/resources/arquillian.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<container qualifier="test" default="true">
88
<configuration>
9-
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.Beta1}</property>
9+
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.CR1}</property>
1010
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
1111
</configuration>
1212
</container>

extra/nosql/hibernate-ogm/src/test/resources/arquillian.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<container qualifier="test" default="true">
88
<configuration>
9-
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.Beta1}</property>
9+
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.CR1}</property>
1010
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
1111
</configuration>
1212
</container>

jaxrs/jaxrs-endpoint/src/test/resources/arquillian.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<container qualifier="test" default="true">
88
<configuration>
9-
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.Beta1}</property>
9+
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.CR1}</property>
1010
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
1111
</configuration>
1212
</container>

jpa/datasourcedefinition/src/test/resources/arquillian.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<container qualifier="test" default="true">
88
<configuration>
9-
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.Beta1}</property>
9+
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.CR1}</property>
1010
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
1111
</configuration>
1212
</container>

json/object-builder/src/test/resources/arquillian.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<container qualifier="test" default="true">
88
<configuration>
9-
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.Beta1}</property>
9+
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.CR1}</property>
1010
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
1111
</configuration>
1212
</container>

jta/transactional/src/test/resources/arquillian.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<container qualifier="test" default="true">
88
<configuration>
9-
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.Beta1}</property>
9+
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.CR1}</property>
1010
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
1111
</configuration>
1212
</container>

jta/tx-exception/src/test/resources/arquillian.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<container qualifier="test" default="true">
88
<configuration>
9-
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.Beta1}</property>
9+
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.CR1}</property>
1010
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
1111
</configuration>
1212
</container>

jta/user-transaction/src/test/resources/arquillian.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<container qualifier="test" default="true">
88
<configuration>
9-
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.Beta1}</property>
9+
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.CR1}</property>
1010
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
1111
</configuration>
1212
</container>

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<maven.min.version>3.0.0</maven.min.version>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
<org.jboss.arquillian.version>1.1.1.Final</org.jboss.arquillian.version>
16-
<org.wildfly>8.0.0.Beta1</org.wildfly>
16+
<org.wildfly>8.0.0.CR1</org.wildfly>
1717
<!-- Plugin versions -->
1818
<plugin.enforcer.version>1.3.1</plugin.enforcer.version>
1919
<maven.test.skip>false</maven.test.skip>

0 commit comments

Comments
 (0)