Skip to content

Commit b60cd0e

Browse files
committed
Make BPMN Rest tests more robust
* Adjust DatabaseInitializer to be more DB agnostic * Check timer and async jobs for areJobsAvailable * Use specific tenant in SignalsResourceTest * Add non empty oneTaskProcess.png
1 parent dc3eabe commit b60cd0e

File tree

6 files changed

+61
-24
lines changed

6 files changed

+61
-24
lines changed

modules/flowable-rest/src/test/java/org/flowable/rest/conf/jpa/DatabaseInititializer.java

+43-7
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,26 @@
1212
*/
1313
package org.flowable.rest.conf.jpa;
1414

15+
import java.sql.Connection;
16+
import java.sql.DatabaseMetaData;
17+
import java.sql.SQLException;
18+
1519
import javax.sql.DataSource;
1620

1721
import org.springframework.beans.factory.annotation.Autowired;
1822
import org.springframework.beans.factory.annotation.Value;
1923
import org.springframework.context.annotation.Bean;
2024
import org.springframework.context.annotation.Configuration;
2125
import org.springframework.core.io.Resource;
26+
import org.springframework.jdbc.datasource.init.CompositeDatabasePopulator;
2227
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
2328
import org.springframework.jdbc.datasource.init.DatabasePopulator;
2429
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
30+
import org.springframework.jdbc.datasource.init.ScriptException;
2531

2632
@Configuration(proxyBeanMethods = false)
2733
public class DatabaseInititializer {
2834

29-
@Value("classpath:org/flowable/rest/api/jpa/schema.sql")
30-
private Resource schemaScript;
31-
3235
@Value("classpath:org/flowable/rest/api/jpa/data.sql")
3336
private Resource dataScript;
3437

@@ -40,13 +43,46 @@ public DataSourceInitializer dataSourceInitializer() {
4043
DataSourceInitializer initializer = new DataSourceInitializer();
4144
initializer.setDataSource(dataSource);
4245
initializer.setDatabasePopulator(databasePopulator());
46+
initializer.setDatabaseCleaner(new FlowableDataSourcePopulator(false));
4347
return initializer;
4448
}
4549

4650
private DatabasePopulator databasePopulator() {
47-
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
48-
populator.addScript(schemaScript);
49-
populator.addScript(dataScript);
50-
return populator;
51+
return new CompositeDatabasePopulator(
52+
new FlowableDataSourcePopulator(true),
53+
new ResourceDatabasePopulator(dataScript)
54+
);
5155
}
56+
57+
protected static class FlowableDataSourcePopulator implements DatabasePopulator {
58+
59+
protected final boolean createTable;
60+
61+
protected FlowableDataSourcePopulator(boolean createTable) {
62+
this.createTable = createTable;
63+
}
64+
65+
@Override
66+
public void populate(Connection connection) throws SQLException, ScriptException {
67+
if (isTablePresent(connection)) {
68+
connection.createStatement().execute("drop table message");
69+
}
70+
71+
if (createTable) {
72+
connection.createStatement().execute("create table message (id int, text varchar(100))");
73+
}
74+
}
75+
76+
77+
}
78+
79+
protected static boolean isTablePresent(Connection connection) throws SQLException {
80+
DatabaseMetaData metaData = connection.getMetaData();
81+
boolean tablePresent = metaData.getTables(null, null, "MESSAGE", new String[] { "TABLE" }).next();
82+
if (tablePresent) {
83+
return true;
84+
}
85+
return metaData.getTables(null, null, "message", new String[] { "TABLE" }).next();
86+
}
87+
5288
}

modules/flowable-rest/src/test/java/org/flowable/rest/service/BaseSpringRestTestCase.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,10 @@ public void waitForJobExecutorOnCondition(long maxMillisToWait, long intervalMil
454454
}
455455

456456
public boolean areJobsAvailable() {
457-
return !managementService.createJobQuery().list().isEmpty();
457+
if (managementService.createTimerJobQuery().list().isEmpty()) {
458+
return !managementService.createJobQuery().list().isEmpty();
459+
}
460+
return true;
458461
}
459462

460463
private static class InterruptTask extends TimerTask {

modules/flowable-rest/src/test/java/org/flowable/rest/service/api/runtime/SignalsResourceTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public void testQueryEventSubscriptions() throws Exception {
211211
}
212212

213213
@Test
214-
@Deployment(resources = { "org/flowable/rest/service/api/runtime/SignalsResourceTest.process-signal-start.bpmn20.xml" })
214+
@Deployment(resources = { "org/flowable/rest/service/api/runtime/SignalsResourceTest.process-signal-start.bpmn20.xml" }, tenantId = "acme")
215215
public void testGetEventSubscription() throws Exception {
216216
EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
217217

@@ -229,7 +229,7 @@ public void testGetEventSubscription() throws Exception {
229229
+ "activityId: '" + eventSubscription.getActivityId() + "',"
230230
+ "processDefinitionId: '" + eventSubscription.getProcessDefinitionId() + "',"
231231
+ "created: " + new TextNode(getISODateStringWithTZ(eventSubscription.getCreated())) + ","
232-
+ "tenantId: ''"
232+
+ "tenantId: 'acme'"
233233
+ "}");
234234
}
235235
}

modules/flowable-rest/src/test/java/org/flowable/rest/service/api/runtime/TaskResourceTest.java

+12-9
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
import static org.assertj.core.api.Assertions.tuple;
1919
import static org.mockito.Mockito.when;
2020

21+
import java.time.Instant;
22+
import java.time.temporal.ChronoUnit;
2123
import java.util.Calendar;
2224
import java.util.Collections;
25+
import java.util.Date;
2326
import java.util.List;
2427
import java.util.Map;
2528

@@ -98,12 +101,12 @@ public void resetMocks() {
98101
@Test
99102
@Deployment
100103
public void testGetProcessTask() throws Exception {
101-
Calendar now = Calendar.getInstance();
102-
processEngineConfiguration.getClock().setCurrentTime(now.getTime());
104+
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
105+
processEngineConfiguration.getClock().setCurrentTime(Date.from(now));
103106

104107
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
105108
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
106-
taskService.setDueDate(task.getId(), now.getTime());
109+
taskService.setDueDate(task.getId(), Date.from(now));
107110
taskService.setOwner(task.getId(), "owner");
108111
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
109112
assertThat(task).isNotNull();
@@ -152,8 +155,8 @@ public void testGetProcessTask() throws Exception {
152155
public void testGetProcessAdhoc() throws Exception {
153156
try {
154157

155-
Calendar now = Calendar.getInstance();
156-
processEngineConfiguration.getClock().setCurrentTime(now.getTime());
158+
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
159+
processEngineConfiguration.getClock().setCurrentTime(Date.from(now));
157160

158161
Task parentTask = taskService.newTask();
159162
taskService.saveTask(parentTask);
@@ -165,7 +168,7 @@ public void testGetProcessAdhoc() throws Exception {
165168
task.setAssignee("kermit");
166169
task.setDelegationState(DelegationState.RESOLVED);
167170
task.setDescription("Description");
168-
task.setDueDate(now.getTime());
171+
task.setDueDate(Date.from(now));
169172
task.setOwner("owner");
170173
task.setPriority(20);
171174
taskService.saveTask(task);
@@ -211,7 +214,7 @@ public void testGetProcessAdhoc() throws Exception {
211214
@Test
212215
public void testUpdateTaskNoOverrides() throws Exception {
213216
try {
214-
Calendar now = Calendar.getInstance();
217+
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
215218
Task parentTask = taskService.newTask();
216219
taskService.saveTask(parentTask);
217220

@@ -222,7 +225,7 @@ public void testUpdateTaskNoOverrides() throws Exception {
222225
task.setAssignee("kermit");
223226
task.setDelegationState(DelegationState.RESOLVED);
224227
task.setDescription("Description");
225-
task.setDueDate(now.getTime());
228+
task.setDueDate(Date.from(now));
226229
task.setOwner("owner");
227230
task.setPriority(20);
228231
taskService.saveTask(task);
@@ -241,7 +244,7 @@ public void testUpdateTaskNoOverrides() throws Exception {
241244
assertThat(task.getOwner()).isEqualTo("owner");
242245
assertThat(task.getPriority()).isEqualTo(20);
243246
assertThat(task.getDelegationState()).isEqualTo(DelegationState.RESOLVED);
244-
assertThat(task.getDueDate()).isEqualTo(now.getTime());
247+
assertThat(task.getDueDate()).isEqualTo(Date.from(now));
245248
assertThat(task.getParentTaskId()).isEqualTo(parentTask.getId());
246249

247250
} finally {

modules/flowable-rest/src/test/resources/org/flowable/rest/api/jpa/schema.sql

-5
This file was deleted.

0 commit comments

Comments
 (0)