Skip to content

Commit

Permalink
[JBPM-10200] Add a profile for testing postgresql with testcontainers
Browse files Browse the repository at this point in the history
  • Loading branch information
gmunozfe authored and root committed Oct 4, 2023
1 parent d0e6241 commit 403c93a
Show file tree
Hide file tree
Showing 22 changed files with 381 additions and 117 deletions.
5 changes: 3 additions & 2 deletions jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/ActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.jbpm.workflow.instance.node.WorkItemNodeInstance;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -115,8 +116,8 @@ public ActivityTest(boolean persistence) throws Exception {
super(persistence);
}

@Before
public void setup() throws Exception {
@BeforeClass
public static void setup() throws Exception {
setUpDataSource();
}

Expand Down
18 changes: 17 additions & 1 deletion jbpm-case-mgmt/jbpm-case-mgmt-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,21 @@
</testResource>
</testResources>
</build>

<profiles>
<profile>
<id>tc-postgres</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<org.kie.persistence.postgresql.useBytea>true</org.kie.persistence.postgresql.useBytea>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


@Entity
@SequenceGenerator(name="patientIdSeq", sequenceName="PATIENT_ID_SEQ")
@SequenceGenerator(name="patientIdSeq", sequenceName="PATIENT_ID_SEQ", allocationSize = 1)
public class Patient implements Serializable {

private static final long serialVersionUID = 5264889024424345041L;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
maxPoolSize=${maven.btm.maxPoolSize}
allowLocalTransactions=true
# JDBC/Database properties that are set in the maven pom
#
# the below variable names (i.e. "${maven.datasource.classname}) are
# automagically replaced with their values (defined in the pom.xml)
# because of the fact that <filtering> is set to true in for the
# src/test/resources directory in the pom.
#
className=${maven.datasource.classname}
driverClassName=${maven.jdbc.driver.class}
user=${maven.jdbc.username}
password=${maven.jdbc.password}
url=${maven.jdbc.url}
serverName=${maven.jdbc.db.server}
portNumber=${maven.jdbc.db.port}
databaseName=${maven.jdbc.db.name}
defaultSchema=${maven.jdbc.schema}
txType=${maven.tx.type}
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,51 @@
import org.jbpm.services.task.impl.TaskDeadlinesServiceImpl;
import org.kie.test.util.db.PoolingDataSourceWrapper;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.kie.internal.task.api.InternalTaskService;

public class DeadlinesLocalTest extends DeadlinesBaseTest {

private PoolingDataSourceWrapper pds;
private EntityManagerFactory emf;

@Before
public void setup() {
this.notificationListener = new MockNotificationListener();
pds = setupPoolingDataSource();
emf = Persistence.createEntityManagerFactory( "org.jbpm.services.task" );
this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator()
.entityManagerFactory(emf)
.getTaskService();
}

@After
public void clean() {
TaskDeadlinesServiceImpl.reset();
super.tearDown();
if (emf != null) {
emf.close();
}
if (pds != null) {
pds.close();
}
}
private static boolean setupDataSource = false;
private static PoolingDataSourceWrapper pds;
private static EntityManagerFactory emf;

@BeforeClass
public static void beforeClass() {
setupDataSource = true;
pds = setupPoolingDataSource();
emf = Persistence.createEntityManagerFactory( "org.jbpm.services.task");
}

@Before
public void setup() {
this.notificationListener = new MockNotificationListener();

this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator()
.entityManagerFactory(emf)
.getTaskService();
}

@After
public void clean() {
TaskDeadlinesServiceImpl.reset();
super.tearDown();
}

@AfterClass
public static void afterClass() {
if (!setupDataSource) {
return;
}

if (emf != null) {
emf.close();
}
if (pds != null) {
pds.close();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,36 @@
import org.jbpm.services.task.impl.factories.TaskFactory;
import org.kie.test.util.db.PoolingDataSourceWrapper;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.kie.api.task.model.Task;
import org.kie.internal.task.api.InternalTaskService;

public class TaskContentTest extends HumanTaskServicesBaseTest {
private PoolingDataSourceWrapper pds;
private EntityManagerFactory emf;
private static PoolingDataSourceWrapper pds;
private static EntityManagerFactory emf;

@Before
public void setup() {
@BeforeClass
public static void beforeClass() {
pds = setupPoolingDataSource();
emf = Persistence.createEntityManagerFactory("org.jbpm.services.task");

}

@Before
public void setup() {
this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf)
.getTaskService();
}

@After
public void clean() {
super.tearDown();
}

@AfterClass
public static void afterClass() {
if( emf != null ) {
emf.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,25 @@

import org.kie.test.util.db.PoolingDataSourceWrapper;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.kie.internal.task.api.InternalTaskService;
import org.kie.internal.utils.ChainedProperties;
import org.kie.internal.utils.ClassLoaderUtil;
import org.subethamail.wiser.Wiser;

public class TaskReminderTest extends TaskReminderBaseTest {

private PoolingDataSourceWrapper pds;
private EntityManagerFactory emf;
private static PoolingDataSourceWrapper pds;
private static EntityManagerFactory emf;

@BeforeClass
public static void beforeClass() {
pds = setupPoolingDataSource();
emf = Persistence.createEntityManagerFactory("org.jbpm.services.task");
}

@Before
public void setup() {
final ChainedProperties props = ChainedProperties.getChainedProperties( "email.conf", ClassLoaderUtil.getClassLoader( null, getClass(), false ));
Expand All @@ -46,8 +54,6 @@ public void setup() {
// Do nothing
}

pds = setupPoolingDataSource();
emf = Persistence.createEntityManagerFactory("org.jbpm.services.task");
this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator()
.entityManagerFactory(emf)
.getTaskService();
Expand All @@ -64,6 +70,10 @@ public void clean() {
}
}
super.tearDown();
}

@AfterClass
public static void afterClass() {
if (emf != null) {
emf.close();
}
Expand Down
17 changes: 17 additions & 0 deletions jbpm-runtime-manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -383,4 +383,21 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>tc-postgres</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<org.kie.persistence.postgresql.useBytea>true</org.kie.persistence.postgresql.useBytea>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
19 changes: 17 additions & 2 deletions jbpm-services/jbpm-executor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@
<filtering>true</filtering>
</testResource>
</testResources>

<plugins>
<plugin>
<!-- We need to fork always as we have tests which are configured by system properties when a JVM starts -->
Expand Down Expand Up @@ -313,5 +312,21 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>tc-postgres</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/DB*Test.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ public class DBUnavilabilityExecutorTest{
@BeforeClass
public static void createDBServer() {
dsProps = ExecutorTestUtil.getDatasourceProperties();
dsProps.setProperty("url", "jdbc:h2:tcp://localhost:9123/./target/jbpm-exec-test;MODE=LEGACY;NON_KEYWORDS=VALUE");
dsProps.setProperty("tcpPort", "9123");
PersistenceUtil.startH2TcpServer(dsProps);
String jdbcUrl = dsProps.getProperty("url");
if (jdbcUrl != null && jdbcUrl.matches("jdbc:h2:.*")) {
dsProps.setProperty("url", "jdbc:h2:tcp://localhost:9123/./target/jbpm-exec-test;MODE=LEGACY;NON_KEYWORDS=VALUE");
dsProps.setProperty("tcpPort", "9123");
PersistenceUtil.startH2TcpServer(dsProps);
}
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ public static void createDBServer() {
System.setProperty("org.kie.executor.setDefaultOwner", "true");
System.setProperty("org.kie.executor.olderThan", "2");
dsProps = ExecutorTestUtil.getDatasourceProperties();
dsProps.setProperty("url", "jdbc:h2:tcp://localhost:9123/./target/jbpm-exec-test;MODE=LEGACY;NON_KEYWORDS=VALUE");
dsProps.setProperty("tcpPort", "9123");
PersistenceUtil.startH2TcpServer(dsProps);
String jdbcUrl = dsProps.getProperty("url");
if (jdbcUrl != null && jdbcUrl.matches("jdbc:h2:.*")) {
dsProps.setProperty("url", "jdbc:h2:tcp://localhost:9123/./target/jbpm-exec-test;MODE=LEGACY;NON_KEYWORDS=VALUE");
dsProps.setProperty("tcpPort", "9123");
PersistenceUtil.startH2TcpServer(dsProps);
}
IdProvider.reset();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,15 @@ public void testGetProcessInstancesByProcessId() {
public void testGetProcessInstancesWithVariables() {

query = new SqlQueryDefinition("getAllProcessInstancesWithVariables", dataSourceJNDIname);
query.setExpression("select pil.*, v.variableId, v.value " + "from ProcessInstanceLog pil " + "inner join (select vil.processInstanceId ,vil.variableId, MAX(vil.ID) maxvilid FROM VariableInstanceLog vil " + "GROUP BY vil.processInstanceId, vil.variableId ORDER BY vil.processInstanceId) x " + "ON (v.variableId = x.variableId AND v.id = x.maxvilid )" + "INNER JOIN VariableInstanceLog v " + "ON (v.processInstanceId = pil.processInstanceId)");

query.setExpression("SELECT pil.*, v.variableId, v.value " +
"FROM ProcessInstanceLog pil " +
"INNER JOIN (" +
" SELECT vil.processInstanceId, vil.variableId, MAX(vil.ID) AS maxvilid" +
" FROM VariableInstanceLog vil" +
" GROUP BY vil.processInstanceId, vil.variableId" +
") x ON (pil.processInstanceId = x.processInstanceId) " +
"INNER JOIN VariableInstanceLog v ON (v.variableId = x.variableId AND v.id = x.maxvilid)");
queryService.registerQuery(query);

Map<String, Object> params = new HashMap<String, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,15 @@ public void testFormName() {

ProcessInstance instance = processService.getProcessInstance(pids[0]);
assertNotNull(instance);

Long hrTaskId = claimAndCompleteTask(pids[0],"katy");
Long itTaskId = claimAndCompleteTask(pids[0], "salaboy");

claimAndCompleteTask(pids[0], 0, "katy");
claimAndCompleteTask(pids[0], 1, "salaboy");

List<Long> taskIds = runtimeDataService.getTasksByProcessInstanceId(pids[0]);

UserTaskInstanceDesc userTask = runtimeDataService.getTaskById(taskIds.get(2));
assertEquals("CreateProposal", userTask.getFormName());
assertEquals("Proposal for: ", userTask.getSubject());

userTask = runtimeDataService.getTaskByWorkItemId(taskIds.get(0));
UserTaskInstanceDesc userTask = runtimeDataService.getTaskByWorkItemId(hrTaskId);
assertEquals("HRInterview", userTask.getFormName());

userTask = runtimeDataService.getTaskByWorkItemId(itTaskId);
assertEquals("TechInterview", userTask.getFormName());

ProcessInstanceDesc instanceDesc = runtimeDataService.getProcessInstanceById(pids[0]);
assertNotNull(instanceDesc);
Expand All @@ -347,6 +344,7 @@ public void testFormName() {
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertEquals("CreateProposal", tasks.get(0).getFormName());
assertEquals("Proposal for: ", tasks.get(0).getSubject());
}

@Test
Expand All @@ -364,12 +362,18 @@ public void testFormNameParallelTasks() {
assertThat(tasks).extracting("getFormName").contains("HRInterview","TechInterview");
}

private void claimAndCompleteTask(Long processInstanceId, int position, String user) {
List<Long> taskIds = runtimeDataService.getTasksByProcessInstanceId(processInstanceId);
assertTrue(!taskIds.isEmpty());
Long taskId = taskIds.get(position);
private Long claimAndCompleteTask(Long processInstanceId, String user) {
ProcessInstanceDesc instanceDesc = runtimeDataService.getProcessInstanceById(pids[0]);
assertNotNull(instanceDesc);
List<UserTaskInstanceDesc> tasks = instanceDesc.getActiveTasks();
assertNotNull(tasks);
assertEquals(1, tasks.size());
Long taskId = tasks.get(0).getTaskId();

userTaskService.claim(taskId, user);
userTaskService.start(taskId, user);
userTaskService.complete(taskId, user, new HashMap<>());

return taskId;
}
}
Binary file not shown.
Loading

0 comments on commit 403c93a

Please sign in to comment.