From 2edf83bdf764eec63e388f0dd179db6788742305 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sat, 11 Aug 2018 19:47:58 +0100 Subject: [PATCH] Start serialization tests for operations --- .../com/google/refine/tests/RefineTest.java | 12 +- .../tests/operations/cell/BlankDownTests.java | 21 ++++ .../tests/operations/cell/FillDownTests.java | 19 ++++ .../cell/JoinMultiValuedCellsTests.java | 24 ++++ .../cell/KeyValueColumnizeTests.java | 70 ++++++++++++ .../operations/cell/MassOperationTests.java | 25 ++++ .../cell/SplitMultiValuedCellsTests.java | 20 ++++ .../tests/operations/cell/TransposeTests.java | 107 ++---------------- .../column/ColumnMoveOperationTests.java | 28 +++++ .../column/ColumnRemovalOperationTests.java | 28 +++++ .../column/ColumnRenameOperationTests.java | 29 +++++ .../column/ColumnReorderOperationTests.java | 30 +++++ .../ReconJudgeSimilarCellsTests.java | 24 +++- .../row/DenormalizeOperationTests.java | 27 +++++ 14 files changed, 367 insertions(+), 97 deletions(-) create mode 100644 main/tests/server/src/com/google/refine/tests/operations/column/ColumnMoveOperationTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/operations/column/ColumnRemovalOperationTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/operations/column/ColumnRenameOperationTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/operations/column/ColumnReorderOperationTests.java rename main/tests/server/src/com/google/refine/tests/operations/{cell => recon}/ReconJudgeSimilarCellsTests.java (66%) create mode 100644 main/tests/server/src/com/google/refine/tests/operations/row/DenormalizeOperationTests.java diff --git a/main/tests/server/src/com/google/refine/tests/RefineTest.java b/main/tests/server/src/com/google/refine/tests/RefineTest.java index 88d72c731..26d21eae6 100644 --- a/main/tests/server/src/com/google/refine/tests/RefineTest.java +++ b/main/tests/server/src/com/google/refine/tests/RefineTest.java @@ -69,6 +69,8 @@ import com.google.refine.model.metadata.ProjectMetadata; import com.google.refine.tests.util.TestUtils; import com.google.refine.util.JSONUtilities; +import edu.mit.simile.butterfly.ButterflyModule; + /** * A base class containing various utilities to help testing Refine. */ @@ -83,7 +85,7 @@ public class RefineTest { private List importingJobs = new ArrayList(); @BeforeSuite - public void init() { + public void init() { System.setProperty("log4j.configuration", "tests.log4j.properties"); try { workspaceDir = TestUtils.createTempDirectory("openrefine-test-workspace-dir"); @@ -93,6 +95,8 @@ public class RefineTest { "{\"class\":\"com.google.refine.preference.TopList\",\"top\":2147483647," + "\"list\":[]},\"scripting.expressions\":{\"class\":\"com.google.refine.preference.TopList\",\"top\":100,\"list\":[]}}}}"); FileProjectManager.initialize(workspaceDir); + + } catch (IOException e) { workspaceDir = null; e.printStackTrace(); @@ -315,4 +319,10 @@ public class RefineTest { Assert.fail("JSONException",e); } } + + protected ButterflyModule getCoreModule() { + ButterflyModule coreModule = mock(ButterflyModule.class); + when(coreModule.getName()).thenReturn("core"); + return coreModule; + } } diff --git a/main/tests/server/src/com/google/refine/tests/operations/cell/BlankDownTests.java b/main/tests/server/src/com/google/refine/tests/operations/cell/BlankDownTests.java index 7b4d3b5fa..2ae32c719 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/cell/BlankDownTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/cell/BlankDownTests.java @@ -1,24 +1,34 @@ package com.google.refine.tests.operations.cell; +import static org.mockito.Mockito.when; + import java.util.Properties; import org.json.JSONObject; import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import com.google.refine.ProjectManager; import com.google.refine.model.AbstractOperation; import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; import com.google.refine.operations.cell.BlankDownOperation; import com.google.refine.process.Process; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; public class BlankDownTests extends RefineTest { Project project = null; + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "blank-down", BlankDownOperation.class); + } + @BeforeMethod public void setUp() { project = createCSVProject( @@ -34,6 +44,17 @@ public class BlankDownTests extends RefineTest { ProjectManager.singleton.deleteProject(project.id); } + @Test + public void serializeBlankDownOperation() { + AbstractOperation op = new BlankDownOperation( + new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}"), + "my column"); + TestUtils.isSerializedTo(op, "{\"op\":\"core/blank-down\"," + + "\"description\":\"Blank down cells in column my column\"," + + "\"engineConfig\":{\"mode\":\"record-based\",\"facets\":[]}," + + "\"columnName\":\"my column\"}"); + } + @Test public void testBlankDownRecords() throws Exception { AbstractOperation op = new BlankDownOperation( diff --git a/main/tests/server/src/com/google/refine/tests/operations/cell/FillDownTests.java b/main/tests/server/src/com/google/refine/tests/operations/cell/FillDownTests.java index 1b6a0154e..fd000c02d 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/cell/FillDownTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/cell/FillDownTests.java @@ -6,19 +6,27 @@ import org.json.JSONObject; import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import com.google.refine.ProjectManager; import com.google.refine.model.AbstractOperation; import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; import com.google.refine.operations.cell.FillDownOperation; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; import com.google.refine.process.Process; public class FillDownTests extends RefineTest { Project project = null; + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "fill-down", FillDownOperation.class); + } + @BeforeMethod public void setUp() { project = createCSVProject( @@ -34,6 +42,17 @@ public class FillDownTests extends RefineTest { ProjectManager.singleton.deleteProject(project.id); } + @Test + public void serializeFillDownOperation() { + AbstractOperation op = new FillDownOperation( + new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}"), + "my key"); + TestUtils.isSerializedTo(op, "{\"op\":\"core/fill-down\"," + + "\"description\":\"Fill down cells in column my key\"," + + "\"engineConfig\":{\"mode\":\"record-based\",\"facets\":[]}," + + "\"columnName\":\"my key\"}"); + } + @Test public void testFillDownRecordKey() throws Exception { AbstractOperation op = new FillDownOperation( diff --git a/main/tests/server/src/com/google/refine/tests/operations/cell/JoinMultiValuedCellsTests.java b/main/tests/server/src/com/google/refine/tests/operations/cell/JoinMultiValuedCellsTests.java index fbac646cf..ad5d3d612 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/cell/JoinMultiValuedCellsTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/cell/JoinMultiValuedCellsTests.java @@ -35,16 +35,21 @@ package com.google.refine.tests.operations.cell; import java.util.Properties; +import org.json.JSONObject; import org.slf4j.LoggerFactory; import org.testng.Assert; +import org.testng.annotations.BeforeSuite; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.refine.model.AbstractOperation; import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.cell.BlankDownOperation; import com.google.refine.operations.cell.MultiValuedCellJoinOperation; import com.google.refine.process.Process; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; public class JoinMultiValuedCellsTests extends RefineTest { @@ -54,6 +59,25 @@ public class JoinMultiValuedCellsTests extends RefineTest { public void init() { logger = LoggerFactory.getLogger(this.getClass()); } + + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "multivalued-cell-join", MultiValuedCellJoinOperation.class); + } + + @Test + public void serializeMultiValuedCellJoinOperation() { + AbstractOperation op = new MultiValuedCellJoinOperation( + "value column", + "key column", + ","); + TestUtils.isSerializedTo(op, "{\"op\":\"core/multivalued-cell-join\"," + + "\"description\":\"Join multi-valued cells in column value column\"," + + "\"columnName\":\"value column\"," + + "\"keyColumnName\":\"key column\"," + + "\"separator\":\",\"}"); + } + /* * Test to demonstrate the intended behaviour of the function diff --git a/main/tests/server/src/com/google/refine/tests/operations/cell/KeyValueColumnizeTests.java b/main/tests/server/src/com/google/refine/tests/operations/cell/KeyValueColumnizeTests.java index 3df3d868a..5e70c6815 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/cell/KeyValueColumnizeTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/cell/KeyValueColumnizeTests.java @@ -61,6 +61,8 @@ import com.google.refine.model.AbstractOperation; import com.google.refine.model.ModelException; import com.google.refine.model.Project; import com.google.refine.model.metadata.ProjectMetadata; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.cell.BlankDownOperation; import com.google.refine.operations.cell.KeyValueColumnizeOperation; import com.google.refine.process.Process; import com.google.refine.tests.RefineServletStub; @@ -94,6 +96,7 @@ public class KeyValueColumnizeTests extends RefineTest { pm.setName("KeyValueColumnize test"); ProjectManager.singleton.registerProject(project, pm); options = mock(JSONObject.class); + OperationRegistry.registerOperation(getCoreModule(), "key-value-columnize", KeyValueColumnizeOperation.class); ImportingManager.initialize(servlet); job = ImportingManager.createJob(); @@ -109,7 +112,74 @@ public class KeyValueColumnizeTests extends RefineTest { pm = null; options = null; } + + @Test + public void serializeKeyValueColumnizeOperation() { + AbstractOperation op = new KeyValueColumnizeOperation("key column", "value column", null); + TestUtils.isSerializedTo(op, "{\"op\":\"core/key-value-columnize\",\"description\":\"Columnize by key column key column and value column value column\",\"keyColumnName\":\"key column\",\"valueColumnName\":\"value column\",\"noteColumnName\":null}"); + op = new KeyValueColumnizeOperation("key column", "value column", "note column"); + TestUtils.isSerializedTo(op, "{\"op\":\"core/key-value-columnize\"," + + "\"description\":\"Columnize by key column key column and value column value column with note column note column\"," + + "\"keyColumnName\":\"key column\"," + + "\"valueColumnName\":\"value column\"," + + "\"noteColumnName\":\"note column\"}"); + } + /** + * 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"); + } + /** * Test to demonstrate the intended behaviour of the function, for issue #1214 * https://github.com/OpenRefine/OpenRefine/issues/1214 diff --git a/main/tests/server/src/com/google/refine/tests/operations/cell/MassOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/cell/MassOperationTests.java index f4fe82a27..bc8bb6e8c 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/cell/MassOperationTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/cell/MassOperationTests.java @@ -2,18 +2,43 @@ package com.google.refine.tests.operations.cell; import java.util.List; +import org.json.JSONException; +import org.json.JSONObject; import org.testng.Assert; +import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; +import com.google.refine.model.AbstractOperation; +import com.google.refine.operations.OperationRegistry; import com.google.refine.operations.cell.MassEditOperation; import com.google.refine.operations.cell.MassEditOperation.Edit; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; import com.google.refine.util.ParsingUtilities; public class MassOperationTests extends RefineTest { private List editList; private String editsString; + + @BeforeSuite + public void setUp() { + OperationRegistry.registerOperation(getCoreModule(), "mass-edit", MassEditOperation.class); + } + + @Test + public void serializeMassEditOperation() throws JSONException, Exception { + editsString = "[{\"from\":[\"String\"],\"to\":\"newString\",\"type\":\"text\"}]"; + + editList = MassEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString)); + JSONObject engineConfig = new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}"); + AbstractOperation op = new MassEditOperation(engineConfig, "my column", "value", editList); + TestUtils.isSerializedTo(op, "{\"op\":\"core/mass-edit\"," + + "\"description\":\"Mass edit cells in column my column\"," + + "\"engineConfig\":{\"mode\":\"record-based\",\"facets\":[]}," + + "\"columnName\":\"my column\",\"expression\":\"value\"," + + "\"edits\":[{\"fromBlank\":false,\"fromError\":false,\"from\":[\"String\"],\"to\":\"newString\"}]}"); + } @Test public void testReconstructEditString() throws Exception { diff --git a/main/tests/server/src/com/google/refine/tests/operations/cell/SplitMultiValuedCellsTests.java b/main/tests/server/src/com/google/refine/tests/operations/cell/SplitMultiValuedCellsTests.java index d4d8fc6f0..6dca22f64 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/cell/SplitMultiValuedCellsTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/cell/SplitMultiValuedCellsTests.java @@ -44,8 +44,11 @@ import org.testng.annotations.Test; import com.google.refine.model.AbstractOperation; import com.google.refine.model.Project; import com.google.refine.process.Process; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.cell.BlankDownOperation; import com.google.refine.operations.cell.MultiValuedCellSplitOperation; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; public class SplitMultiValuedCellsTests extends RefineTest { @@ -54,6 +57,23 @@ public class SplitMultiValuedCellsTests extends RefineTest { @BeforeTest public void init() { logger = LoggerFactory.getLogger(this.getClass()); + OperationRegistry.registerOperation(getCoreModule(), "multivalued-cell-split", MultiValuedCellSplitOperation.class); + } + + @Test + public void serializeMultiValuedCellSplitOperation() { + AbstractOperation op = new MultiValuedCellSplitOperation( + "Value", + "Key", + ":", + false); + TestUtils.isSerializedTo(op, "{\"op\":\"core/multivalued-cell-split\"," + + "\"description\":\"Split multi-valued cells in column Value\"," + + "\"columnName\":\"Value\"," + + "\"keyColumnName\":\"Key\"," + + "\"mode\":\"separator\"," + + "\"separator\":\":\"," + + "\"regex\":false}"); } /** diff --git a/main/tests/server/src/com/google/refine/tests/operations/cell/TransposeTests.java b/main/tests/server/src/com/google/refine/tests/operations/cell/TransposeTests.java index fba73147d..0ed17c369 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/cell/TransposeTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/cell/TransposeTests.java @@ -33,7 +33,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.tests.operations.cell; -import java.util.Properties; import org.slf4j.LoggerFactory; import org.testng.Assert; @@ -41,11 +40,12 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.refine.model.AbstractOperation; -import com.google.refine.model.Project; -import com.google.refine.model.metadata.ProjectMetadata; -import com.google.refine.operations.cell.KeyValueColumnizeOperation; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.cell.BlankDownOperation; +import com.google.refine.operations.cell.TransposeRowsIntoColumnsOperation; import com.google.refine.process.Process; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; public class TransposeTests extends RefineTest { @@ -53,99 +53,16 @@ public class TransposeTests extends RefineTest { @BeforeTest public void init() { logger = LoggerFactory.getLogger(this.getClass()); - } - - /** - * 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"); + OperationRegistry.registerOperation(getCoreModule(), "transpose-rows-into-columns", TransposeRowsIntoColumnsOperation.class); } - /** - * Test to demonstrate the intended behaviour of the function when no id is available, for issue #1214 - * https://github.com/OpenRefine/OpenRefine/issues/1214 - */ @Test - public void testKeyValueColumnizeWithoutID() throws Exception { - Project project = createCSVProject( - "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"); - - 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"); + public void testTransposeRowsIntoColumnsOperation() { + AbstractOperation op = new TransposeRowsIntoColumnsOperation("start column", 3); + TestUtils.isSerializedTo(op, "{\"op\":\"core/transpose-rows-into-columns\"," + + "\"description\":\"Transpose every 3 cells in column start column into separate columns\"," + + "\"columnName\":\"start column\"," + + "\"rowCount\":3}"); } + } diff --git a/main/tests/server/src/com/google/refine/tests/operations/column/ColumnMoveOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/column/ColumnMoveOperationTests.java new file mode 100644 index 000000000..466c1489d --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/column/ColumnMoveOperationTests.java @@ -0,0 +1,28 @@ +package com.google.refine.tests.operations.column; + +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.AbstractOperation; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.cell.BlankDownOperation; +import com.google.refine.operations.column.ColumnMoveOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class ColumnMoveOperationTests extends RefineTest { + + @BeforeSuite + public void setUp() { + OperationRegistry.registerOperation(getCoreModule(), "column-move", ColumnMoveOperation.class); + } + + @Test + public void serializeColumnMoveOperation() { + AbstractOperation op = new ColumnMoveOperation("my column", 3); + TestUtils.isSerializedTo(op, "{\"op\":\"core/column-move\"," + + "\"description\":\"Move column my column to position 3\"," + + "\"columnName\":\"my column\"," + + "\"index\":3}"); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/operations/column/ColumnRemovalOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/column/ColumnRemovalOperationTests.java new file mode 100644 index 000000000..fd692cc85 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/column/ColumnRemovalOperationTests.java @@ -0,0 +1,28 @@ +package com.google.refine.tests.operations.column; + +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.AbstractOperation; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.column.ColumnMoveOperation; +import com.google.refine.operations.column.ColumnRemovalOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + + +public class ColumnRemovalOperationTests extends RefineTest { + + @BeforeSuite + public void setUp() { + OperationRegistry.registerOperation(getCoreModule(), "column-removal", ColumnRemovalOperation.class); + } + + @Test + public void serializeColumnRemovalOperation() { + AbstractOperation op = new ColumnRemovalOperation("my column"); + TestUtils.isSerializedTo(op, "{\"op\":\"core/column-removal\"," + + "\"description\":\"Remove column my column\"," + + "\"columnName\":\"my column\"}"); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/operations/column/ColumnRenameOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/column/ColumnRenameOperationTests.java new file mode 100644 index 000000000..1e17ece03 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/column/ColumnRenameOperationTests.java @@ -0,0 +1,29 @@ +package com.google.refine.tests.operations.column; + +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.AbstractOperation; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.column.ColumnMoveOperation; +import com.google.refine.operations.column.ColumnRenameOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + + +public class ColumnRenameOperationTests extends RefineTest { + + @BeforeSuite + public void setUp() { + OperationRegistry.registerOperation(getCoreModule(), "column-rename", ColumnRenameOperation.class); + } + + @Test + public void serializeColumnRenameOperation() { + AbstractOperation op = new ColumnRenameOperation("old name", "new name"); + TestUtils.isSerializedTo(op, "{\"op\":\"core/column-rename\"," + + "\"description\":\"Rename column old name to new name\"," + + "\"oldColumnName\":\"old name\"," + + "\"newColumnName\":\"new name\"}"); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/operations/column/ColumnReorderOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/column/ColumnReorderOperationTests.java new file mode 100644 index 000000000..7a66884be --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/column/ColumnReorderOperationTests.java @@ -0,0 +1,30 @@ +package com.google.refine.tests.operations.column; + +import java.util.Arrays; + +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.AbstractOperation; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.column.ColumnMoveOperation; +import com.google.refine.operations.column.ColumnReorderOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + + +public class ColumnReorderOperationTests extends RefineTest { + + @BeforeSuite + public void setUp() { + OperationRegistry.registerOperation(getCoreModule(), "column-reorder", ColumnReorderOperation.class); + } + + @Test + public void serializeColumnReorderOperation() { + AbstractOperation op = new ColumnReorderOperation(Arrays.asList("b","c","a")); + TestUtils.isSerializedTo(op, "{\"op\":\"core/column-reorder\"," + + "\"description\":\"Reorder columns\"," + + "\"columnNames\":[\"b\",\"c\",\"a\"]}"); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/operations/cell/ReconJudgeSimilarCellsTests.java b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsTests.java similarity index 66% rename from main/tests/server/src/com/google/refine/tests/operations/cell/ReconJudgeSimilarCellsTests.java rename to main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsTests.java index 043ea3bf1..dd304ff45 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/cell/ReconJudgeSimilarCellsTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsTests.java @@ -1,4 +1,4 @@ -package com.google.refine.tests.operations.cell; +package com.google.refine.tests.operations.recon; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; @@ -8,6 +8,7 @@ import java.util.Properties; import org.json.JSONObject; import org.slf4j.LoggerFactory; +import org.testng.annotations.BeforeSuite; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -18,9 +19,12 @@ import com.google.refine.model.Project; import com.google.refine.model.Recon; import com.google.refine.model.recon.ReconConfig; import com.google.refine.model.recon.StandardReconConfig; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.column.ColumnMoveOperation; import com.google.refine.operations.recon.ReconJudgeSimilarCellsOperation; import com.google.refine.process.Process; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; public class ReconJudgeSimilarCellsTests extends RefineTest { @@ -30,6 +34,24 @@ public class ReconJudgeSimilarCellsTests extends RefineTest { @BeforeTest public void init() { logger = LoggerFactory.getLogger(this.getClass()); + OperationRegistry.registerOperation(getCoreModule(), "recon-judge-similar-cells", ReconJudgeSimilarCellsOperation.class); + } + + @Test + public void serializeReconJudgeSimilarCellsOperation() { + AbstractOperation op = new ReconJudgeSimilarCellsOperation( + ENGINE_CONFIG, + "A", + "foo", + Recon.Judgment.New, + null, true); + TestUtils.isSerializedTo(op, "{\"op\":\"core/recon-judge-similar-cells\"," + + "\"description\":\"Mark to create one single new item for all cells containing \\\"foo\\\" in column A\"," + + "\"engineConfig\":{\"mode\":\"row-based\"}," + + "\"columnName\":\"A\"," + + "\"similarValue\":\"foo\"," + + "\"judgment\":\"new\"," + + "\"shareNewTopics\":true}"); } @Test diff --git a/main/tests/server/src/com/google/refine/tests/operations/row/DenormalizeOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/row/DenormalizeOperationTests.java new file mode 100644 index 000000000..066edcb7b --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/row/DenormalizeOperationTests.java @@ -0,0 +1,27 @@ +package com.google.refine.tests.operations.row; + +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.AbstractOperation; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.cell.MultiValuedCellSplitOperation; +import com.google.refine.operations.row.DenormalizeOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + + +public class DenormalizeOperationTests extends RefineTest { + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "denormalize", DenormalizeOperation.class); + } + + @Test + public void serializeDenormalizeOperation() { + AbstractOperation op = new DenormalizeOperation(); + TestUtils.isSerializedTo(op, "{" + + "\"op\":\"core/denormalize\"," + + "\"description\":\"Denormalize\"}"); + } +}