Skip to content

Commit

Permalink
Make BPMN Rest tests more robust
Browse files Browse the repository at this point in the history
* Adjust DatabaseInitializer to be more DB agnostic
* Check timer and async jobs for areJobsAvailable
* Use specific tenant in SignalsResourceTest
* Add non empty oneTaskProcess.png
  • Loading branch information
filiphr committed Aug 2, 2024
1 parent dc3eabe commit b60cd0e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,26 @@
*/
package org.flowable.rest.conf.jpa;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.datasource.init.CompositeDatabasePopulator;
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
import org.springframework.jdbc.datasource.init.DatabasePopulator;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.jdbc.datasource.init.ScriptException;

@Configuration(proxyBeanMethods = false)
public class DatabaseInititializer {

@Value("classpath:org/flowable/rest/api/jpa/schema.sql")
private Resource schemaScript;

@Value("classpath:org/flowable/rest/api/jpa/data.sql")
private Resource dataScript;

Expand All @@ -40,13 +43,46 @@ public DataSourceInitializer dataSourceInitializer() {
DataSourceInitializer initializer = new DataSourceInitializer();
initializer.setDataSource(dataSource);
initializer.setDatabasePopulator(databasePopulator());
initializer.setDatabaseCleaner(new FlowableDataSourcePopulator(false));
return initializer;
}

private DatabasePopulator databasePopulator() {
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
populator.addScript(schemaScript);
populator.addScript(dataScript);
return populator;
return new CompositeDatabasePopulator(
new FlowableDataSourcePopulator(true),
new ResourceDatabasePopulator(dataScript)
);
}

protected static class FlowableDataSourcePopulator implements DatabasePopulator {

protected final boolean createTable;

protected FlowableDataSourcePopulator(boolean createTable) {
this.createTable = createTable;
}

@Override
public void populate(Connection connection) throws SQLException, ScriptException {
if (isTablePresent(connection)) {
connection.createStatement().execute("drop table message");
}

if (createTable) {
connection.createStatement().execute("create table message (id int, text varchar(100))");
}
}


}

protected static boolean isTablePresent(Connection connection) throws SQLException {
DatabaseMetaData metaData = connection.getMetaData();
boolean tablePresent = metaData.getTables(null, null, "MESSAGE", new String[] { "TABLE" }).next();
if (tablePresent) {
return true;
}
return metaData.getTables(null, null, "message", new String[] { "TABLE" }).next();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ public void waitForJobExecutorOnCondition(long maxMillisToWait, long intervalMil
}

public boolean areJobsAvailable() {
return !managementService.createJobQuery().list().isEmpty();
if (managementService.createTimerJobQuery().list().isEmpty()) {
return !managementService.createJobQuery().list().isEmpty();
}
return true;
}

private static class InterruptTask extends TimerTask {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void testQueryEventSubscriptions() throws Exception {
}

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

Expand All @@ -229,7 +229,7 @@ public void testGetEventSubscription() throws Exception {
+ "activityId: '" + eventSubscription.getActivityId() + "',"
+ "processDefinitionId: '" + eventSubscription.getProcessDefinitionId() + "',"
+ "created: " + new TextNode(getISODateStringWithTZ(eventSubscription.getCreated())) + ","
+ "tenantId: ''"
+ "tenantId: 'acme'"
+ "}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.Mockito.when;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -98,12 +101,12 @@ public void resetMocks() {
@Test
@Deployment
public void testGetProcessTask() throws Exception {
Calendar now = Calendar.getInstance();
processEngineConfiguration.getClock().setCurrentTime(now.getTime());
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
processEngineConfiguration.getClock().setCurrentTime(Date.from(now));

ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskService.setDueDate(task.getId(), now.getTime());
taskService.setDueDate(task.getId(), Date.from(now));
taskService.setOwner(task.getId(), "owner");
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertThat(task).isNotNull();
Expand Down Expand Up @@ -152,8 +155,8 @@ public void testGetProcessTask() throws Exception {
public void testGetProcessAdhoc() throws Exception {
try {

Calendar now = Calendar.getInstance();
processEngineConfiguration.getClock().setCurrentTime(now.getTime());
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
processEngineConfiguration.getClock().setCurrentTime(Date.from(now));

Task parentTask = taskService.newTask();
taskService.saveTask(parentTask);
Expand All @@ -165,7 +168,7 @@ public void testGetProcessAdhoc() throws Exception {
task.setAssignee("kermit");
task.setDelegationState(DelegationState.RESOLVED);
task.setDescription("Description");
task.setDueDate(now.getTime());
task.setDueDate(Date.from(now));
task.setOwner("owner");
task.setPriority(20);
taskService.saveTask(task);
Expand Down Expand Up @@ -211,7 +214,7 @@ public void testGetProcessAdhoc() throws Exception {
@Test
public void testUpdateTaskNoOverrides() throws Exception {
try {
Calendar now = Calendar.getInstance();
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
Task parentTask = taskService.newTask();
taskService.saveTask(parentTask);

Expand All @@ -222,7 +225,7 @@ public void testUpdateTaskNoOverrides() throws Exception {
task.setAssignee("kermit");
task.setDelegationState(DelegationState.RESOLVED);
task.setDescription("Description");
task.setDueDate(now.getTime());
task.setDueDate(Date.from(now));
task.setOwner("owner");
task.setPriority(20);
taskService.saveTask(task);
Expand All @@ -241,7 +244,7 @@ public void testUpdateTaskNoOverrides() throws Exception {
assertThat(task.getOwner()).isEqualTo("owner");
assertThat(task.getPriority()).isEqualTo(20);
assertThat(task.getDelegationState()).isEqualTo(DelegationState.RESOLVED);
assertThat(task.getDueDate()).isEqualTo(now.getTime());
assertThat(task.getDueDate()).isEqualTo(Date.from(now));
assertThat(task.getParentTaskId()).isEqualTo(parentTask.getId());

} finally {
Expand Down

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b60cd0e

Please sign in to comment.