]> source.dussan.org Git - jackcess.git/commitdiff
Allow ImportFilter and ExportFilter to return null from filterRow() to indicate that...
authorJames Ahlborn <jtahlborn@yahoo.com>
Fri, 25 Nov 2011 02:09:15 +0000 (02:09 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Fri, 25 Nov 2011 02:09:15 +0000 (02:09 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@598 f203690c-595d-4dc9-a70b-905162fa7fd2

test/src/java/com/healthmarketscience/jackcess/ExportTest.java
test/src/java/com/healthmarketscience/jackcess/ImportTest.java

index 86b8fa6f1832feb7b589bff0577ed256eb46de0e..4e2268374effd9e2e77faa7818bd7962adf6446f 100644 (file)
@@ -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());
     }
   }
 
index a0de8c4213ad1ae248888ce14c7ecc53c6a75813..5f75de07504f3d69a55160c2b368e4b9f15446ba 100644 (file)
@@ -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();
     }
   }