Verifying generated SQL in integration-test hib-test
authorKai Moritz <kai@juplo.de>
Tue, 29 Apr 2014 07:43:06 +0000 (09:43 +0200)
committerKai Moritz <kai@juplo.de>
Tue, 29 Apr 2014 16:34:10 +0000 (18:34 +0200)
pom.xml
src/it/hib-test/h2.sql [new file with mode: 0644]
src/it/hib-test/oracle.sql [new file with mode: 0644]
src/it/hib-test/pom.xml
src/it/hib-test/postgres.sql [new file with mode: 0644]
src/it/hib-test/verify.bsh [new file with mode: 0644]
src/test/java/de/juplo/test/FileComparator.java [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index ec7efc8..f09a085 100644 (file)
--- a/pom.xml
+++ b/pom.xml
           <settingsFile>src/it/settings.xml</settingsFile>
           <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
           <postBuildHookScript>verify</postBuildHookScript>
+          <addTestClassPath>true</addTestClassPath>
         </configuration>
         <executions>
           <execution>
diff --git a/src/it/hib-test/h2.sql b/src/it/hib-test/h2.sql
new file mode 100644 (file)
index 0000000..9569fa6
--- /dev/null
@@ -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 (file)
index 0000000..c610b03
--- /dev/null
@@ -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);
index 9ddcf4f..88dad6a 100644 (file)
@@ -8,7 +8,6 @@
   <packaging>jar</packaging>
   <properties>
     <!--hibernate.skip>false</hibernate.skip-->
-    <hibernate.exportdir>${project.build.directory}/hibernate4-schema/another/subdir</hibernate.exportdir>
   </properties>
   <dependencies>
     <dependency>
@@ -49,7 +48,7 @@
             </goals>
             <configuration>
               <hibernateDialect>org.hibernate.dialect.H2Dialect</hibernateDialect>
-              <outputFile>${hibernate.exportdir}/h2.sql</outputFile>
+              <outputFile>h2.sql</outputFile>
             </configuration>
           </execution>
           <execution>
@@ -59,7 +58,7 @@
             </goals>
             <configuration>
               <hibernateDialect>org.hibernate.dialect.PostgreSQL82Dialect</hibernateDialect>
-              <outputFile>${hibernate.exportdir}/postgres.sql</outputFile>
+              <outputFile>postgres.sql</outputFile>
             </configuration>
           </execution>
           <execution>
@@ -69,7 +68,7 @@
             </goals>
             <configuration>
               <hibernateDialect>org.hibernate.dialect.Oracle10gDialect</hibernateDialect>
-              <outputFile>${hibernate.exportdir}/oracle.sql</outputFile>
+              <outputFile>oracle.sql</outputFile>
             </configuration>
           </execution>
         </executions>
diff --git a/src/it/hib-test/postgres.sql b/src/it/hib-test/postgres.sql
new file mode 100644 (file)
index 0000000..875da31
--- /dev/null
@@ -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 (file)
index 0000000..ac2ae58
--- /dev/null
@@ -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 (file)
index 0000000..beb2564
--- /dev/null
@@ -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