From cd23b435686872ea0abd59568be5bd2bd1994858 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Thu, 28 May 2009 02:57:33 +0000 Subject: add initial test for reading queries; add support for multicolumn joins git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@393 f203690c-595d-4dc9-a70b-905162fa7fd2 --- test/data/queryTest.mdb | Bin 0 -> 163840 bytes .../healthmarketscience/jackcess/DatabaseTest.java | 14 +++--- .../jackcess/query/QueryTest.java | 48 +++++++++++++++++++++ 3 files changed, 56 insertions(+), 6 deletions(-) create mode 100755 test/data/queryTest.mdb (limited to 'test') diff --git a/test/data/queryTest.mdb b/test/data/queryTest.mdb new file mode 100755 index 0000000..5bb6b28 Binary files /dev/null and b/test/data/queryTest.mdb differ diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java index aedf3e7..5b5d343 100644 --- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -66,27 +66,29 @@ public class DatabaseTest extends TestCase { super(name); } - static Database open() throws Exception { + public static Database open() throws Exception { return open(new File("test/data/test.mdb")); } - static Database open(File file) throws Exception { + public static Database open(File file) throws Exception { return Database.open(file, true, _autoSync); } - static Database create() throws Exception { + public static Database create() throws Exception { return create(false); } - static Database create(boolean keep) throws Exception { + public static Database create(boolean keep) throws Exception { return Database.create(createTempFile(keep), _autoSync); } - static Database openCopy(File srcFile) throws Exception { + public static Database openCopy(File srcFile) throws Exception { return openCopy(srcFile, false); } - static Database openCopy(File srcFile, boolean keep) throws Exception { + public static Database openCopy(File srcFile, boolean keep) + throws Exception + { File tmp = createTempFile(keep); copyFile(srcFile, tmp); return Database.open(tmp, false, _autoSync); diff --git a/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java b/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java index 10d976c..5d24307 100644 --- a/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java @@ -27,12 +27,17 @@ King of Prussia, PA 19406 package com.healthmarketscience.jackcess.query; +import java.io.File; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import com.healthmarketscience.jackcess.DataType; +import com.healthmarketscience.jackcess.Database; +import com.healthmarketscience.jackcess.DatabaseTest; import com.healthmarketscience.jackcess.query.Query.Row; import junit.framework.TestCase; import org.apache.commons.lang.StringUtils; @@ -192,6 +197,49 @@ public class QueryTest extends TestCase } + public void testReadQueries() throws Exception + { + Map expectedQueries = new HashMap(); + expectedQueries.put( + "SelectQuery", multiline( + "SELECT Table1.*, Table2.col1, Table2.col2, Table3.col3", + "FROM (Table1 LEFT OUTER JOIN Table3 ON Table1.col1 = Table3.col1) INNER JOIN Table2 ON (Table3.col1 = Table2.col1) AND (Table3.col1 = Table2.col2)", + "WHERE (((Table2.col2)=\"foo\" Or (Table2.col2) In (\"buzz\",\"bazz\")))", + "ORDER BY Table2.col1;")); + expectedQueries.put( + "DeleteQuery", multiline( + "DELETE Table1.col1, Table1.col2, Table1.col3", + "FROM Table1", + "WHERE (((Table1.col1)>\"blah\"));")); + expectedQueries.put( + "AppendQuery",multiline( + "INSERT INTO Table3", + "SELECT [Table1].[col2], [Table2].[col2], [Table2].[col3]", + "FROM Table3, Table1 INNER JOIN Table2 ON [Table1].[col1]=[Table2].[col1];")); + expectedQueries.put( + "UpdateQuery",multiline( + "UPDATE Table1", + "SET Table1.col1 = \"foo\", Table1.col2 = [Table2].[col3]", + "WHERE (([Table2].[col1] Is Not Null));")); + expectedQueries.put( + "MakeTableQuery",multiline( + "SELECT Max(Table2.col1) AS MaxOfcol1, Table2.col2, Table3.col2 INTO Table4", + "FROM (Table2 INNER JOIN Table1 ON Table2.col1 = Table1.col2) RIGHT OUTER JOIN Table3 ON Table1.col2 = Table3.col3", + "GROUP BY Table2.col2, Table3.col2", + "HAVING (((Max(Table2.col1))=\"buzz\") AND ((Table2.col2)<>\"blah\"));")); + + Database db = DatabaseTest.open(new File("test/data/queryTest.mdb")); + + Map foundQueries = new HashMap(); + for(Query q : db.getQueries()) { + assertNull(foundQueries.put(q.getName(), q.toSQLString())); + } + + assertEquals(expectedQueries, foundQueries); + + db.close(); + } + private void doTestColumns(SelectQuery query) throws Exception { addRows(query, newRow(COLUMN_ATTRIBUTE, "Table1.id", null, null)); -- cgit v1.2.3