Skip to content

Commit

Permalink
[JBPM-10195] Schema validation exception when validating Spring Boot …
Browse files Browse the repository at this point in the history
…DDL (kiegroup#2332)

Scripts for Oracle and PostgreSQL
  • Loading branch information
gmunozfe authored and fjtirado committed Nov 6, 2023
1 parent 600de5d commit e2455de
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<property name="hibernate.default_schema" value="${maven.jdbc.schema}"/>

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

<!-- The following line is what's used in Hibernate 4 instead of a TransactionManagerLookup class -->
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import java.io.IOException;
import org.jbpm.test.persistence.scripts.DatabaseType;
import org.jbpm.test.persistence.scripts.PersistenceUnit;
import org.jbpm.test.persistence.scripts.ScriptsBase;
Expand Down Expand Up @@ -55,40 +55,48 @@ public static Collection<ScriptFilter[]> data() {

ScriptFilter[] sbPg = new ScriptFilter[]{filter("postgresql-springboot-jbpm-schema.sql",
"quartz_tables_postgres.sql").setSupportedDatabase(DatabaseType.POSTGRESQL)
.setOptions(Option.DISALLOW_EMPTY_RESULTS, Option.THROW_ON_SCRIPT_ERROR),
.setOptions(Option.DISALLOW_EMPTY_RESULTS,
Option.THROW_ON_SCRIPT_ERROR,
Option.NEW_GENERATOR_MAPPINGS_TRUE),
filter("postgresql-springboot-jbpm-drop-schema.sql",
"quartz_tables_drop_postgres.sql")};

ScriptFilter[] pqlBytea = new ScriptFilter[]{filter("postgresql-bytea-jbpm-schema.sql",
"quartz_tables_postgres.sql")
.setSupportedDatabase(DatabaseType.POSTGRESQL)
.setOptions(Option.DISALLOW_EMPTY_RESULTS, Option.THROW_ON_SCRIPT_ERROR)
.setOptions(Option.DISALLOW_EMPTY_RESULTS,
Option.THROW_ON_SCRIPT_ERROR)
.env("org.kie.persistence.postgresql.useBytea", "true"),
filter("postgresql-bytea-jbpm-drop-schema.sql",
"quartz_tables_drop_postgres.sql")};

ScriptFilter[] pqlSpringBootBytea = new ScriptFilter[]{filter("postgresql-springboot-bytea-jbpm-schema.sql",
"quartz_tables_postgres.sql")
.setSupportedDatabase(DatabaseType.POSTGRESQL)
.setOptions(Option.DISALLOW_EMPTY_RESULTS, Option.THROW_ON_SCRIPT_ERROR)
.setOptions(Option.DISALLOW_EMPTY_RESULTS,
Option.THROW_ON_SCRIPT_ERROR,
Option.NEW_GENERATOR_MAPPINGS_TRUE)
.env("org.kie.persistence.postgresql.useBytea", "true"),
filter("postgresql-springboot-bytea-jbpm-drop-schema.sql",
"quartz_tables_drop_postgres.sql")};

ScriptFilter[] sbOracle = new ScriptFilter[]{filter("oracle-springboot-jbpm-schema.sql",
"quartz_tables_oracle.sql").setSupportedDatabase(DatabaseType.ORACLE)
.setOptions(Option.DISALLOW_EMPTY_RESULTS, Option.THROW_ON_SCRIPT_ERROR),
.setOptions(Option.DISALLOW_EMPTY_RESULTS,
Option.THROW_ON_SCRIPT_ERROR),
filter("oracle-springboot-jbpm-drop-schema.sql",
"quartz_tables_drop_oracle.sql")};

ScriptFilter[] mySqlCluster = new ScriptFilter[]{filter("mysql-innodb-cluster-jbpm-schema.sql",
"quartz_tables_mysql_innodb.sql").setSupportedDatabase(DatabaseType.MYSQLINNODB)
.setOptions(Option.DISALLOW_EMPTY_RESULTS, Option.THROW_ON_SCRIPT_ERROR),
.setOptions(Option.DISALLOW_EMPTY_RESULTS,
Option.THROW_ON_SCRIPT_ERROR),
filter("mysql-innodb-jbpm-drop-schema.sql",
"quartz_tables_drop_mysql_innodb.sql")};

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

@Before
public void prepare() {
public void prepare() throws IOException {
replaceNewGeneratorMappingsValue(createScript);
oldEnvironment = new HashMap<>();
Map<String, Object> newEnvironment = createScript.getEnvironment();
for (Map.Entry<String, Object> entry : newEnvironment.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.jbpm.test.persistence.scripts.ScriptsBase;
import org.jbpm.test.persistence.scripts.util.ScriptFilter;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -80,6 +81,11 @@ public static void hasToBeTested() {
assumeTrue(dbType!=DB2 && dbType!=SYBASE);
}

@Before
public void prepare() throws IOException {
replaceNewGeneratorMappingsValue(ScriptFilter.init(false, false));
}

private void createSchema60UsingDDLs() throws IOException, SQLException {
//create 6.0 schema
executeScriptRunner(DB_60_SCRIPTS_RESOURCE_PATH, ScriptFilter.init(false, true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.jbpm.test.persistence.scripts.util.TestsUtil;
import org.jbpm.test.persistence.scripts.util.ScriptFilter.Option;
import org.jbpm.test.persistence.scripts.util.ScriptFilter;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.TestRule;
Expand All @@ -32,14 +37,17 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static org.jbpm.test.persistence.scripts.TestPersistenceContextBase.createAndInitContext;
import static org.jbpm.test.persistence.scripts.util.ScriptFilter.filter;

public class ScriptsBase {

protected static final String DB_DDL_SCRIPTS_RESOURCE_PATH = "/db/ddl-scripts";
protected static final String TEST_PROCESS_ID = "minimalProcess";

protected static final String PERSISTENCE_XML_PATH = "target/test-classes/META-INF/persistence.xml";
protected static final String BACKUP_PERSISTENCE_XML_PATH = "target/test-classes/META-INF/persistence-backup.xml";

private static final Logger logger = LoggerFactory.getLogger(ScriptsBase.class);

public ScriptsBase() {
Expand All @@ -60,6 +68,17 @@ public static void cleanUp() throws IOException, SQLException {
// Drop optional table "PlanningTask" if exists
executeScriptRunner(DB_DDL_SCRIPTS_RESOURCE_PATH, filter("task_assigning_tables_drop_"));
}

@Before
public void setUp() throws IOException {
// Create a backup of the original persistence.xml for not losing placeholder for next tests
Files.copy(Paths.get(PERSISTENCE_XML_PATH), Paths.get(BACKUP_PERSISTENCE_XML_PATH), REPLACE_EXISTING);
}

@After
public void restoreBackup() throws IOException {
Files.copy(Paths.get(BACKUP_PERSISTENCE_XML_PATH), Paths.get(PERSISTENCE_XML_PATH), StandardCopyOption.REPLACE_EXISTING);
}

public static void executeScriptRunner(String resourcePath, ScriptFilter scriptFilter) throws IOException, SQLException {
final TestPersistenceContextBase scriptRunnerContext = createAndInitContext(PersistenceUnit.SCRIPT_RUNNER);
Expand All @@ -80,4 +99,17 @@ public static void executeScriptRunner(String resourcePath, ScriptFilter scriptF
scriptRunnerContext.clean();
}
}

protected void replaceNewGeneratorMappingsValue(ScriptFilter script) throws IOException {
if (script.hasOption(Option.NEW_GENERATOR_MAPPINGS_TRUE)) {
Files.write(Paths.get(PERSISTENCE_XML_PATH), getUpdatedXml("true").getBytes());
} else {
Files.write(Paths.get(PERSISTENCE_XML_PATH), getUpdatedXml("false").getBytes());
}
}

protected String getUpdatedXml(String placeholderValue) throws IOException {
String templateXml = new String(Files.readAllBytes(Paths.get(BACKUP_PERSISTENCE_XML_PATH)));
return templateXml.replace("${new_generator_mappings.value}", placeholderValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ScriptFilter {
public enum Option {
DISALLOW_EMPTY_RESULTS, // if the filter allow no results
THROW_ON_SCRIPT_ERROR, // if the filter allows script errors
NEW_GENERATOR_MAPPINGS_TRUE //if the new_generator_mappings property switches to true
}

public enum Filter {
Expand Down

0 comments on commit e2455de

Please sign in to comment.