From: Kai Moritz Date: Tue, 29 Apr 2014 07:43:06 +0000 (+0200) Subject: Verifying generated SQL in integration-test hib-test X-Git-Tag: hibernate4-maven-plugin-1.0.4~8 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=f18f820198878cddcea8b98c2a5e0c9843b923d2;p=hibernate-maven-plugin Verifying generated SQL in integration-test hib-test --- diff --git a/pom.xml b/pom.xml index ec7efc82..f09a0850 100644 --- a/pom.xml +++ b/pom.xml @@ -264,6 +264,7 @@ src/it/settings.xml ${project.build.directory}/it verify + true diff --git a/src/it/hib-test/h2.sql b/src/it/hib-test/h2.sql new file mode 100644 index 00000000..9569fa60 --- /dev/null +++ b/src/it/hib-test/h2.sql @@ -0,0 +1,12 @@ + + drop table test_simple if exists; + + create table test_simple ( + uuid varchar(36) not null, + content clob, + externalid varchar(148), + sources varchar(255), + primary key (uuid) + ); + + create index idx_test_simple_tuple on test_simple (sources, uuid); diff --git a/src/it/hib-test/oracle.sql b/src/it/hib-test/oracle.sql new file mode 100644 index 00000000..c610b03f --- /dev/null +++ b/src/it/hib-test/oracle.sql @@ -0,0 +1,12 @@ + + drop table test_simple cascade constraints; + + create table test_simple ( + uuid varchar2(36 char) not null, + content clob, + externalid varchar2(148 char), + sources varchar2(255 char), + primary key (uuid) + ); + + create index idx_test_simple_tuple on test_simple (sources, uuid); diff --git a/src/it/hib-test/pom.xml b/src/it/hib-test/pom.xml index 9ddcf4fe..88dad6a6 100644 --- a/src/it/hib-test/pom.xml +++ b/src/it/hib-test/pom.xml @@ -8,7 +8,6 @@ jar - ${project.build.directory}/hibernate4-schema/another/subdir @@ -49,7 +48,7 @@ org.hibernate.dialect.H2Dialect - ${hibernate.exportdir}/h2.sql + h2.sql @@ -59,7 +58,7 @@ org.hibernate.dialect.PostgreSQL82Dialect - ${hibernate.exportdir}/postgres.sql + postgres.sql @@ -69,7 +68,7 @@ org.hibernate.dialect.Oracle10gDialect - ${hibernate.exportdir}/oracle.sql + oracle.sql diff --git a/src/it/hib-test/postgres.sql b/src/it/hib-test/postgres.sql new file mode 100644 index 00000000..875da31e --- /dev/null +++ b/src/it/hib-test/postgres.sql @@ -0,0 +1,12 @@ + + drop table if exists test_simple cascade; + + create table test_simple ( + uuid varchar(36) not null, + content text, + externalid varchar(148), + sources varchar(255), + primary key (uuid) + ); + + create index idx_test_simple_tuple on test_simple (sources, uuid); diff --git a/src/it/hib-test/verify.bsh b/src/it/hib-test/verify.bsh new file mode 100644 index 00000000..ac2ae58a --- /dev/null +++ b/src/it/hib-test/verify.bsh @@ -0,0 +1,11 @@ +import de.juplo.test.FileComparator; + + +FileComparator comparator = new FileComparator(basedir); + +if (!comparator.isEqual("h2.sql","target/h2.sql")) + return false; +if (!comparator.isEqual("oracle.sql","target/oracle.sql")) + return false; +if (!comparator.isEqual("postgres.sql","target/postgres.sql")) + return false; diff --git a/src/test/java/de/juplo/test/FileComparator.java b/src/test/java/de/juplo/test/FileComparator.java new file mode 100644 index 00000000..beb25641 --- /dev/null +++ b/src/test/java/de/juplo/test/FileComparator.java @@ -0,0 +1,57 @@ +package de.juplo.test; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + + +public class FileComparator +{ + private final File basedir; + private BufferedReader expectedReader; + private BufferedReader foundReader; + + public FileComparator(File basedir) + { + this.basedir = basedir; + } + + public boolean isEqual(final String expectedFile, final String foundFile) + throws + FileNotFoundException, + IOException + { + File file; + String expected, found; + + file = new File(basedir, expectedFile); + expectedReader = new BufferedReader(new FileReader(file)); + + file = new File(basedir, foundFile); + foundReader = new BufferedReader(new FileReader(file)); + + + while ((expected = expectedReader.readLine()) != null) + { + found = foundReader.readLine(); + if (!expected.equals(found)) + { + System.err.println("Mismatch!"); + System.err.println("Expected: " + expected); + System.err.println("Found: " + found); + return false; + } + } + + if ((found = foundReader.readLine()) != null) + { + System.err.println("Found more content than expected!"); + System.err.println("Starting with: " + found); + return false; + } + + return true; + } +} \ No newline at end of file