From 256a81e30899ba5c64bcf2b5ec9bb49d0d7283b1 Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Sat, 2 Jun 2018 23:08:49 +0100 Subject: [PATCH 1/5] Initial MassOperationTests Corrected and expanded tests for ReconstructEdit Improve tests --- .../operations/cell/MassOperationTests.java | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 main/tests/server/src/com/google/refine/tests/operations/cell/MassOperationTests.java 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 new file mode 100644 index 000000000..81b9fcf3e --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/cell/MassOperationTests.java @@ -0,0 +1,110 @@ +package com.google.refine.tests.operations.cell; + +import java.util.List; + +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +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.util.ParsingUtilities; + +public class MassOperationTests extends RefineTest { + + List editList; + String editsString = null; + + @BeforeMethod + public void setUp() { + } + + @AfterMethod + public void tearDown() { + } + + @Test + public void testReconstructEditString() throws Exception { + editsString = "[{\"from\":[\"String\"],\"to\":\"newString\",\"type\":\"text\"}]"; + + editList = MassEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString)); + + Assert.assertEquals(editList.get(0).from.size(), 1); + Assert.assertEquals(editList.get(0).from.get(0), "String"); + Assert.assertEquals(editList.get(0).to,"newString" ); + Assert.assertFalse(editList.get(0).fromBlank); + Assert.assertFalse(editList.get(0).fromError); + } + + @Test + public void testReconstructEditMultiString() throws Exception { + editsString = "[{\"from\":[\"String1\",\"String2\"],\"to\":\"newString\",\"type\":\"text\"}]"; + + editList = MassEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString)); + + Assert.assertEquals(editList.get(0).from.size(), 2); + Assert.assertEquals(editList.get(0).from.get(0), "String1"); + Assert.assertEquals(editList.get(0).from.get(1), "String2"); + Assert.assertEquals(editList.get(0).to,"newString" ); + Assert.assertFalse(editList.get(0).fromBlank); + Assert.assertFalse(editList.get(0).fromError); + } + + @Test + public void testReconstructEditBoolean() throws Exception { + editsString = "[{\"from\":[true],\"to\":\"newString\",\"type\":\"text\"}]"; + + editList = MassEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString)); + + Assert.assertEquals(editList.get(0).from.size(), 1); + Assert.assertEquals(editList.get(0).from.get(0), "true"); + Assert.assertEquals(editList.get(0).to,"newString" ); + Assert.assertFalse(editList.get(0).fromBlank); + Assert.assertFalse(editList.get(0).fromError); + } + + @Test + public void testReconstructEditNumber() throws Exception { + editsString = "[{\"from\":[1],\"to\":\"newString\",\"type\":\"text\"}]"; + + editList = MassEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString)); + + Assert.assertEquals(editList.get(0).from.size(), 1); + Assert.assertEquals(editList.get(0).from.get(0), "1"); + Assert.assertEquals(editList.get(0).to,"newString" ); + Assert.assertFalse(editList.get(0).fromBlank); + Assert.assertFalse(editList.get(0).fromError); + } + + @Test + public void testReconstructEditDate() throws Exception { + editsString = "[{\"from\":[\"2018-10-04T00:00:00Z\"],\"to\":\"newString\",\"type\":\"text\"}]"; + + editList = MassEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString)); + + Assert.assertEquals(editList.get(0).from.size(), 1); + Assert.assertEquals(editList.get(0).from.get(0), "2018-10-04T00:00Z"); + Assert.assertEquals(editList.get(0).to,"newString" ); + Assert.assertFalse(editList.get(0).fromBlank); + Assert.assertFalse(editList.get(0).fromError); + } + + @Test + public void testReconstructEditEmpty() throws Exception { + editsString = "[{\"from\":[\"\"],\"to\":\"newString\",\"type\":\"text\"}]"; + + editList = MassEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString)); + + Assert.assertEquals(editList.get(0).from.size(), 1); + Assert.assertEquals(editList.get(0).from.get(0), ""); + Assert.assertEquals(editList.get(0).to,"newString" ); + Assert.assertTrue(editList.get(0).fromBlank); + Assert.assertFalse(editList.get(0).fromError); + + } + + //Not yet testing for editing a cell containing an OR error + +} From 689442fff2bee4a8c6aae40ac155b100b88ee103 Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Wed, 6 Jun 2018 16:34:52 +0100 Subject: [PATCH 2/5] If only one value and that's zero length set fromBlank to true Added whitespace --- .../com/google/refine/operations/cell/MassEditOperation.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/src/com/google/refine/operations/cell/MassEditOperation.java b/main/src/com/google/refine/operations/cell/MassEditOperation.java index a5ef0e84c..a37374ab7 100644 --- a/main/src/com/google/refine/operations/cell/MassEditOperation.java +++ b/main/src/com/google/refine/operations/cell/MassEditOperation.java @@ -121,13 +121,13 @@ public class MassEditOperation extends EngineDependentMassCellOperation { from = new ArrayList(fromCount); for (int j = 0; j < fromCount; j++) { - from.add(fromA.getString(j)); + from.add(fromA.get(j).toString()); } } else { from = new ArrayList(); } - boolean fromBlank = editO.has("fromBlank") && editO.getBoolean("fromBlank"); + boolean fromBlank = (editO.has("fromBlank") && editO.getBoolean("fromBlank") || from.get(0).length() == 0 && from.size() == 1); boolean fromError = editO.has("fromError") && editO.getBoolean("fromError"); Serializable to = (Serializable) editO.get("to"); From 97ea151134466f1309af612b26dd52666be00585 Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Fri, 8 Jun 2018 08:22:57 +0100 Subject: [PATCH 3/5] Removed date tests --- .../operations/cell/MassOperationTests.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) 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 81b9fcf3e..b592efcf9 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 @@ -78,19 +78,6 @@ public class MassOperationTests extends RefineTest { Assert.assertFalse(editList.get(0).fromError); } - @Test - public void testReconstructEditDate() throws Exception { - editsString = "[{\"from\":[\"2018-10-04T00:00:00Z\"],\"to\":\"newString\",\"type\":\"text\"}]"; - - editList = MassEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString)); - - Assert.assertEquals(editList.get(0).from.size(), 1); - Assert.assertEquals(editList.get(0).from.get(0), "2018-10-04T00:00Z"); - Assert.assertEquals(editList.get(0).to,"newString" ); - Assert.assertFalse(editList.get(0).fromBlank); - Assert.assertFalse(editList.get(0).fromError); - } - @Test public void testReconstructEditEmpty() throws Exception { editsString = "[{\"from\":[\"\"],\"to\":\"newString\",\"type\":\"text\"}]"; @@ -105,6 +92,7 @@ public class MassOperationTests extends RefineTest { } - //Not yet testing for editing a cell containing an OR error + //Not yet testing for mass edit from OR Error + //Not yet testing for mass edit from OR Date } From 2e9708c16db925ae9b09a61081bebf126f8e832e Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Fri, 8 Jun 2018 20:03:38 +0100 Subject: [PATCH 4/5] Tidying up test file --- .../tests/operations/cell/MassOperationTests.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) 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 b592efcf9..743e2f5c9 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 @@ -14,16 +14,8 @@ import com.google.refine.util.ParsingUtilities; public class MassOperationTests extends RefineTest { - List editList; - String editsString = null; - - @BeforeMethod - public void setUp() { - } - - @AfterMethod - public void tearDown() { - } + private List editList; + private String editsString = null; @Test public void testReconstructEditString() throws Exception { From 92e456d2ffb4fc1f2306b3aec9c9c49023429736 Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Fri, 8 Jun 2018 20:09:29 +0100 Subject: [PATCH 5/5] More tidying of tests --- .../refine/tests/operations/cell/MassOperationTests.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 743e2f5c9..2bc659dac 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 @@ -3,8 +3,6 @@ package com.google.refine.tests.operations.cell; import java.util.List; import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import com.google.refine.operations.cell.MassEditOperation; @@ -15,7 +13,7 @@ import com.google.refine.util.ParsingUtilities; public class MassOperationTests extends RefineTest { private List editList; - private String editsString = null; + private String editsString; @Test public void testReconstructEditString() throws Exception {