Skip to content

Commit 4db8c90

Browse files
gmunozferoot
authored andcommitted
[JBPM-10200] Add a profile for testing postgresql with testcontainers
1 parent d0e6241 commit 4db8c90

File tree

22 files changed

+378
-117
lines changed

22 files changed

+378
-117
lines changed

jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/ActivityTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.jbpm.workflow.instance.node.WorkItemNodeInstance;
5757
import org.junit.After;
5858
import org.junit.Before;
59+
import org.junit.BeforeClass;
5960
import org.junit.Test;
6061
import org.junit.runner.RunWith;
6162
import org.junit.runners.Parameterized;
@@ -115,8 +116,8 @@ public ActivityTest(boolean persistence) throws Exception {
115116
super(persistence);
116117
}
117118

118-
@Before
119-
public void setup() throws Exception {
119+
@BeforeClass
120+
public static void setup() throws Exception {
120121
setUpDataSource();
121122
}
122123

jbpm-case-mgmt/jbpm-case-mgmt-impl/pom.xml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,21 @@
197197
</testResource>
198198
</testResources>
199199
</build>
200-
200+
<profiles>
201+
<profile>
202+
<id>tc-postgres</id>
203+
<build>
204+
<plugins>
205+
<plugin>
206+
<artifactId>maven-surefire-plugin</artifactId>
207+
<configuration>
208+
<systemPropertyVariables>
209+
<org.kie.persistence.postgresql.useBytea>true</org.kie.persistence.postgresql.useBytea>
210+
</systemPropertyVariables>
211+
</configuration>
212+
</plugin>
213+
</plugins>
214+
</build>
215+
</profile>
216+
</profiles>
201217
</project>

jbpm-case-mgmt/jbpm-case-mgmt-impl/src/test/java/org/jbpm/casemgmt/impl/objects/Patient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030
@Entity
31-
@SequenceGenerator(name="patientIdSeq", sequenceName="PATIENT_ID_SEQ")
31+
@SequenceGenerator(name="patientIdSeq", sequenceName="PATIENT_ID_SEQ", allocationSize = 1)
3232
public class Patient implements Serializable {
3333

3434
private static final long serialVersionUID = 5264889024424345041L;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
maxPoolSize=${maven.btm.maxPoolSize}
2+
allowLocalTransactions=true
3+
# JDBC/Database properties that are set in the maven pom
4+
#
5+
# the below variable names (i.e. "${maven.datasource.classname}) are
6+
# automagically replaced with their values (defined in the pom.xml)
7+
# because of the fact that <filtering> is set to true in for the
8+
# src/test/resources directory in the pom.
9+
#
10+
className=${maven.datasource.classname}
11+
driverClassName=${maven.jdbc.driver.class}
12+
user=${maven.jdbc.username}
13+
password=${maven.jdbc.password}
14+
url=${maven.jdbc.url}
15+
serverName=${maven.jdbc.db.server}
16+
portNumber=${maven.jdbc.db.port}
17+
databaseName=${maven.jdbc.db.name}
18+
defaultSchema=${maven.jdbc.schema}
19+
txType=${maven.tx.type}

jbpm-human-task/jbpm-human-task-core/src/test/java/org/jbpm/services/task/DeadlinesLocalTest.java

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,51 @@
2222
import org.jbpm.services.task.impl.TaskDeadlinesServiceImpl;
2323
import org.kie.test.util.db.PoolingDataSourceWrapper;
2424
import org.junit.After;
25+
import org.junit.AfterClass;
2526
import org.junit.Before;
27+
import org.junit.BeforeClass;
2628
import org.kie.internal.task.api.InternalTaskService;
2729

2830
public class DeadlinesLocalTest extends DeadlinesBaseTest {
2931

30-
private PoolingDataSourceWrapper pds;
31-
private EntityManagerFactory emf;
32-
33-
@Before
34-
public void setup() {
35-
this.notificationListener = new MockNotificationListener();
36-
pds = setupPoolingDataSource();
37-
emf = Persistence.createEntityManagerFactory( "org.jbpm.services.task" );
38-
this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator()
39-
.entityManagerFactory(emf)
40-
.getTaskService();
41-
}
42-
43-
@After
44-
public void clean() {
45-
TaskDeadlinesServiceImpl.reset();
46-
super.tearDown();
47-
if (emf != null) {
48-
emf.close();
49-
}
50-
if (pds != null) {
51-
pds.close();
52-
}
53-
}
32+
private static boolean setupDataSource = false;
33+
private static PoolingDataSourceWrapper pds;
34+
private static EntityManagerFactory emf;
35+
36+
@BeforeClass
37+
public static void beforeClass() {
38+
setupDataSource = true;
39+
pds = setupPoolingDataSource();
40+
emf = Persistence.createEntityManagerFactory( "org.jbpm.services.task");
41+
}
42+
43+
@Before
44+
public void setup() {
45+
this.notificationListener = new MockNotificationListener();
46+
47+
this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator()
48+
.entityManagerFactory(emf)
49+
.getTaskService();
50+
}
51+
52+
@After
53+
public void clean() {
54+
TaskDeadlinesServiceImpl.reset();
55+
super.tearDown();
56+
}
57+
58+
@AfterClass
59+
public static void afterClass() {
60+
if (!setupDataSource) {
61+
return;
62+
}
63+
64+
if (emf != null) {
65+
emf.close();
66+
}
67+
if (pds != null) {
68+
pds.close();
69+
}
70+
}
5471

5572
}

jbpm-human-task/jbpm-human-task-core/src/test/java/org/jbpm/services/task/TaskContentTest.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,36 @@
2929
import org.jbpm.services.task.impl.factories.TaskFactory;
3030
import org.kie.test.util.db.PoolingDataSourceWrapper;
3131
import org.junit.After;
32+
import org.junit.AfterClass;
3233
import org.junit.Before;
34+
import org.junit.BeforeClass;
3335
import org.junit.Test;
3436
import org.kie.api.task.model.Task;
3537
import org.kie.internal.task.api.InternalTaskService;
3638

3739
public class TaskContentTest extends HumanTaskServicesBaseTest {
38-
private PoolingDataSourceWrapper pds;
39-
private EntityManagerFactory emf;
40+
private static PoolingDataSourceWrapper pds;
41+
private static EntityManagerFactory emf;
4042

41-
@Before
42-
public void setup() {
43+
@BeforeClass
44+
public static void beforeClass() {
4345
pds = setupPoolingDataSource();
4446
emf = Persistence.createEntityManagerFactory("org.jbpm.services.task");
45-
47+
}
48+
49+
@Before
50+
public void setup() {
4651
this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf)
4752
.getTaskService();
4853
}
4954

5055
@After
5156
public void clean() {
5257
super.tearDown();
58+
}
59+
60+
@AfterClass
61+
public static void afterClass() {
5362
if( emf != null ) {
5463
emf.close();
5564
}

jbpm-human-task/jbpm-human-task-core/src/test/java/org/jbpm/services/task/TaskReminderTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,25 @@
2121

2222
import org.kie.test.util.db.PoolingDataSourceWrapper;
2323
import org.junit.After;
24+
import org.junit.AfterClass;
2425
import org.junit.Before;
26+
import org.junit.BeforeClass;
2527
import org.kie.internal.task.api.InternalTaskService;
2628
import org.kie.internal.utils.ChainedProperties;
2729
import org.kie.internal.utils.ClassLoaderUtil;
2830
import org.subethamail.wiser.Wiser;
2931

3032
public class TaskReminderTest extends TaskReminderBaseTest {
3133

32-
private PoolingDataSourceWrapper pds;
33-
private EntityManagerFactory emf;
34+
private static PoolingDataSourceWrapper pds;
35+
private static EntityManagerFactory emf;
3436

37+
@BeforeClass
38+
public static void beforeClass() {
39+
pds = setupPoolingDataSource();
40+
emf = Persistence.createEntityManagerFactory("org.jbpm.services.task");
41+
}
42+
3543
@Before
3644
public void setup() {
3745
final ChainedProperties props = ChainedProperties.getChainedProperties( "email.conf", ClassLoaderUtil.getClassLoader( null, getClass(), false ));
@@ -46,8 +54,6 @@ public void setup() {
4654
// Do nothing
4755
}
4856

49-
pds = setupPoolingDataSource();
50-
emf = Persistence.createEntityManagerFactory("org.jbpm.services.task");
5157
this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator()
5258
.entityManagerFactory(emf)
5359
.getTaskService();
@@ -64,6 +70,10 @@ public void clean() {
6470
}
6571
}
6672
super.tearDown();
73+
}
74+
75+
@AfterClass
76+
public static void afterClass() {
6777
if (emf != null) {
6878
emf.close();
6979
}

jbpm-runtime-manager/pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,4 +383,21 @@
383383
</plugin>
384384
</plugins>
385385
</build>
386+
<profiles>
387+
<profile>
388+
<id>tc-postgres</id>
389+
<build>
390+
<plugins>
391+
<plugin>
392+
<artifactId>maven-surefire-plugin</artifactId>
393+
<configuration>
394+
<systemPropertyVariables>
395+
<org.kie.persistence.postgresql.useBytea>true</org.kie.persistence.postgresql.useBytea>
396+
</systemPropertyVariables>
397+
</configuration>
398+
</plugin>
399+
</plugins>
400+
</build>
401+
</profile>
402+
</profiles>
386403
</project>

jbpm-services/jbpm-executor/pom.xml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@
239239
<filtering>true</filtering>
240240
</testResource>
241241
</testResources>
242-
243242
<plugins>
244243
<plugin>
245244
<!-- We need to fork always as we have tests which are configured by system properties when a JVM starts -->
@@ -313,5 +312,21 @@
313312
</plugin>
314313
</plugins>
315314
</build>
316-
315+
<profiles>
316+
<profile>
317+
<id>tc-postgres</id>
318+
<build>
319+
<plugins>
320+
<plugin>
321+
<artifactId>maven-surefire-plugin</artifactId>
322+
<configuration>
323+
<excludes>
324+
<exclude>**/DB*Test.java</exclude>
325+
</excludes>
326+
</configuration>
327+
</plugin>
328+
</plugins>
329+
</build>
330+
</profile>
331+
</profiles>
317332
</project>

jbpm-services/jbpm-executor/src/test/java/org/jbpm/executor/DBUnavilabilityExecutorTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ public class DBUnavilabilityExecutorTest{
5858
@BeforeClass
5959
public static void createDBServer() {
6060
dsProps = ExecutorTestUtil.getDatasourceProperties();
61-
dsProps.setProperty("url", "jdbc:h2:tcp://localhost:9123/./target/jbpm-exec-test;MODE=LEGACY;NON_KEYWORDS=VALUE");
62-
dsProps.setProperty("tcpPort", "9123");
63-
PersistenceUtil.startH2TcpServer(dsProps);
61+
String jdbcUrl = dsProps.getProperty("url");
62+
if (jdbcUrl != null && jdbcUrl.matches("jdbc:h2:tcp:.*")) {
63+
dsProps.setProperty("url", "jdbc:h2:tcp://localhost:9123/./target/jbpm-exec-test;MODE=LEGACY;NON_KEYWORDS=VALUE");
64+
dsProps.setProperty("tcpPort", "9123");
65+
PersistenceUtil.startH2TcpServer(dsProps);
66+
}
6467
}
6568

6669
@AfterClass

0 commit comments

Comments
 (0)