From a9279e2997c6e6eca18541e42dba8b20e11989a1 Mon Sep 17 00:00:00 2001 From: David Huynh Date: Thu, 6 Oct 2011 07:09:05 +0000 Subject: [PATCH] Got more tests to pass. Note that the automatic column naming behavior did change from { "Column", "Column2", "Column3", ... } to { "Column 1", "Column 2", "Column 3", ... }. Also note that the tsv/csv importer no longer supports the option not to split into columns. That's another importer (the line-based importer). git-svn-id: http://google-refine.googlecode.com/svn/trunk@2277 7d457c2a-affb-35e4-300a-418c747d4874 --- .../refine/tests/importers/ImporterTest.java | 3 +- .../tests/importers/JsonImporterTests.java | 24 ++++----- .../tests/importers/TsvCsvImporterTests.java | 49 ++++++------------- 3 files changed, 30 insertions(+), 46 deletions(-) diff --git a/main/tests/server/src/com/google/refine/tests/importers/ImporterTest.java b/main/tests/server/src/com/google/refine/tests/importers/ImporterTest.java index 61591647e..e11288d8c 100644 --- a/main/tests/server/src/com/google/refine/tests/importers/ImporterTest.java +++ b/main/tests/server/src/com/google/refine/tests/importers/ImporterTest.java @@ -7,6 +7,7 @@ import java.io.Reader; import java.util.ArrayList; import org.json.JSONObject; +import org.mockito.Mockito; import com.google.refine.ProjectMetadata; import com.google.refine.RefineServlet; @@ -38,7 +39,7 @@ abstract class ImporterTest extends RefineTest { metadata = new ProjectMetadata(); job = ImportingManager.createJob(); - options = new JSONObject(); + options = Mockito.mock(JSONObject.class); } public void TearDown(){ diff --git a/main/tests/server/src/com/google/refine/tests/importers/JsonImporterTests.java b/main/tests/server/src/com/google/refine/tests/importers/JsonImporterTests.java index a3e21d9df..f5897ea55 100644 --- a/main/tests/server/src/com/google/refine/tests/importers/JsonImporterTests.java +++ b/main/tests/server/src/com/google/refine/tests/importers/JsonImporterTests.java @@ -101,8 +101,8 @@ public class JsonImporterTests extends ImporterTest { Row row = project.rows.get(0); Assert.assertNotNull(row); - Assert.assertNotNull(row.getCell(2)); - Assert.assertEquals(row.getCell(2).value, "Author 1, The"); + Assert.assertNotNull(row.getCell(1)); + Assert.assertEquals(row.getCell(1).value, "Author 1, The"); } @Test @@ -114,10 +114,10 @@ public class JsonImporterTests extends ImporterTest { Row row = project.rows.get(0); Assert.assertNotNull(row); - Assert.assertEquals(row.cells.size(), 5); - Assert.assertNotNull(row.getCell(2)); - Assert.assertEquals(row.getCell(2).value, "Author 1, The"); - Assert.assertEquals(project.rows.get(1).getCell(2).value, "Author 1, Another"); + Assert.assertEquals(row.cells.size(), 4); + Assert.assertNotNull(row.getCell(1)); + Assert.assertEquals(row.getCell(1).value, "Author 1, The"); + Assert.assertEquals(project.rows.get(1).getCell(1).value, "Author 1, Another"); } @Test @@ -130,9 +130,9 @@ public class JsonImporterTests extends ImporterTest { Row row = project.rows.get(3); Assert.assertNotNull(row); - Assert.assertEquals(row.cells.size(), 5); - Assert.assertNotNull(row.getCell(2)); - Assert.assertEquals(row.getCell(2).value, "With line\n break"); + Assert.assertEquals(row.cells.size(), 4); + Assert.assertNotNull(row.getCell(1)); + Assert.assertEquals(row.getCell(1).value, "With line\n break"); } @Test @@ -142,15 +142,15 @@ public class JsonImporterTests extends ImporterTest { log(project); assertProjectCreated(project, 5, 6); - Assert.assertEquals( project.columnModel.getColumnByCellIndex(5).getName(), "__anonymous__ - genre"); + Assert.assertEquals( project.columnModel.getColumnByCellIndex(4).getName(), "__anonymous__ - genre"); Row row0 = project.rows.get(0); Assert.assertNotNull(row0); - Assert.assertEquals(row0.cells.size(),5); + Assert.assertEquals(row0.cells.size(),4); Row row5 = project.rows.get(5); Assert.assertNotNull(row5); - Assert.assertEquals(row5.cells.size(),6); + Assert.assertEquals(row5.cells.size(),5); } @Test diff --git a/main/tests/server/src/com/google/refine/tests/importers/TsvCsvImporterTests.java b/main/tests/server/src/com/google/refine/tests/importers/TsvCsvImporterTests.java index 8a655db82..d3b71a011 100644 --- a/main/tests/server/src/com/google/refine/tests/importers/TsvCsvImporterTests.java +++ b/main/tests/server/src/com/google/refine/tests/importers/TsvCsvImporterTests.java @@ -96,25 +96,6 @@ public class TsvCsvImporterTests extends ImporterTest { Assert.assertEquals(project.columnModel.columns.get(2).getName(), "col3"); } - @Test(dataProvider = "CSV-TSV-AutoDetermine") - public void readUnseperatedData(String sep){ - //create input to test with - String inputSeparator = sep == null ? "\t" : sep; - String input = "value1" + inputSeparator + "value2" + inputSeparator + "value3"; - - try { - prepareOptions(sep, -1, 0, 0, 0, false, false, false); - parseOneFile(SUT, new StringReader(input)); - } catch (Exception e) { - Assert.fail(); - } - Assert.assertEquals(project.columnModel.columns.size(), 1); - Assert.assertEquals(project.columnModel.columns.get(0).getName(), "Column"); - Assert.assertEquals(project.rows.size(), 1); - Assert.assertEquals(project.rows.get(0).cells.size(), 1); - Assert.assertEquals(project.rows.get(0).cells.get(0).value, input); - } - @Test(dataProvider = "CSV-TSV-AutoDetermine") public void readSimpleData_CSV_1Header_1Row(String sep){ //create input to test with @@ -179,9 +160,9 @@ public class TsvCsvImporterTests extends ImporterTest { Assert.fail(); } Assert.assertEquals(project.columnModel.columns.size(), 3); - Assert.assertEquals(project.columnModel.columns.get(0).getName(), "Column"); - Assert.assertEquals(project.columnModel.columns.get(1).getName(), "Column2"); - Assert.assertEquals(project.columnModel.columns.get(2).getName(), "Column3"); + Assert.assertEquals(project.columnModel.columns.get(0).getName(), "Column 1"); + Assert.assertEquals(project.columnModel.columns.get(1).getName(), "Column 2"); + Assert.assertEquals(project.columnModel.columns.get(2).getName(), "Column 3"); Assert.assertEquals(project.rows.size(), 1); Assert.assertEquals(project.rows.get(0).cells.size(), 3); Assert.assertEquals(project.rows.get(0).cells.get(0).value, "data1"); @@ -291,9 +272,9 @@ public class TsvCsvImporterTests extends ImporterTest { Assert.assertEquals(project.columnModel.columns.get(0).getName(), "col1"); Assert.assertEquals(project.columnModel.columns.get(1).getName(), "col2"); Assert.assertEquals(project.columnModel.columns.get(2).getName(), "col3"); - Assert.assertEquals(project.columnModel.columns.get(3).getName(), "Column"); - Assert.assertEquals(project.columnModel.columns.get(3).getName(), "Column"); - Assert.assertEquals(project.columnModel.columns.get(3).getName(), "Column"); + Assert.assertEquals(project.columnModel.columns.get(3).getName(), "Column 4"); + Assert.assertEquals(project.columnModel.columns.get(4).getName(), "Column 5"); + Assert.assertEquals(project.columnModel.columns.get(5).getName(), "Column 6"); Assert.assertEquals(project.rows.size(), 1); Assert.assertEquals(project.rows.get(0).cells.size(), 6); Assert.assertEquals(project.rows.get(0).cells.get(0).value, "data1"); @@ -586,13 +567,15 @@ public class TsvCsvImporterTests extends ImporterTest { private void prepareOptions( String sep, int limit, int skip, int ignoreLines, int headerLines, boolean guessValueType, boolean splitIntoColumns, boolean ignoreQuotes) { - JSONUtilities.safePut(options, "separator", sep); - JSONUtilities.safePut(options, "limit", limit); - JSONUtilities.safePut(options, "skipDataLines", skip); - JSONUtilities.safePut(options, "ignoreLines", ignoreLines); - JSONUtilities.safePut(options, "headerLines", headerLines); - JSONUtilities.safePut(options, "guessCellValueTypes", guessValueType); - JSONUtilities.safePut(options, "splitIntoColumns", splitIntoColumns); - JSONUtilities.safePut(options, "processQuotes", !ignoreQuotes); + + whenGetStringOption("separator", options, sep); + whenGetIntegerOption("limit", options, limit); + whenGetIntegerOption("skipDataLines", options, skip); + whenGetIntegerOption("ignoreLines", options, ignoreLines); + whenGetIntegerOption("headerLines", options, headerLines); + whenGetBooleanOption("guessCellValueTypes", options, guessValueType); + whenGetBooleanOption("splitIntoColumns", options, splitIntoColumns); + whenGetBooleanOption("processQuotes", options, !ignoreQuotes); + whenGetBooleanOption("storeBlankCellsAsNulls", options, true); } }