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
This commit is contained in:
David Huynh 2011-10-06 07:09:05 +00:00
parent 1c5dc32b88
commit a9279e2997
3 changed files with 30 additions and 46 deletions

View File

@ -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(){

View File

@ -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

View File

@ -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);
}
}