summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2006-11-13 14:58:29 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2006-11-13 14:58:29 +0000
commitc1f7c9fdc130b58ff94500cb5f44f56de8921e69 (patch)
tree1bce4f44508f4d43d27ac74a9220422f83c9ed5e /test
parentaca6f8632e9dc6b02249607a9f339b1ca8a57260 (diff)
downloadjackcess-c1f7c9fdc130b58ff94500cb5f44f56de8921e69.tar.gz
jackcess-c1f7c9fdc130b58ff94500cb5f44f56de8921e69.zip
add unit test for new copyTable behavior
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@136 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'test')
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java3
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/ImportTest.java126
2 files changed, 122 insertions, 7 deletions
diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
index 51d9220..92cbb47 100644
--- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
@@ -81,7 +81,7 @@ public class DatabaseTest extends TestCase {
col = new Column();
col.setName("A");
col.setType(DataType.TEXT);
- col.setLength((short)(352 * 2));
+ col.setLength((short)(352 * DataType.TEXT.getUnitSize()));
columns.add(col);
try {
@@ -295,7 +295,6 @@ public class DatabaseTest extends TestCase {
assertEquals("Standard", row.get("PROJ_INFO_CAL_NAME"));
assertEquals("Project1", row.get("PROJ_PROP_TITLE"));
byte[] foundBinaryData = (byte[])row.get("RESERVED_BINARY_DATA");
- System.out.println("FOO found len " + foundBinaryData.length);
byte[] expectedBinaryData =
toByteArray(new File("test/data/test2BinData.dat"));
assertTrue(Arrays.equals(expectedBinaryData, foundBinaryData));
diff --git a/test/src/java/com/healthmarketscience/jackcess/ImportTest.java b/test/src/java/com/healthmarketscience/jackcess/ImportTest.java
index 2caf825..c3cb5aa 100644
--- a/test/src/java/com/healthmarketscience/jackcess/ImportTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/ImportTest.java
@@ -2,13 +2,19 @@
package com.healthmarketscience.jackcess;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import com.healthmarketscience.jackcess.Database;
-
import java.io.File;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.List;
+
import junit.framework.TestCase;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* @author Rob Di Marco
@@ -42,4 +48,114 @@ public class ImportTest extends TestCase
"\\t");
}
+ public void testCopySqlHeaders() throws Exception
+ {
+ TestResultSet rs = new TestResultSet();
+
+ rs.addColumn(Types.INTEGER, "col1");
+ rs.addColumn(Types.VARCHAR, "col2", 60, 0, 0);
+ rs.addColumn(Types.VARCHAR, "col3", 500, 0, 0);
+ rs.addColumn(Types.BINARY, "col4", 128, 0, 0);
+ rs.addColumn(Types.BINARY, "col5", 512, 0, 0);
+ rs.addColumn(Types.NUMERIC, "col6", 0, 7, 15);
+
+ Database db = create();
+ db.copyTable("Test1", (ResultSet)Proxy.newProxyInstance(
+ Thread.currentThread().getContextClassLoader(),
+ new Class[]{ResultSet.class},
+ rs));
+
+ Table t = db.getTable("Test1");
+ List<Column> columns = t.getColumns();
+ assertEquals(6, columns.size());
+
+ Column c = columns.get(0);
+ assertEquals("col1", c.getName());
+ assertEquals(DataType.LONG, c.getType());
+
+ c = columns.get(1);
+ assertEquals("col2", c.getName());
+ assertEquals(DataType.TEXT, c.getType());
+ assertEquals(120, c.getLength());
+
+ c = columns.get(2);
+ assertEquals("col3", c.getName());
+ assertEquals(DataType.MEMO, c.getType());
+ assertEquals(0, c.getLength());
+
+ c = columns.get(3);
+ assertEquals("col4", c.getName());
+ assertEquals(DataType.BINARY, c.getType());
+ assertEquals(128, c.getLength());
+
+ c = columns.get(4);
+ assertEquals("col5", c.getName());
+ assertEquals(DataType.OLE, c.getType());
+ assertEquals(0, c.getLength());
+
+ c = columns.get(5);
+ assertEquals("col6", c.getName());
+ assertEquals(DataType.NUMERIC, c.getType());
+ assertEquals(17, c.getLength());
+ assertEquals(7, c.getScale());
+ assertEquals(15, c.getPrecision());
+
+ }
+
+
+ private static class TestResultSet implements InvocationHandler
+ {
+ private List<Integer> _types = new ArrayList<Integer>();
+ private List<String> _names = new ArrayList<String>();
+ private List<Integer> _displaySizes = new ArrayList<Integer>();
+ private List<Integer> _scales = new ArrayList<Integer>();
+ private List<Integer> _precisions = new ArrayList<Integer>();
+
+ public Object invoke(Object proxy, Method method, Object[] args)
+ {
+ String methodName = method.getName();
+ if(methodName.equals("getMetaData")) {
+ return Proxy.newProxyInstance(
+ Thread.currentThread().getContextClassLoader(),
+ new Class[]{ResultSetMetaData.class},
+ this);
+ } else if(methodName.equals("next")) {
+ return Boolean.FALSE;
+ } else if(methodName.equals("getColumnCount")) {
+ return _types.size();
+ } else if(methodName.equals("getColumnName")) {
+ return getValue(_names, args[0]);
+ } else if(methodName.equals("getColumnDisplaySize")) {
+ return getValue(_displaySizes, args[0]);
+ } else if(methodName.equals("getColumnType")) {
+ return getValue(_types, args[0]);
+ } else if(methodName.equals("getScale")) {
+ return getValue(_scales, args[0]);
+ } else if(methodName.equals("getPrecision")) {
+ return getValue(_precisions, args[0]);
+ } else {
+ throw new UnsupportedOperationException(methodName);
+ }
+ }
+
+ public void addColumn(int type, String name)
+ {
+ addColumn(type, name, 0, 0, 0);
+ }
+
+ public void addColumn(int type, String name, int displaySize,
+ int scale, int precision)
+ {
+ _types.add(type);
+ _names.add(name);
+ _displaySizes.add(displaySize);
+ _scales.add(scale);
+ _precisions.add(precision);
+ }
+
+ public <T> T getValue(List<T> values, Object index) {
+ return values.get((Integer)index - 1);
+ }
+ }
+
}