Search in sources :

Example 31 with AbstractOperation

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

the class FillDownTests method testFillDownRows.

// For issue #742
// https://github.com/OpenRefine/OpenRefine/issues/742
@Test
public void testFillDownRows() throws Exception {
    AbstractOperation op = new FillDownOperation(EngineConfig.reconstruct("{\"mode\":\"row-based\",\"facets\":[]}"), "second");
    Process process = op.createProcess(project, new Properties());
    process.performImmediate();
    Assert.assertEquals("c", project.rows.get(0).cells.get(2).value);
    Assert.assertEquals("c", project.rows.get(1).cells.get(2).value);
    Assert.assertEquals("c", project.rows.get(2).cells.get(2).value);
    Assert.assertEquals("h", project.rows.get(3).cells.get(2).value);
}
Also used : AbstractOperation(com.google.refine.model.AbstractOperation) Process(com.google.refine.process.Process) Properties(java.util.Properties) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test)

Example 32 with AbstractOperation

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

the class FillDownTests method testFillDownRecordKey.

@Test
public void testFillDownRecordKey() throws Exception {
    AbstractOperation op = new FillDownOperation(EngineConfig.reconstruct("{\"mode\":\"record-based\",\"facets\":[]}"), "key");
    Process process = op.createProcess(project, new Properties());
    process.performImmediate();
    Assert.assertEquals("a", project.rows.get(0).cells.get(0).value);
    Assert.assertEquals("a", project.rows.get(1).cells.get(0).value);
    Assert.assertEquals("e", project.rows.get(2).cells.get(0).value);
    Assert.assertEquals("e", project.rows.get(3).cells.get(0).value);
}
Also used : AbstractOperation(com.google.refine.model.AbstractOperation) Process(com.google.refine.process.Process) Properties(java.util.Properties) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test)

Example 33 with AbstractOperation

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

the class KeyValueColumnizeTests method testKeyValueColumnizeWithID.

/**
 * Test in the case where an ID is available in the first column.
 *
 * @throws Exception
 */
@Test
public void testKeyValueColumnizeWithID() throws Exception {
    Project project = createCSVProject("ID,Cat,Val\n" + "1,a,1\n" + "1,b,3\n" + "2,b,4\n" + "2,c,5\n" + "3,a,2\n" + "3,b,5\n" + "3,d,3\n");
    AbstractOperation op = new KeyValueColumnizeOperation("Cat", "Val", null);
    Process process = op.createProcess(project, new Properties());
    process.performImmediate();
    // Expected output from the GUI.
    // ID,a,b,c,d
    // 1,1,3,,
    // 2,,4,5,
    // 3,2,5,,3
    Assert.assertEquals(project.columnModel.columns.size(), 5);
    Assert.assertEquals(project.columnModel.columns.get(0).getName(), "ID");
    Assert.assertEquals(project.columnModel.columns.get(1).getName(), "a");
    Assert.assertEquals(project.columnModel.columns.get(2).getName(), "b");
    Assert.assertEquals(project.columnModel.columns.get(3).getName(), "c");
    Assert.assertEquals(project.columnModel.columns.get(4).getName(), "d");
    Assert.assertEquals(project.rows.size(), 3);
    // The actual row data structure has to leave the columns model untouched for redo/undo purpose.
    // So we have 2 empty columns(column 1,2) on the row level.
    // 1,1,3,,
    Assert.assertEquals(project.rows.get(0).cells.get(0).value, "1");
    Assert.assertEquals(project.rows.get(0).cells.get(3).value, "1");
    Assert.assertEquals(project.rows.get(0).cells.get(4).value, "3");
    // 2,,4,5,
    Assert.assertEquals(project.rows.get(1).cells.get(0).value, "2");
    Assert.assertEquals(project.rows.get(1).cells.get(4).value, "4");
    Assert.assertEquals(project.rows.get(1).cells.get(5).value, "5");
    // 3,2,5,,3
    Assert.assertEquals(project.rows.get(2).cells.get(0).value, "3");
    Assert.assertEquals(project.rows.get(2).cells.get(3).value, "2");
    Assert.assertEquals(project.rows.get(2).cells.get(4).value, "5");
    Assert.assertEquals(project.rows.get(2).cells.get(6).value, "3");
}
Also used : Project(com.google.refine.model.Project) AbstractOperation(com.google.refine.model.AbstractOperation) Process(com.google.refine.process.Process) Properties(java.util.Properties) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 34 with AbstractOperation

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

the class KeyValueColumnizeTests method testKeyValueColumnize.

/**
 * Test to demonstrate the intended behaviour of the function, for issue #1214
 * https://github.com/OpenRefine/OpenRefine/issues/1214
 */
@Test
public void testKeyValueColumnize() throws Exception {
    String csv = "Key,Value\n" + "merchant,Katie\n" + "fruit,apple\n" + "price,1.2\n" + "fruit,pear\n" + "price,1.5\n" + "merchant,John\n" + "fruit,banana\n" + "price,3.1\n";
    prepareOptions(",", 20, 0, 0, 1, false, false);
    List<Exception> exceptions = new ArrayList<Exception>();
    importer.parseOneFile(project, pm, job, "filesource", new StringReader(csv), -1, options, exceptions);
    project.update();
    ProjectManager.singleton.registerProject(project, pm);
    AbstractOperation op = new KeyValueColumnizeOperation("Key", "Value", null);
    Process process = op.createProcess(project, new Properties());
    process.performImmediate();
    int merchantCol = project.columnModel.getColumnByName("merchant").getCellIndex();
    int fruitCol = project.columnModel.getColumnByName("fruit").getCellIndex();
    int priceCol = project.columnModel.getColumnByName("price").getCellIndex();
    Assert.assertEquals(project.rows.get(0).getCellValue(merchantCol), "Katie");
    Assert.assertEquals(project.rows.get(1).getCellValue(merchantCol), null);
    Assert.assertEquals(project.rows.get(2).getCellValue(merchantCol), "John");
    Assert.assertEquals(project.rows.get(0).getCellValue(fruitCol), "apple");
    Assert.assertEquals(project.rows.get(1).getCellValue(fruitCol), "pear");
    Assert.assertEquals(project.rows.get(2).getCellValue(fruitCol), "banana");
    Assert.assertEquals(project.rows.get(0).getCellValue(priceCol), "1.2");
    Assert.assertEquals(project.rows.get(1).getCellValue(priceCol), "1.5");
    Assert.assertEquals(project.rows.get(2).getCellValue(priceCol), "3.1");
}
Also used : AbstractOperation(com.google.refine.model.AbstractOperation) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) Process(com.google.refine.process.Process) Properties(java.util.Properties) IOException(java.io.IOException) ModelException(com.google.refine.model.ModelException) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 35 with AbstractOperation

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

the class SplitMultiValuedCellsTests method testSplitMultiValuedCellsTextSeparator.

/**
 * Test to demonstrate the intended behaviour of the function, for issue #1268
 * https://github.com/OpenRefine/OpenRefine/issues/1268
 */
@Test
public void testSplitMultiValuedCellsTextSeparator() throws Exception {
    AbstractOperation op = new MultiValuedCellSplitOperation("Value", "Key", ":", false);
    Process process = op.createProcess(project, new Properties());
    process.performImmediate();
    int keyCol = project.columnModel.getColumnByName("Key").getCellIndex();
    int valueCol = project.columnModel.getColumnByName("Value").getCellIndex();
    Assert.assertEquals(project.rows.get(0).getCellValue(keyCol), "Record_1");
    Assert.assertEquals(project.rows.get(0).getCellValue(valueCol), "one");
    Assert.assertEquals(project.rows.get(1).getCellValue(keyCol), null);
    Assert.assertEquals(project.rows.get(1).getCellValue(valueCol), "two;three four;fiveSix SevèËight;niné91011twelve thirteen 14Àifteen");
}
Also used : AbstractOperation(com.google.refine.model.AbstractOperation) Process(com.google.refine.process.Process) Properties(java.util.Properties) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

AbstractOperation (com.google.refine.model.AbstractOperation)42 Process (com.google.refine.process.Process)36 Properties (java.util.Properties)36 Test (org.testng.annotations.Test)27 RefineTest (com.google.refine.RefineTest)25 Project (com.google.refine.model.Project)14 IOException (java.io.IOException)14 BeforeTest (org.testng.annotations.BeforeTest)14 ServletException (javax.servlet.ServletException)13 ArrayList (java.util.ArrayList)4 Column (com.google.refine.model.Column)3 HistoryEntry (com.google.refine.history.HistoryEntry)2 Cell (com.google.refine.model.Cell)2 Row (com.google.refine.model.Row)2 StringReader (java.io.StringReader)2 ProjectMetadata (com.google.refine.ProjectMetadata)1 Change (com.google.refine.history.Change)1 ModelException (com.google.refine.model.ModelException)1 ReconConfig (com.google.refine.model.recon.ReconConfig)1 StandardReconConfig (com.google.refine.model.recon.StandardReconConfig)1