Integration-Test for envers really generates the SQL
authorKai Moritz <km@juplo.de>
Sun, 3 May 2015 09:42:54 +0000 (11:42 +0200)
committerKai Moritz <kai@juplo.de>
Thu, 14 May 2015 19:30:48 +0000 (21:30 +0200)
src/it/hibernate4-maven-plugin-envers-sample/create-tables-hsqldb.sql
src/it/hibernate4-maven-plugin-envers-sample/drop-tables-hsqldb.sql
src/it/hibernate4-maven-plugin-envers-sample/pom.xml
src/it/hibernate4-maven-plugin-envers-sample/src/main/scripts/sql/create-tables-hsqldb.sql [deleted file]
src/it/hibernate4-maven-plugin-envers-sample/src/main/scripts/sql/drop-tables-hsqldb.sql [deleted file]
src/it/hibernate4-maven-plugin-envers-sample/src/test/java/org/bitbucket/fbascheper/tutorial/envers/EnversIllustrationTest.java
src/it/hibernate4-maven-plugin-envers-sample/src/test/java/org/bitbucket/fbascheper/tutorial/envers/util/InitScriptRunner.java

index fe6130e..5326293 100644 (file)
@@ -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;
index 1578d89..04b457d 100644 (file)
@@ -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;
index 3ca641d..1897c09 100644 (file)
     </properties>
 
 
-    <profiles>
-        <profile>
-            <id>createHsqlDbScript</id>
-            <!-- Activate this profile to create a database script for a clean HSQLDB schema -->
-            <activation>
-                <activeByDefault>false</activeByDefault>
-            </activation>
-
-            <properties>
-                <!-- These properties are filtered into the integration-test-context-properties
-                     and loaded by spring to run the integration tests -->
-                <filter.execute.db.creation.script>true</filter.execute.db.creation.script>
-                <filter.db.creation.script.location>classpath:/sql/create-tables-hsqldb.sql
-                </filter.db.creation.script.location>
-
-                <filter.dataSource.driverClassName>org.hsqldb.jdbc.JDBCDriver</filter.dataSource.driverClassName>
-                <filter.dataSource.url>jdbc:hsqldb:mem:demodb</filter.dataSource.url>
-                <filter.dataSource.user>sa</filter.dataSource.user>
-                <filter.dataSource.password>sapwd</filter.dataSource.password>
-                <filter.hibernate.dialect>org.hibernate.dialect.HSQLDialect</filter.hibernate.dialect>
-
-                <!-- These properties are used by hibernate4-maven-plugin to create the script -->
-                <hibernate.connection.driver_class>org.hsqldb.jdbcDriver</hibernate.connection.driver_class>
-                <hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
-                <hibernate.connection.url>
-                    <![CDATA[jdbc:hsqldb:target/db/testdb;shutdown=true]]></hibernate.connection.url>
-                <hibernate.connection.username>sa</hibernate.connection.username>
-                <hibernate.connection.password></hibernate.connection.password>
-                <hibernate.export.envers>true</hibernate.export.envers>
-            </properties>
-
-            <build>
-                <plugins>
-                    <plugin>
-                        <groupId>de.juplo</groupId>
-                        <artifactId>hibernate4-maven-plugin</artifactId>
-                        <version>${de.juplo-hibernate-plugin-version}</version>
-                        <executions>
-                            <execution>
-                                <goals>
-                                    <goal>export</goal>
-                                </goals>
-                            </execution>
-                        </executions>
-                        <configuration>
-                            <outputFile>${project.build.sourceDirectory}/../scripts/sql/create-tables-hsqldb.sql
-                            </outputFile>
-                            <target>SCRIPT</target>
-                            <type>CREATE</type>
-                        </configuration>
-                        <dependencies>
-                            <dependency>
-                                <groupId>org.hibernate</groupId>
-                                <artifactId>hibernate-core</artifactId>
-                                <version>${org.hibernate.version}</version>
-                            </dependency>
-                            <dependency>
-                                <groupId>org.scannotation</groupId>
-                                <artifactId>scannotation</artifactId>
-                                <version>1.0.3</version>
-                            </dependency>
-                            <dependency>
-                                <groupId>org.slf4j</groupId>
-                                <artifactId>slf4j-api</artifactId>
-                                <version>${org.slf4j.version}</version>
-                            </dependency>
-                            <dependency>
-                                <groupId>org.hsqldb</groupId>
-                                <artifactId>hsqldb</artifactId>
-                                <version>${org.hsqldb.version}</version>
-                            </dependency>
-                        </dependencies>
-                    </plugin>
-                </plugins>
-            </build>
-        </profile>
-    </profiles>
 
 
     <dependencies>
                     <showWarnings>true</showWarnings>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>de.juplo</groupId>
+                <artifactId>hibernate4-maven-plugin</artifactId>
+                <version>${de.juplo-hibernate-plugin-version}</version>
+                <executions>
+                    <execution>
+                        <id>create-create-script</id>
+                        <goals>
+                            <goal>export</goal>
+                        </goals>
+                        <configuration>
+                            <outputFile>${project.build.directory}/test-classes/sql/create-tables-hsqldb.sql
+                            </outputFile>
+                            <type>CREATE</type>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>create-drop-script</id>
+                        <goals>
+                            <goal>export</goal>
+                        </goals>
+                        <configuration>
+                            <outputFile>${project.build.directory}/test-classes/sql/drop-tables-hsqldb.sql
+                            </outputFile>
+                            <type>DROP</type>
+                        </configuration>
+                    </execution>
+                </executions>
+                <configuration>
+                    <target>SCRIPT</target>
+                    <driverClassName>org.hsqldb.jdbc.JDBCDriver</driverClassName>
+                    <hibernateDialect>org.hibernate.dialect.HSQLDialect</hibernateDialect>
+                    <envers>true</envers>
+                </configuration>
+                <dependencies>
+                    <dependency>
+                        <groupId>org.hsqldb</groupId>
+                        <artifactId>hsqldb</artifactId>
+                        <version>${org.hsqldb.version}</version>
+                    </dependency>
+                </dependencies>
+            </plugin>
         </plugins>
 
         <resources>
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 (file)
index fe6130e..0000000
+++ /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 (file)
index 1578d89..0000000
+++ /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 ;
-
index 91b3cf1..7e46f35 100644 (file)
@@ -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);
 
index b7c9e04..ac3994d 100644 (file)
@@ -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) {}
 
         }