aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2011-11-25 15:06:47 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2011-11-25 15:06:47 +0000
commit67560e68f22c9745a7fe11876224a170798b05d5 (patch)
treed2de2a53d1bfdf549b7f104a033c8cef6ea1db35 /test
parent54e66161e13f78312d2a13c7647646dac7032bd5 (diff)
downloadjackcess-67560e68f22c9745a7fe11876224a170798b05d5.tar.gz
jackcess-67560e68f22c9745a7fe11876224a170798b05d5.zip
Add option to import file without headers to existing table; Add ImportUtil.Builder and ExportUtil.Builder to simplify import/export operations
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@599 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'test')
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/ExportTest.java16
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/ImportTest.java60
2 files changed, 63 insertions, 13 deletions
diff --git a/test/src/java/com/healthmarketscience/jackcess/ExportTest.java b/test/src/java/com/healthmarketscience/jackcess/ExportTest.java
index 4e22683..0499277 100644
--- a/test/src/java/com/healthmarketscience/jackcess/ExportTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/ExportTest.java
@@ -81,7 +81,8 @@ public class ExportTest extends TestCase
StringWriter out = new StringWriter();
- ExportUtil.exportWriter(db, "test", new BufferedWriter(out));
+ new ExportUtil.Builder(db, "test")
+ .exportWriter(new BufferedWriter(out));
String expected =
"some text||some more,13,13.25,\"61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78" + NL +
@@ -93,8 +94,11 @@ public class ExportTest extends TestCase
out = new StringWriter();
- ExportUtil.exportWriter(db, "test", new BufferedWriter(out),
- true, "||", '\'', SimpleExportFilter.INSTANCE);
+ new ExportUtil.Builder(db, "test")
+ .setHeader(true)
+ .setDelimiter("||")
+ .setQuote('\'')
+ .exportWriter(new BufferedWriter(out));
expected =
"col1||col2||col3||col4||col5||col6" + NL +
@@ -117,9 +121,9 @@ public class ExportTest extends TestCase
out = new StringWriter();
- ExportUtil.exportWriter(db, "test", new BufferedWriter(out), false,
- ExportUtil.DEFAULT_DELIMITER,
- ExportUtil.DEFAULT_QUOTE_CHAR, oddFilter);
+ new ExportUtil.Builder(db, "test")
+ .setFilter(oddFilter)
+ .exportWriter(new BufferedWriter(out));
expected =
"some text||some more,13,13.25,\"61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78" + NL +
diff --git a/test/src/java/com/healthmarketscience/jackcess/ImportTest.java b/test/src/java/com/healthmarketscience/jackcess/ImportTest.java
index 5f75de0..0be36e1 100644
--- a/test/src/java/com/healthmarketscience/jackcess/ImportTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/ImportTest.java
@@ -58,8 +58,9 @@ public class ImportTest extends TestCase
{
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
Database db = create(fileFormat);
- String tableName = db.importFile(
- "test", new File("test/data/sample-input.tab"), "\\t");
+ String tableName = new ImportUtil.Builder(db, "test")
+ .setDelimiter("\\t")
+ .importFile(new File("test/data/sample-input.tab"));
Table t = db.getTable(tableName);
List<String> colNames = new ArrayList<String>();
@@ -94,6 +95,48 @@ public class ImportTest extends TestCase
);
assertTable(expectedRows, t);
+ t = new TableBuilder("test2")
+ .addColumn(new ColumnBuilder("T1", DataType.TEXT))
+ .addColumn(new ColumnBuilder("T2", DataType.TEXT))
+ .addColumn(new ColumnBuilder("T3", DataType.TEXT))
+ .toTable(db);
+
+ new ImportUtil.Builder(db, "test2")
+ .setDelimiter("\\t")
+ .setUseExistingTable(true)
+ .setHeader(false)
+ .importFile(new File("test/data/sample-input.tab"));
+
+ expectedRows =
+ createExpectedTable(
+ createExpectedRow(
+ "T1", "Test1",
+ "T2", "Test2",
+ "T3", "Test3"),
+ createExpectedRow(
+ "T1", "Foo",
+ "T2", "Bar",
+ "T3", "Ralph"),
+ createExpectedRow(
+ "T1", "S",
+ "T2", "Mouse",
+ "T3", "Rocks"),
+ createExpectedRow(
+ "T1", "",
+ "T2", "Partial line",
+ "T3", null),
+ createExpectedRow(
+ "T1", " Quoted Value",
+ "T2", " bazz ",
+ "T3", " Really \"Crazy" + ImportUtil.LINE_SEPARATOR
+ + "value\""),
+ createExpectedRow(
+ "T1", "buzz",
+ "T2", "embedded\tseparator",
+ "T3", "long")
+ );
+ assertTable(expectedRows, t);
+
ImportFilter oddFilter = new SimpleImportFilter() {
private int _num;
@@ -106,8 +149,10 @@ public class ImportTest extends TestCase
}
};
- tableName = db.importFile(
- "test2", new File("test/data/sample-input.tab"), "\\t", oddFilter);
+ tableName = new ImportUtil.Builder(db, "test3")
+ .setDelimiter("\\t")
+ .setFilter(oddFilter)
+ .importFile(new File("test/data/sample-input.tab"));
t = db.getTable(tableName);
colNames = new ArrayList<String>();
@@ -141,8 +186,9 @@ public class ImportTest extends TestCase
{
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
Database db = create(fileFormat);
- String tableName = db.importFile(
- "test", new File("test/data/sample-input-only-headers.tab"), "\\t");
+ String tableName = new ImportUtil.Builder(db, "test")
+ .setDelimiter("\\t")
+ .importFile(new File("test/data/sample-input-only-headers.tab"));
Table t = db.getTable(tableName);
@@ -273,7 +319,7 @@ public class ImportTest extends TestCase
_precisions.add(precision);
}
- public <T> T getValue(List<T> values, Object index) {
+ private static <T> T getValue(List<T> values, Object index) {
return values.get((Integer)index - 1);
}
}