From b9cb058b5ac7c0f38d2752344cbd145e9d677a6a Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Thu, 28 Oct 2010 03:11:31 +0000 Subject: add support for specifying a quote character on import git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@491 f203690c-595d-4dc9-a70b-905162fa7fd2 --- test/data/sample-input.tab | 6 ++- .../healthmarketscience/jackcess/ImportTest.java | 58 ++++++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/data/sample-input.tab b/test/data/sample-input.tab index 8acfea9..6a88f55 100644 --- a/test/data/sample-input.tab +++ b/test/data/sample-input.tab @@ -1,3 +1,7 @@ Test1 Test2 Test3 Foo Bar Ralph -S Mouse Rocks \ No newline at end of file +S Mouse Rocks + Partial line +" Quoted Value" bazz " Really ""Crazy +value""" +buzz "embedded separator" long line diff --git a/test/src/java/com/healthmarketscience/jackcess/ImportTest.java b/test/src/java/com/healthmarketscience/jackcess/ImportTest.java index 6403077..a0de8c4 100644 --- a/test/src/java/com/healthmarketscience/jackcess/ImportTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/ImportTest.java @@ -35,7 +35,9 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Types; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Map; import junit.framework.TestCase; @@ -56,7 +58,43 @@ public class ImportTest extends TestCase { for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { Database db = create(fileFormat); - db.importFile("test", new File("test/data/sample-input.tab"), "\\t"); + String tableName = db.importFile( + "test", new File("test/data/sample-input.tab"), "\\t"); + Table t = db.getTable(tableName); + + List colNames = new ArrayList(); + for(Column c : t.getColumns()) { + colNames.add(c.getName()); + } + assertEquals(Arrays.asList("Test1", "Test2", "Test3"), colNames); + + List> expectedRows = + createExpectedTable( + createExpectedRow( + "Test1", "Foo", + "Test2", "Bar", + "Test3", "Ralph"), + createExpectedRow( + "Test1", "S", + "Test2", "Mouse", + "Test3", "Rocks"), + createExpectedRow( + "Test1", "", + "Test2", "Partial line", + "Test3", null), + createExpectedRow( + "Test1", " Quoted Value", + "Test2", " bazz ", + "Test3", " Really \"Crazy" + ImportUtil.LINE_SEPARATOR + + "value\""), + createExpectedRow( + "Test1", "buzz", + "Test2", "embedded\tseparator", + "Test3", "long") + ); + assertTable(expectedRows, t); + + db.close(); } } @@ -64,8 +102,22 @@ public class ImportTest extends TestCase { for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { Database db = create(fileFormat); - db.importFile("test", new File("test/data/sample-input-only-headers.tab"), - "\\t"); + String tableName = db.importFile( + "test", new File("test/data/sample-input-only-headers.tab"), "\\t"); + + Table t = db.getTable(tableName); + + List colNames = new ArrayList(); + for(Column c : t.getColumns()) { + colNames.add(c.getName()); + } + assertEquals(Arrays.asList( + "RESULT_PHYS_ID", "FIRST", "MIDDLE", "LAST", "OUTLIER", + "RANK", "CLAIM_COUNT", "PROCEDURE_COUNT", + "WEIGHTED_CLAIM_COUNT", "WEIGHTED_PROCEDURE_COUNT"), + colNames); + + db.close(); } } -- cgit v1.2.3