diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2011-11-25 02:09:15 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2011-11-25 02:09:15 +0000 |
commit | 54e66161e13f78312d2a13c7647646dac7032bd5 (patch) | |
tree | d7d03996a27600718d964c0e7c8aa2d87229ba6a /test | |
parent | 2661755b796d99fb8331393c075c9f9309a687cd (diff) | |
download | jackcess-54e66161e13f78312d2a13c7647646dac7032bd5.tar.gz jackcess-54e66161e13f78312d2a13c7647646dac7032bd5.zip |
Allow ImportFilter and ExportFilter to return null from filterRow() to indicate that a row should be skipped.
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@598 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'test')
-rw-r--r-- | test/src/java/com/healthmarketscience/jackcess/ExportTest.java | 24 | ||||
-rw-r--r-- | test/src/java/com/healthmarketscience/jackcess/ImportTest.java | 39 |
2 files changed, 63 insertions, 0 deletions
diff --git a/test/src/java/com/healthmarketscience/jackcess/ExportTest.java b/test/src/java/com/healthmarketscience/jackcess/ExportTest.java index 86b8fa6..4e22683 100644 --- a/test/src/java/com/healthmarketscience/jackcess/ExportTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/ExportTest.java @@ -103,6 +103,30 @@ public class ExportTest extends TestCase "'crazy''data\"here'||-345||-3.45E-4||61 62 63 64 65 66 67||true||" + NL + "C:\\temp\\some_file.txt||25||0.0||||false||" + NL; assertEquals(expected, out.toString()); + + ExportFilter oddFilter = new SimpleExportFilter() { + private int _num; + @Override + public Object[] filterRow(Object[] row) { + if((_num++ % 2) == 1) { + return null; + } + return row; + } + }; + + out = new StringWriter(); + + ExportUtil.exportWriter(db, "test", new BufferedWriter(out), false, + ExportUtil.DEFAULT_DELIMITER, + ExportUtil.DEFAULT_QUOTE_CHAR, oddFilter); + + 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 + + "79 7A 61 62 63 64\",true," + testDate + NL + + "C:\\temp\\some_file.txt,25,0.0,,false," + NL; + + assertEquals(expected, out.toString()); } } diff --git a/test/src/java/com/healthmarketscience/jackcess/ImportTest.java b/test/src/java/com/healthmarketscience/jackcess/ImportTest.java index a0de8c4..5f75de0 100644 --- a/test/src/java/com/healthmarketscience/jackcess/ImportTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/ImportTest.java @@ -94,6 +94,45 @@ public class ImportTest extends TestCase ); assertTable(expectedRows, t); + + ImportFilter oddFilter = new SimpleImportFilter() { + private int _num; + @Override + public Object[] filterRow(Object[] row) { + if((_num++ % 2) == 1) { + return null; + } + return row; + } + }; + + tableName = db.importFile( + "test2", new File("test/data/sample-input.tab"), "\\t", oddFilter); + t = db.getTable(tableName); + + colNames = new ArrayList<String>(); + for(Column c : t.getColumns()) { + colNames.add(c.getName()); + } + assertEquals(Arrays.asList("Test1", "Test2", "Test3"), colNames); + + expectedRows = + createExpectedTable( + createExpectedRow( + "Test1", "Foo", + "Test2", "Bar", + "Test3", "Ralph"), + createExpectedRow( + "Test1", "", + "Test2", "Partial line", + "Test3", null), + createExpectedRow( + "Test1", "buzz", + "Test2", "embedded\tseparator", + "Test3", "long") + ); + assertTable(expectedRows, t); + db.close(); } } |