summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2009-05-28 02:57:33 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2009-05-28 02:57:33 +0000
commitcd23b435686872ea0abd59568be5bd2bd1994858 (patch)
tree70923292c775828b5da4348f19edca4168607a62 /test
parent9ee53ade6d1056a259a7472fa3ba8116f708a7cb (diff)
downloadjackcess-cd23b435686872ea0abd59568be5bd2bd1994858.tar.gz
jackcess-cd23b435686872ea0abd59568be5bd2bd1994858.zip
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
Diffstat (limited to 'test')
-rwxr-xr-xtest/data/queryTest.mdbbin0 -> 163840 bytes
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java14
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java48
3 files changed, 56 insertions, 6 deletions
diff --git a/test/data/queryTest.mdb b/test/data/queryTest.mdb
new file mode 100755
index 0000000..5bb6b28
--- /dev/null
+++ b/test/data/queryTest.mdb
Binary files 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<String,String> expectedQueries = new HashMap<String,String>();
+ 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<String,String> foundQueries = new HashMap<String,String>();
+ 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));