Search in sources :

Example 46 with Cell

use of com.google.refine.model.Cell in project OpenRefine by OpenRefine.

the class FunctionTests method SetUp.

@BeforeMethod
public void SetUp() throws IOException, ModelException {
    bindings = new Properties();
    File dir = TestUtils.createTempDirectory("openrefine-test-workspace-dir");
    FileProjectManager.initialize(dir);
    project = new Project();
    ProjectMetadata pm = new ProjectMetadata();
    pm.setName("TNG Test Project");
    ProjectManager.singleton.registerProject(project, pm);
    int index = project.columnModel.allocateNewCellIndex();
    Column column = new Column(index, "Column A");
    project.columnModel.addColumn(index, column, true);
    options = mock(Properties.class);
    bindings.put("project", project);
    // Five rows of a's and five of 1s
    for (int i = 0; i < 10; i++) {
        Row row = new Row(1);
        row.setCell(0, new Cell(i < 5 ? "a" : new Integer(1), null));
        project.rows.add(row);
    }
}
Also used : Project(com.google.refine.model.Project) Column(com.google.refine.model.Column) ProjectMetadata(com.google.refine.ProjectMetadata) Row(com.google.refine.model.Row) Properties(java.util.Properties) File(java.io.File) Cell(com.google.refine.model.Cell) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 47 with Cell

use of com.google.refine.model.Cell in project OpenRefine by OpenRefine.

the class CsvExporterTests method CreateGrid.

protected void CreateGrid(int noOfRows, int noOfColumns) {
    CreateColumns(noOfColumns);
    for (int i = 0; i < noOfRows; i++) {
        Row row = new Row(noOfColumns);
        for (int j = 0; j < noOfColumns; j++) {
            row.cells.add(new Cell("row" + i + "cell" + j, null));
        }
        project.rows.add(row);
    }
}
Also used : Row(com.google.refine.model.Row) Cell(com.google.refine.model.Cell)

Example 48 with Cell

use of com.google.refine.model.Cell in project OpenRefine by OpenRefine.

the class CsvExporterTests method exportCsvWithQuote.

@Test
public void exportCsvWithQuote() {
    CreateGrid(3, 3);
    project.rows.get(1).cells.set(1, new Cell("line has \"quote\"", null));
    try {
        SUT.export(project, options, engine, writer);
    } catch (IOException e) {
        Assert.fail();
    }
    Assert.assertEquals(writer.toString(), "column0,column1,column2\n" + "row0cell0,row0cell1,row0cell2\n" + "row1cell0,\"line has \"\"quote\"\"\",row1cell2\n" + "row2cell0,row2cell1,row2cell2\n");
}
Also used : IOException(java.io.IOException) Cell(com.google.refine.model.Cell) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) RefineTest(com.google.refine.tests.RefineTest)

Example 49 with Cell

use of com.google.refine.model.Cell in project OpenRefine by OpenRefine.

the class CsvExporterTests method exportDateColumns.

@Test
public void exportDateColumns() {
    CreateGrid(1, 2);
    Calendar calendar = Calendar.getInstance();
    Date date = new Date();
    when(options.getProperty("printColumnHeader")).thenReturn("false");
    project.rows.get(0).cells.set(0, new Cell(calendar, null));
    project.rows.get(0).cells.set(1, new Cell(date, null));
    try {
        SUT.export(project, options, engine, writer);
    } catch (IOException e) {
        Assert.fail();
    }
    String expectedOutput = ParsingUtilities.dateToString(calendar.getTime()) + "," + ParsingUtilities.dateToString(date) + "\n";
    Assert.assertEquals(writer.toString(), expectedOutput);
}
Also used : Calendar(java.util.Calendar) IOException(java.io.IOException) Cell(com.google.refine.model.Cell) Date(java.util.Date) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) RefineTest(com.google.refine.tests.RefineTest)

Example 50 with Cell

use of com.google.refine.model.Cell in project OpenRefine by OpenRefine.

the class CsvExporterTests method exportCsvWithLineBreaks.

@Test
public void exportCsvWithLineBreaks() {
    CreateGrid(3, 3);
    project.rows.get(1).cells.set(1, new Cell("line\n\n\nbreak", null));
    try {
        SUT.export(project, options, engine, writer);
    } catch (IOException e) {
        Assert.fail();
    }
    Assert.assertEquals(writer.toString(), "column0,column1,column2\n" + "row0cell0,row0cell1,row0cell2\n" + "row1cell0,\"line\n\n\nbreak\",row1cell2\n" + "row2cell0,row2cell1,row2cell2\n");
}
Also used : IOException(java.io.IOException) Cell(com.google.refine.model.Cell) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) RefineTest(com.google.refine.tests.RefineTest)

Aggregations

Cell (com.google.refine.model.Cell)58 Row (com.google.refine.model.Row)36 Column (com.google.refine.model.Column)19 Test (org.testng.annotations.Test)16 RefineTest (com.google.refine.tests.RefineTest)15 BeforeTest (org.testng.annotations.BeforeTest)15 JSONObject (org.json.JSONObject)13 ArrayList (java.util.ArrayList)12 Project (com.google.refine.model.Project)11 IOException (java.io.IOException)11 Properties (java.util.Properties)11 JSONException (org.json.JSONException)9 RowVisitor (com.google.refine.browsing.RowVisitor)7 HistoryEntry (com.google.refine.history.HistoryEntry)7 Serializable (java.io.Serializable)7 Recon (com.google.refine.model.Recon)6 CellChange (com.google.refine.model.changes.CellChange)6 HashMap (java.util.HashMap)6 Evaluable (com.google.refine.expr.Evaluable)5 JSONArray (org.json.JSONArray)4