From b60cd0eaf85748634e96d1b97a0298dd6e23a6ca Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 2 Aug 2024 14:08:04 +0200 Subject: [PATCH] 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 --- .../rest/conf/jpa/DatabaseInititializer.java | 50 +++++++++++++++--- .../rest/service/BaseSpringRestTestCase.java | 5 +- .../api/runtime/SignalsResourceTest.java | 4 +- .../service/api/runtime/TaskResourceTest.java | 21 ++++---- .../org/flowable/rest/api/jpa/schema.sql | 5 -- .../service/api/repository/oneTaskProcess.png | Bin 0 -> 4048 bytes 6 files changed, 61 insertions(+), 24 deletions(-) delete mode 100644 modules/flowable-rest/src/test/resources/org/flowable/rest/api/jpa/schema.sql diff --git a/modules/flowable-rest/src/test/java/org/flowable/rest/conf/jpa/DatabaseInititializer.java b/modules/flowable-rest/src/test/java/org/flowable/rest/conf/jpa/DatabaseInititializer.java index c0d6844ca43..b633b4aebc6 100644 --- a/modules/flowable-rest/src/test/java/org/flowable/rest/conf/jpa/DatabaseInititializer.java +++ b/modules/flowable-rest/src/test/java/org/flowable/rest/conf/jpa/DatabaseInititializer.java @@ -12,6 +12,10 @@ */ 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; @@ -19,16 +23,15 @@ 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; @@ -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(); + } + } diff --git a/modules/flowable-rest/src/test/java/org/flowable/rest/service/BaseSpringRestTestCase.java b/modules/flowable-rest/src/test/java/org/flowable/rest/service/BaseSpringRestTestCase.java index 8b06545b84c..d4b36abb119 100644 --- a/modules/flowable-rest/src/test/java/org/flowable/rest/service/BaseSpringRestTestCase.java +++ b/modules/flowable-rest/src/test/java/org/flowable/rest/service/BaseSpringRestTestCase.java @@ -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 { diff --git a/modules/flowable-rest/src/test/java/org/flowable/rest/service/api/runtime/SignalsResourceTest.java b/modules/flowable-rest/src/test/java/org/flowable/rest/service/api/runtime/SignalsResourceTest.java index 83dcd335dcb..81aea66cb32 100644 --- a/modules/flowable-rest/src/test/java/org/flowable/rest/service/api/runtime/SignalsResourceTest.java +++ b/modules/flowable-rest/src/test/java/org/flowable/rest/service/api/runtime/SignalsResourceTest.java @@ -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(); @@ -229,7 +229,7 @@ public void testGetEventSubscription() throws Exception { + "activityId: '" + eventSubscription.getActivityId() + "'," + "processDefinitionId: '" + eventSubscription.getProcessDefinitionId() + "'," + "created: " + new TextNode(getISODateStringWithTZ(eventSubscription.getCreated())) + "," - + "tenantId: ''" + + "tenantId: 'acme'" + "}"); } } diff --git a/modules/flowable-rest/src/test/java/org/flowable/rest/service/api/runtime/TaskResourceTest.java b/modules/flowable-rest/src/test/java/org/flowable/rest/service/api/runtime/TaskResourceTest.java index 6b45fce94dc..331d566d837 100644 --- a/modules/flowable-rest/src/test/java/org/flowable/rest/service/api/runtime/TaskResourceTest.java +++ b/modules/flowable-rest/src/test/java/org/flowable/rest/service/api/runtime/TaskResourceTest.java @@ -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; @@ -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(); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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 { diff --git a/modules/flowable-rest/src/test/resources/org/flowable/rest/api/jpa/schema.sql b/modules/flowable-rest/src/test/resources/org/flowable/rest/api/jpa/schema.sql deleted file mode 100644 index b2c540558a8..00000000000 --- a/modules/flowable-rest/src/test/resources/org/flowable/rest/api/jpa/schema.sql +++ /dev/null @@ -1,5 +0,0 @@ -drop table if exists message; -create table message ( - id int, - text varchar(100) -); \ No newline at end of file diff --git a/modules/flowable-rest/src/test/resources/org/flowable/rest/service/api/repository/oneTaskProcess.png b/modules/flowable-rest/src/test/resources/org/flowable/rest/service/api/repository/oneTaskProcess.png index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..af78780a298656d68edbbed3302c2539b5021fcd 100644 GIT binary patch literal 4048 zcmcgvXH-*Lw+(?{Xo5f}0)hny5PENt1Q19lQJNG%4S`FO-jNbO1hGK`LXjvc&Lo_<5eMsORuBlpVPb4> z1q5Qi0N4e}47?|PhwT6#hJY(ZXi#aV@B#?LnQUT!vI=!t&Skr6-Ot}TsM2Z0XH!Jp zHt&hVxu4XK+AjOpdRn{%$6{D=Hb3bM`kdvg*r|ekt1Kx(JWO0X|9+f}D~@%l?l~#t z>BVqQ7fmhG$hzZN$GK?Hxt|dOwfjr^-ca}1rONH2fs0MUo_g3HBO@aTNvt>qX(WUu zjYH!qg8souGDuuS!auMA4#1>;AQV&mXW|k$S(Aemdm6gRLDrXtUI>BjaZT+OLzu&~r&@k}My*_S~UBQE{_djA>2!uiv z6%}JMv-_m<^x1vPEGGr&;E;{5t1$5J^d$5anZ*-8%l=^`N{6B9?Bm5n4?*4Vs*W7Z zG!I@}tl>RAlYoFq6*V=!GTxPJ3Ha!a-@NLVOcy&lvaoJANw>YbpJN+MM_63kb~wtynftxdq3;=R_zR5a&ZB2t}|D8 z58du{xgni`k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