Search in sources :

Example 56 with Cell

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

the class RowTests method toStringTest.

@Test
public void toStringTest() {
    Row row = new Row(5);
    row.setCell(0, new Cell(1, null));
    row.setCell(1, new Cell(2, null));
    row.setCell(2, new Cell(3, null));
    row.setCell(3, new Cell(4, null));
    row.setCell(4, new Cell(5, null));
    Assert.assertEquals(row.toString(), "1,2,3,4,5,");
}
Also used : Row(com.google.refine.model.Row) Cell(com.google.refine.model.Cell) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) RefineTest(com.google.refine.tests.RefineTest)

Example 57 with Cell

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

the class UrlFetchingTests method testUrlCaching.

/**
     * Test for caching
     */
@Test
public void testUrlCaching() throws Exception {
    for (int i = 0; i < 100; i++) {
        Row row = new Row(2);
        row.setCell(0, new Cell(i < 5 ? "apple" : "orange", null));
        project.rows.add(row);
    }
    EngineDependentOperation op = new ColumnAdditionByFetchingURLsOperation(engine_config, "fruits", "\"https://www.random.org/integers/?num=1&min=1&max=100&col=1&base=10&format=plain&rnd=new&city=\"+value", OnError.SetToBlank, "rand", 1, 500, true);
    ProcessManager pm = project.getProcessManager();
    Process process = op.createProcess(project, options);
    process.startPerforming(pm);
    Assert.assertTrue(process.isRunning());
    try {
        // We have 100 rows and 500 ms per row but only two distinct
        // values so we should not wait more than ~2000 ms to get the
        // results. Just to make sure the test passes with plenty of
        // net latency we sleep for longer (but still less than
        // 50,000ms).
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        Assert.fail("Test interrupted");
    }
    Assert.assertFalse(process.isRunning());
    // Inspect rows
    String ref_val = (String) project.rows.get(0).getCellValue(1);
    // just to make sure I picked the right column
    Assert.assertTrue(ref_val != "apple");
    for (int i = 1; i < 4; i++) {
        // all random values should be equal due to caching
        Assert.assertEquals(project.rows.get(i).getCellValue(1), ref_val);
    }
}
Also used : EngineDependentOperation(com.google.refine.operations.EngineDependentOperation) ColumnAdditionByFetchingURLsOperation(com.google.refine.operations.column.ColumnAdditionByFetchingURLsOperation) Process(com.google.refine.process.Process) Row(com.google.refine.model.Row) Cell(com.google.refine.model.Cell) ProcessManager(com.google.refine.process.ProcessManager) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) RefineTest(com.google.refine.tests.RefineTest)

Example 58 with Cell

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

the class CacheTests method testIssue567.

/**
     * Test for issue 567.  Problem doesn't seem to occur when testing
     * interactively, but this demonstrates that the facet count cache
     * can get stale after row removal operations
     * 
     * @throws Exception
     */
@Test
public void testIssue567() throws Exception {
    for (int i = 0; i < 5; i++) {
        Row row = new Row(5);
        row.setCell(0, new Cell(i < 4 ? "a" : "b", null));
        project.rows.add(row);
    }
    engine.getAllRows().accept(project, new CountingRowVisitor(5));
    engine.getAllFilteredRows().accept(project, new CountingRowVisitor(4));
    Function fc = new FacetCount();
    Integer count = (Integer) fc.call(bindings, new Object[] { "a", "value", "Column A" });
    Assert.assertEquals(count.intValue(), 4);
    EngineDependentOperation op = new RowRemovalOperation(engine_config);
    op.createProcess(project, options).performImmediate();
    engine.getAllRows().accept(project, new CountingRowVisitor(1));
    engine.getAllFilteredRows().accept(project, new CountingRowVisitor(0));
    count = (Integer) fc.call(bindings, new Object[] { "a", "value", "Column A" });
    Assert.assertEquals(count.intValue(), 0);
}
Also used : RowRemovalOperation(com.google.refine.operations.row.RowRemovalOperation) Function(com.google.refine.grel.Function) EngineDependentOperation(com.google.refine.operations.EngineDependentOperation) JSONObject(org.json.JSONObject) Row(com.google.refine.model.Row) FacetCount(com.google.refine.expr.functions.FacetCount) 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