From fed9fc9e4e053c8b61895e78d1fbe045fadf7348 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 3 May 2015 11:42:54 +0200 Subject: [PATCH] Integration-Test for envers really generates the SQL --- .../create-tables-hsqldb.sql | 6 +- .../drop-tables-hsqldb.sql | 13 +- .../pom.xml | 119 +++++++----------- .../main/scripts/sql/create-tables-hsqldb.sql | 33 ----- .../main/scripts/sql/drop-tables-hsqldb.sql | 10 -- .../envers/EnversIllustrationTest.java | 4 +- .../envers/util/InitScriptRunner.java | 8 +- 7 files changed, 62 insertions(+), 131 deletions(-) delete mode 100644 src/it/hibernate4-maven-plugin-envers-sample/src/main/scripts/sql/create-tables-hsqldb.sql delete mode 100644 src/it/hibernate4-maven-plugin-envers-sample/src/main/scripts/sql/drop-tables-hsqldb.sql diff --git a/src/it/hibernate4-maven-plugin-envers-sample/create-tables-hsqldb.sql b/src/it/hibernate4-maven-plugin-envers-sample/create-tables-hsqldb.sql index fe6130e0..53262938 100644 --- a/src/it/hibernate4-maven-plugin-envers-sample/create-tables-hsqldb.sql +++ b/src/it/hibernate4-maven-plugin-envers-sample/create-tables-hsqldb.sql @@ -1,7 +1,7 @@ create table TTL_AUDIT_REVISION ( ID bigint not null, - EVENT_DATE timestamp, + EVENT_DATE timestamp not null, ENVERS_TSTAMP bigint not null, USER_NAME varchar(80) not null, primary key (ID) @@ -28,6 +28,6 @@ foreign key (REV) references TTL_AUDIT_REVISION; - create sequence TTL_AUDIT_REVISION_SEQ; + create sequence TTL_AUDIT_REVISION_SEQ start with 1; - create sequence TTL_EVENT_SEQ; + create sequence TTL_EVENT_SEQ start with 1; diff --git a/src/it/hibernate4-maven-plugin-envers-sample/drop-tables-hsqldb.sql b/src/it/hibernate4-maven-plugin-envers-sample/drop-tables-hsqldb.sql index 1578d898..04b457d0 100644 --- a/src/it/hibernate4-maven-plugin-envers-sample/drop-tables-hsqldb.sql +++ b/src/it/hibernate4-maven-plugin-envers-sample/drop-tables-hsqldb.sql @@ -1,10 +1,13 @@ - drop table TTL_AUDIT_REVISION if exists cascade; - drop table TTL_EVENT if exists cascade; + alter table TTL_EVENT_AUD + drop constraint FK_cjsh8995uabmdm9b30uvmyj6p; - drop table TTL_EVENT_AUD if exists cascade; + drop table TTL_AUDIT_REVISION if exists; - drop sequence TTL_AUDIT_REVISION_SEQ if exists ; + drop table TTL_EVENT if exists; - drop sequence TTL_EVENT_SEQ if exists ; + drop table TTL_EVENT_AUD if exists; + drop sequence TTL_AUDIT_REVISION_SEQ; + + drop sequence TTL_EVENT_SEQ; diff --git a/src/it/hibernate4-maven-plugin-envers-sample/pom.xml b/src/it/hibernate4-maven-plugin-envers-sample/pom.xml index 3ca641da..1897c09f 100644 --- a/src/it/hibernate4-maven-plugin-envers-sample/pom.xml +++ b/src/it/hibernate4-maven-plugin-envers-sample/pom.xml @@ -35,83 +35,6 @@ - - - createHsqlDbScript - - - false - - - - - true - classpath:/sql/create-tables-hsqldb.sql - - - org.hsqldb.jdbc.JDBCDriver - jdbc:hsqldb:mem:demodb - sa - sapwd - org.hibernate.dialect.HSQLDialect - - - org.hsqldb.jdbcDriver - org.hibernate.dialect.HSQLDialect - - - sa - - true - - - - - - de.juplo - hibernate4-maven-plugin - ${de.juplo-hibernate-plugin-version} - - - - export - - - - - ${project.build.sourceDirectory}/../scripts/sql/create-tables-hsqldb.sql - - SCRIPT - CREATE - - - - org.hibernate - hibernate-core - ${org.hibernate.version} - - - org.scannotation - scannotation - 1.0.3 - - - org.slf4j - slf4j-api - ${org.slf4j.version} - - - org.hsqldb - hsqldb - ${org.hsqldb.version} - - - - - - - @@ -251,6 +174,48 @@ true + + de.juplo + hibernate4-maven-plugin + ${de.juplo-hibernate-plugin-version} + + + create-create-script + + export + + + ${project.build.directory}/test-classes/sql/create-tables-hsqldb.sql + + CREATE + + + + create-drop-script + + export + + + ${project.build.directory}/test-classes/sql/drop-tables-hsqldb.sql + + DROP + + + + + SCRIPT + org.hsqldb.jdbc.JDBCDriver + org.hibernate.dialect.HSQLDialect + true + + + + org.hsqldb + hsqldb + ${org.hsqldb.version} + + + diff --git a/src/it/hibernate4-maven-plugin-envers-sample/src/main/scripts/sql/create-tables-hsqldb.sql b/src/it/hibernate4-maven-plugin-envers-sample/src/main/scripts/sql/create-tables-hsqldb.sql deleted file mode 100644 index fe6130e0..00000000 --- a/src/it/hibernate4-maven-plugin-envers-sample/src/main/scripts/sql/create-tables-hsqldb.sql +++ /dev/null @@ -1,33 +0,0 @@ - - create table TTL_AUDIT_REVISION ( - ID bigint not null, - EVENT_DATE timestamp, - ENVERS_TSTAMP bigint not null, - USER_NAME varchar(80) not null, - primary key (ID) - ); - - create table TTL_EVENT ( - ID bigint not null, - EVENT_DATE timestamp not null, - TITLE varchar(80) not null, - primary key (ID) - ); - - create table TTL_EVENT_AUD ( - ID bigint not null, - REV bigint not null, - REVTYPE tinyint, - EVENT_DATE timestamp, - TITLE varchar(80), - primary key (ID, REV) - ); - - alter table TTL_EVENT_AUD - add constraint FK_cjsh8995uabmdm9b30uvmyj6p - foreign key (REV) - references TTL_AUDIT_REVISION; - - create sequence TTL_AUDIT_REVISION_SEQ; - - create sequence TTL_EVENT_SEQ; diff --git a/src/it/hibernate4-maven-plugin-envers-sample/src/main/scripts/sql/drop-tables-hsqldb.sql b/src/it/hibernate4-maven-plugin-envers-sample/src/main/scripts/sql/drop-tables-hsqldb.sql deleted file mode 100644 index 1578d898..00000000 --- a/src/it/hibernate4-maven-plugin-envers-sample/src/main/scripts/sql/drop-tables-hsqldb.sql +++ /dev/null @@ -1,10 +0,0 @@ - drop table TTL_AUDIT_REVISION if exists cascade; - - drop table TTL_EVENT if exists cascade; - - drop table TTL_EVENT_AUD if exists cascade; - - drop sequence TTL_AUDIT_REVISION_SEQ if exists ; - - drop sequence TTL_EVENT_SEQ if exists ; - diff --git a/src/it/hibernate4-maven-plugin-envers-sample/src/test/java/org/bitbucket/fbascheper/tutorial/envers/EnversIllustrationTest.java b/src/it/hibernate4-maven-plugin-envers-sample/src/test/java/org/bitbucket/fbascheper/tutorial/envers/EnversIllustrationTest.java index 91b3cf11..7e46f35e 100644 --- a/src/it/hibernate4-maven-plugin-envers-sample/src/test/java/org/bitbucket/fbascheper/tutorial/envers/EnversIllustrationTest.java +++ b/src/it/hibernate4-maven-plugin-envers-sample/src/test/java/org/bitbucket/fbascheper/tutorial/envers/EnversIllustrationTest.java @@ -113,8 +113,8 @@ public class EnversIllustrationTest extends AbstractIntegrationTest { long event2Revision1 = event2Revisions.get(0).longValue(); long event2Revision2 = event2Revisions.get(1).longValue(); - assertThat(event2Revision1, is(2L)); - assertThat(event2Revision2, is(3L)); + assertThat(event2Revision1, is(11L)); + assertThat(event2Revision2, is(12L)); Event firstRevision = reader.find(Event.class, event2Id, event2Revision1); diff --git a/src/it/hibernate4-maven-plugin-envers-sample/src/test/java/org/bitbucket/fbascheper/tutorial/envers/util/InitScriptRunner.java b/src/it/hibernate4-maven-plugin-envers-sample/src/test/java/org/bitbucket/fbascheper/tutorial/envers/util/InitScriptRunner.java index b7c9e041..ac3994d9 100644 --- a/src/it/hibernate4-maven-plugin-envers-sample/src/test/java/org/bitbucket/fbascheper/tutorial/envers/util/InitScriptRunner.java +++ b/src/it/hibernate4-maven-plugin-envers-sample/src/test/java/org/bitbucket/fbascheper/tutorial/envers/util/InitScriptRunner.java @@ -71,8 +71,14 @@ public interface InitScriptRunner { public void runScript() { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); - JdbcTestUtils.executeSqlScript(jdbcTemplate, dbDropScriptLocation, false); + try { + JdbcTestUtils.executeSqlScript(jdbcTemplate, dbDropScriptLocation, false); + } + catch (Exception e) {} + try { JdbcTestUtils.executeSqlScript(jdbcTemplate, dbCreateScriptLocation, false); + } + catch (Exception e) {} } -- 2.20.1