Skip to content

Commit e2455de

Browse files
gmunozfefjtirado
authored andcommitted
[JBPM-10195] Schema validation exception when validating Spring Boot DDL (kiegroup#2332)
Scripts for Oracle and PostgreSQL
1 parent 600de5d commit e2455de

File tree

5 files changed

+59
-11
lines changed

5 files changed

+59
-11
lines changed

jbpm-db-scripts/src/test/filtered-resources/META-INF/persistence.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
<property name="hibernate.default_schema" value="${maven.jdbc.schema}"/>
135135

136136
<!-- BZ 841786: AS7/EAP 6/Hib 4 uses new (sequence) generators which seem to cause problems -->
137-
<property name="hibernate.id.new_generator_mappings" value="false"/>
137+
<property name="hibernate.id.new_generator_mappings" value="${new_generator_mappings.value}"/>
138138

139139
<!-- The following line is what's used in Hibernate 4 instead of a TransactionManagerLookup class -->
140140
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform"/>

jbpm-db-scripts/src/test/java/org/jbpm/persistence/scripts/DDLScriptsTest.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.util.Collection;
2020
import java.util.HashMap;
2121
import java.util.Map;
22-
22+
import java.io.IOException;
2323
import org.jbpm.test.persistence.scripts.DatabaseType;
2424
import org.jbpm.test.persistence.scripts.PersistenceUnit;
2525
import org.jbpm.test.persistence.scripts.ScriptsBase;
@@ -55,40 +55,48 @@ public static Collection<ScriptFilter[]> data() {
5555

5656
ScriptFilter[] sbPg = new ScriptFilter[]{filter("postgresql-springboot-jbpm-schema.sql",
5757
"quartz_tables_postgres.sql").setSupportedDatabase(DatabaseType.POSTGRESQL)
58-
.setOptions(Option.DISALLOW_EMPTY_RESULTS, Option.THROW_ON_SCRIPT_ERROR),
58+
.setOptions(Option.DISALLOW_EMPTY_RESULTS,
59+
Option.THROW_ON_SCRIPT_ERROR,
60+
Option.NEW_GENERATOR_MAPPINGS_TRUE),
5961
filter("postgresql-springboot-jbpm-drop-schema.sql",
6062
"quartz_tables_drop_postgres.sql")};
6163

6264
ScriptFilter[] pqlBytea = new ScriptFilter[]{filter("postgresql-bytea-jbpm-schema.sql",
6365
"quartz_tables_postgres.sql")
6466
.setSupportedDatabase(DatabaseType.POSTGRESQL)
65-
.setOptions(Option.DISALLOW_EMPTY_RESULTS, Option.THROW_ON_SCRIPT_ERROR)
67+
.setOptions(Option.DISALLOW_EMPTY_RESULTS,
68+
Option.THROW_ON_SCRIPT_ERROR)
6669
.env("org.kie.persistence.postgresql.useBytea", "true"),
6770
filter("postgresql-bytea-jbpm-drop-schema.sql",
6871
"quartz_tables_drop_postgres.sql")};
6972

7073
ScriptFilter[] pqlSpringBootBytea = new ScriptFilter[]{filter("postgresql-springboot-bytea-jbpm-schema.sql",
7174
"quartz_tables_postgres.sql")
7275
.setSupportedDatabase(DatabaseType.POSTGRESQL)
73-
.setOptions(Option.DISALLOW_EMPTY_RESULTS, Option.THROW_ON_SCRIPT_ERROR)
76+
.setOptions(Option.DISALLOW_EMPTY_RESULTS,
77+
Option.THROW_ON_SCRIPT_ERROR,
78+
Option.NEW_GENERATOR_MAPPINGS_TRUE)
7479
.env("org.kie.persistence.postgresql.useBytea", "true"),
7580
filter("postgresql-springboot-bytea-jbpm-drop-schema.sql",
7681
"quartz_tables_drop_postgres.sql")};
7782

7883
ScriptFilter[] sbOracle = new ScriptFilter[]{filter("oracle-springboot-jbpm-schema.sql",
7984
"quartz_tables_oracle.sql").setSupportedDatabase(DatabaseType.ORACLE)
80-
.setOptions(Option.DISALLOW_EMPTY_RESULTS, Option.THROW_ON_SCRIPT_ERROR),
85+
.setOptions(Option.DISALLOW_EMPTY_RESULTS,
86+
Option.THROW_ON_SCRIPT_ERROR),
8187
filter("oracle-springboot-jbpm-drop-schema.sql",
8288
"quartz_tables_drop_oracle.sql")};
8389

8490
ScriptFilter[] mySqlCluster = new ScriptFilter[]{filter("mysql-innodb-cluster-jbpm-schema.sql",
8591
"quartz_tables_mysql_innodb.sql").setSupportedDatabase(DatabaseType.MYSQLINNODB)
86-
.setOptions(Option.DISALLOW_EMPTY_RESULTS, Option.THROW_ON_SCRIPT_ERROR),
92+
.setOptions(Option.DISALLOW_EMPTY_RESULTS,
93+
Option.THROW_ON_SCRIPT_ERROR),
8794
filter("mysql-innodb-jbpm-drop-schema.sql",
8895
"quartz_tables_drop_mysql_innodb.sql")};
8996

9097
ScriptFilter[] taskAssigningTables = new ScriptFilter[]{filter(Filter.OUT, "drop", "bytea", "springboot", "cluster")
91-
.setOptions(Option.DISALLOW_EMPTY_RESULTS, Option.THROW_ON_SCRIPT_ERROR),
98+
.setOptions(Option.DISALLOW_EMPTY_RESULTS,
99+
Option.THROW_ON_SCRIPT_ERROR),
92100
filter("jbpm-drop-schema.sql",
93101
"quartz_tables_drop_",
94102
"task_assigning_tables_drop_")};
@@ -107,7 +115,8 @@ public DDLScriptsTest(ScriptFilter createScript, ScriptFilter dropScript) {
107115
private Map<String, Object> oldEnvironment;
108116

109117
@Before
110-
public void prepare() {
118+
public void prepare() throws IOException {
119+
replaceNewGeneratorMappingsValue(createScript);
111120
oldEnvironment = new HashMap<>();
112121
Map<String, Object> newEnvironment = createScript.getEnvironment();
113122
for (Map.Entry<String, Object> entry : newEnvironment.entrySet()) {

jbpm-db-scripts/src/test/java/org/jbpm/persistence/scripts/UpgradeScriptsTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.jbpm.test.persistence.scripts.ScriptsBase;
2929
import org.jbpm.test.persistence.scripts.util.ScriptFilter;
3030
import org.junit.Assert;
31+
import org.junit.Before;
3132
import org.junit.BeforeClass;
3233
import org.junit.Test;
3334
import org.junit.runner.RunWith;
@@ -80,6 +81,11 @@ public static void hasToBeTested() {
8081
assumeTrue(dbType!=DB2 && dbType!=SYBASE);
8182
}
8283

84+
@Before
85+
public void prepare() throws IOException {
86+
replaceNewGeneratorMappingsValue(ScriptFilter.init(false, false));
87+
}
88+
8389
private void createSchema60UsingDDLs() throws IOException, SQLException {
8490
//create 6.0 schema
8591
executeScriptRunner(DB_60_SCRIPTS_RESOURCE_PATH, ScriptFilter.init(false, true));

jbpm-test-util/src/main/java/org/jbpm/test/persistence/scripts/ScriptsBase.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@
1818

1919
import java.io.File;
2020
import java.io.IOException;
21+
import java.nio.file.Files;
22+
import java.nio.file.Paths;
23+
import java.nio.file.StandardCopyOption;
2124
import java.sql.SQLException;
22-
2325
import javax.sql.DataSource;
2426

2527
import org.jbpm.test.persistence.scripts.util.TestsUtil;
28+
import org.jbpm.test.persistence.scripts.util.ScriptFilter.Option;
2629
import org.jbpm.test.persistence.scripts.util.ScriptFilter;
30+
import org.junit.After;
31+
import org.junit.Before;
2732
import org.junit.BeforeClass;
2833
import org.junit.Rule;
2934
import org.junit.rules.TestRule;
@@ -32,14 +37,17 @@
3237
import org.slf4j.Logger;
3338
import org.slf4j.LoggerFactory;
3439

40+
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
3541
import static org.jbpm.test.persistence.scripts.TestPersistenceContextBase.createAndInitContext;
3642
import static org.jbpm.test.persistence.scripts.util.ScriptFilter.filter;
3743

3844
public class ScriptsBase {
3945

4046
protected static final String DB_DDL_SCRIPTS_RESOURCE_PATH = "/db/ddl-scripts";
4147
protected static final String TEST_PROCESS_ID = "minimalProcess";
42-
48+
protected static final String PERSISTENCE_XML_PATH = "target/test-classes/META-INF/persistence.xml";
49+
protected static final String BACKUP_PERSISTENCE_XML_PATH = "target/test-classes/META-INF/persistence-backup.xml";
50+
4351
private static final Logger logger = LoggerFactory.getLogger(ScriptsBase.class);
4452

4553
public ScriptsBase() {
@@ -60,6 +68,17 @@ public static void cleanUp() throws IOException, SQLException {
6068
// Drop optional table "PlanningTask" if exists
6169
executeScriptRunner(DB_DDL_SCRIPTS_RESOURCE_PATH, filter("task_assigning_tables_drop_"));
6270
}
71+
72+
@Before
73+
public void setUp() throws IOException {
74+
// Create a backup of the original persistence.xml for not losing placeholder for next tests
75+
Files.copy(Paths.get(PERSISTENCE_XML_PATH), Paths.get(BACKUP_PERSISTENCE_XML_PATH), REPLACE_EXISTING);
76+
}
77+
78+
@After
79+
public void restoreBackup() throws IOException {
80+
Files.copy(Paths.get(BACKUP_PERSISTENCE_XML_PATH), Paths.get(PERSISTENCE_XML_PATH), StandardCopyOption.REPLACE_EXISTING);
81+
}
6382

6483
public static void executeScriptRunner(String resourcePath, ScriptFilter scriptFilter) throws IOException, SQLException {
6584
final TestPersistenceContextBase scriptRunnerContext = createAndInitContext(PersistenceUnit.SCRIPT_RUNNER);
@@ -80,4 +99,17 @@ public static void executeScriptRunner(String resourcePath, ScriptFilter scriptF
8099
scriptRunnerContext.clean();
81100
}
82101
}
102+
103+
protected void replaceNewGeneratorMappingsValue(ScriptFilter script) throws IOException {
104+
if (script.hasOption(Option.NEW_GENERATOR_MAPPINGS_TRUE)) {
105+
Files.write(Paths.get(PERSISTENCE_XML_PATH), getUpdatedXml("true").getBytes());
106+
} else {
107+
Files.write(Paths.get(PERSISTENCE_XML_PATH), getUpdatedXml("false").getBytes());
108+
}
109+
}
110+
111+
protected String getUpdatedXml(String placeholderValue) throws IOException {
112+
String templateXml = new String(Files.readAllBytes(Paths.get(BACKUP_PERSISTENCE_XML_PATH)));
113+
return templateXml.replace("${new_generator_mappings.value}", placeholderValue);
114+
}
83115
}

jbpm-test-util/src/main/java/org/jbpm/test/persistence/scripts/util/ScriptFilter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class ScriptFilter {
3535
public enum Option {
3636
DISALLOW_EMPTY_RESULTS, // if the filter allow no results
3737
THROW_ON_SCRIPT_ERROR, // if the filter allows script errors
38+
NEW_GENERATOR_MAPPINGS_TRUE //if the new_generator_mappings property switches to true
3839
}
3940

4041
public enum Filter {

0 commit comments

Comments
 (0)