From f41678e087fcf3197660c38c4a6bd618cfc502ce Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Wed, 8 Aug 2018 10:58:25 +0100 Subject: [PATCH 01/26] Move tests to their relevant package. --- .../{tests/model => operations/column}/UrlFetchingTests.java | 2 +- .../com/google/refine/tests/model/{ => recon}/ReconTests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename main/tests/server/src/com/google/refine/{tests/model => operations/column}/UrlFetchingTests.java (99%) rename main/tests/server/src/com/google/refine/tests/model/{ => recon}/ReconTests.java (98%) diff --git a/main/tests/server/src/com/google/refine/tests/model/UrlFetchingTests.java b/main/tests/server/src/com/google/refine/operations/column/UrlFetchingTests.java similarity index 99% rename from main/tests/server/src/com/google/refine/tests/model/UrlFetchingTests.java rename to main/tests/server/src/com/google/refine/operations/column/UrlFetchingTests.java index d35f25169..36ccefc08 100644 --- a/main/tests/server/src/com/google/refine/tests/model/UrlFetchingTests.java +++ b/main/tests/server/src/com/google/refine/operations/column/UrlFetchingTests.java @@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.google.refine.tests.model; +package com.google.refine.operations.column; import java.io.IOException; import java.net.InetAddress; diff --git a/main/tests/server/src/com/google/refine/tests/model/ReconTests.java b/main/tests/server/src/com/google/refine/tests/model/recon/ReconTests.java similarity index 98% rename from main/tests/server/src/com/google/refine/tests/model/ReconTests.java rename to main/tests/server/src/com/google/refine/tests/model/recon/ReconTests.java index 5d6466c99..a60de0294 100644 --- a/main/tests/server/src/com/google/refine/tests/model/ReconTests.java +++ b/main/tests/server/src/com/google/refine/tests/model/recon/ReconTests.java @@ -1,4 +1,4 @@ -package com.google.refine.tests.model; +package com.google.refine.tests.model.recon; import java.util.ArrayList; From 3ea18227734b5fef5c17e34aab9f575e71d3d055 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Wed, 8 Aug 2018 11:04:42 +0100 Subject: [PATCH 02/26] Remove duplicate test class introduced by Jacky --- .../tests/model/TextSearchFacetTests.java | 265 ------------------ 1 file changed, 265 deletions(-) delete mode 100644 main/tests/server/src/com/google/refine/tests/model/TextSearchFacetTests.java diff --git a/main/tests/server/src/com/google/refine/tests/model/TextSearchFacetTests.java b/main/tests/server/src/com/google/refine/tests/model/TextSearchFacetTests.java deleted file mode 100644 index 85a30b63d..000000000 --- a/main/tests/server/src/com/google/refine/tests/model/TextSearchFacetTests.java +++ /dev/null @@ -1,265 +0,0 @@ -/* - -Copyright 2010, Google Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ - -package com.google.refine.tests.model; - -import static org.mockito.Mockito.mock; - -import java.io.File; -import java.io.IOException; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.List; - -import org.json.JSONException; -import org.json.JSONObject; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.refine.ProjectManager; -import com.google.refine.RefineServlet; -import com.google.refine.browsing.RowFilter; -import com.google.refine.browsing.facets.TextSearchFacet; -import com.google.refine.importers.SeparatorBasedImporter; -import com.google.refine.importing.ImportingJob; -import com.google.refine.importing.ImportingManager; -import com.google.refine.io.FileProjectManager; -import com.google.refine.model.ModelException; -import com.google.refine.model.Project; -import com.google.refine.model.metadata.ProjectMetadata; -import com.google.refine.tests.RefineServletStub; -import com.google.refine.tests.RefineTest; -import com.google.refine.tests.util.TestUtils; - - -public class TextSearchFacetTests extends RefineTest { - // dependencies - private RefineServlet servlet; - private Project project; - private ProjectMetadata pm; - private JSONObject options; - private ImportingJob job; - private SeparatorBasedImporter importer; - private TextSearchFacet textfilter; - private JSONObject textsearchfacet; - private RowFilter rowfilter; - - @Override - @BeforeTest - public void init() { - logger = LoggerFactory.getLogger(this.getClass()); - } - - @BeforeMethod - public void setUp() throws JSONException, IOException, ModelException { - servlet = new RefineServletStub(); - File dir = TestUtils.createTempDirectory("openrefine-test-workspace-dir"); - FileProjectManager.initialize(dir); - project = new Project(); - pm = new ProjectMetadata(); - pm.setName("TextSearchFacet test"); - ProjectManager.singleton.registerProject(project, pm); - options = mock(JSONObject.class); - - ImportingManager.initialize(servlet); - job = ImportingManager.createJob(); - importer = new SeparatorBasedImporter(); - - String csv = "Value\n" - + "a\n" - + "b\n" - + "ab\n" - + "Abc\n"; - prepareOptions(",", 10, 0, 0, 1, false, false); - List exceptions = new ArrayList(); - importer.parseOneFile(project, pm, job, "filesource", new StringReader(csv), -1, options, exceptions); - project.update(); - ProjectManager.singleton.registerProject(project, pm); - } - - @AfterMethod - public void tearDown() { - ImportingManager.disposeJob(job.id); - ProjectManager.singleton.deleteProject(project.id); - job = null; - project = null; - pm = null; - options = null; - } - - /** - * Test to demonstrate the intended behaviour of the function - */ - - @Test - public void testTextFilter() throws Exception { - //Apply text filter "a" - - //Column: "Value" - //Filter Query: "a" - //Mode: "text" - //Case sensitive: False - //Invert: False - String filter = "{\"type\":\"text\"," - + "\"name\":\"Value\"," - + "\"columnName\":\"Value\"," - + "\"mode\":\"text\"," - + "\"caseSensitive\":false," - + "\"invert\":false," - + "\"query\":\"a\"}"; - - //Add the facet to the project and create a row filter - textfilter = new TextSearchFacet(); - textsearchfacet = new JSONObject(filter); - textfilter.initializeFromJSON(project,textsearchfacet); - rowfilter = textfilter.getRowFilter(project); - - //Check each row in the project against the filter - Assert.assertEquals(rowfilter.filterRow(project, 0, project.rows.get(0)),true); - Assert.assertEquals(rowfilter.filterRow(project, 1, project.rows.get(1)),false); - Assert.assertEquals(rowfilter.filterRow(project, 2, project.rows.get(2)),true); - Assert.assertEquals(rowfilter.filterRow(project, 3, project.rows.get(3)),true); - } - - @Test - public void testInvertedTextFilter() throws Exception { - //Apply inverted text filter "a" - - //Column: "Value" - //Filter Query: "a" - //Mode: "text" - //Case sensitive: False - //Invert: True - String filter = "{\"type\":\"text\"," - + "\"name\":\"Value\"," - + "\"columnName\":\"Value\"," - + "\"mode\":\"text\"," - + "\"caseSensitive\":false," - + "\"invert\":true," - + "\"query\":\"a\"}"; - - //Add the facet to the project and create a row filter - textfilter = new TextSearchFacet(); - textsearchfacet = new JSONObject(filter); - textfilter.initializeFromJSON(project,textsearchfacet); - rowfilter = textfilter.getRowFilter(project); - - //Check each row in the project against the filter - Assert.assertEquals(rowfilter.filterRow(project, 0, project.rows.get(0)),false); - Assert.assertEquals(rowfilter.filterRow(project, 1, project.rows.get(1)),true); - Assert.assertEquals(rowfilter.filterRow(project, 2, project.rows.get(2)),false); - Assert.assertEquals(rowfilter.filterRow(project, 3, project.rows.get(3)),false); - } - - @Test - public void testRegExFilter() throws Exception { - //Apply regular expression filter "[bc]" - - //Column: "Value" - //Filter Query: "[bc]" - //Mode: "regex" - //Case sensitive: False - //Invert: False - String filter = "{\"type\":\"text\"," - + "\"name\":\"Value\"," - + "\"columnName\":\"Value\"," - + "\"mode\":\"regex\"," - + "\"caseSensitive\":false," - + "\"invert\":false," - + "\"query\":\"[bc]\"}"; - - //Add the facet to the project and create a row filter - textfilter = new TextSearchFacet(); - textsearchfacet = new JSONObject(filter); - textfilter.initializeFromJSON(project,textsearchfacet); - rowfilter = textfilter.getRowFilter(project); - - //Check each row in the project against the filter - Assert.assertEquals(rowfilter.filterRow(project, 0, project.rows.get(0)),false); - Assert.assertEquals(rowfilter.filterRow(project, 1, project.rows.get(1)),true); - Assert.assertEquals(rowfilter.filterRow(project, 2, project.rows.get(2)),true); - Assert.assertEquals(rowfilter.filterRow(project, 3, project.rows.get(3)),true); - } - - @Test - public void testCaseSensitiveFilter() throws Exception { - //Apply case-sensitive filter "A" - - //Column: "Value" - //Filter Query: "A" - //Mode: "text" - //Case sensitive: True - //Invert: False - String filter = "{\"type\":\"text\"," - + "\"name\":\"Value\"," - + "\"columnName\":\"Value\"," - + "\"mode\":\"text\"," - + "\"caseSensitive\":true," - + "\"invert\":false," - + "\"query\":\"A\"}"; - - //Add the facet to the project and create a row filter - textfilter = new TextSearchFacet(); - textsearchfacet = new JSONObject(filter); - textfilter.initializeFromJSON(project,textsearchfacet); - rowfilter = textfilter.getRowFilter(project); - - //Check each row in the project against the filter - //Expect to retrieve one row containing "Abc" - Assert.assertEquals(rowfilter.filterRow(project, 0, project.rows.get(0)),false); - Assert.assertEquals(rowfilter.filterRow(project, 1, project.rows.get(1)),false); - Assert.assertEquals(rowfilter.filterRow(project, 2, project.rows.get(2)),false); - Assert.assertEquals(rowfilter.filterRow(project, 3, project.rows.get(3)),true); - } - - private void prepareOptions( - String sep, int limit, int skip, int ignoreLines, - int headerLines, boolean guessValueType, boolean ignoreQuotes) { - - whenGetStringOption("separator", options, sep); - whenGetIntegerOption("limit", options, limit); - whenGetIntegerOption("skipDataLines", options, skip); - whenGetIntegerOption("ignoreLines", options, ignoreLines); - whenGetIntegerOption("headerLines", options, headerLines); - whenGetBooleanOption("guessCellValueTypes", options, guessValueType); - whenGetBooleanOption("processQuotes", options, !ignoreQuotes); - whenGetBooleanOption("storeBlankCellsAsNulls", options, true); - } - - -} - From b12b29b393e68d0224c0c06646977b4dd18e2108 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Wed, 8 Aug 2018 11:45:16 +0100 Subject: [PATCH 03/26] Rename ReconTests --- .../recon/{ReconTests.java => StandardReconConfigTests.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename main/tests/server/src/com/google/refine/tests/model/recon/{ReconTests.java => StandardReconConfigTests.java} (100%) diff --git a/main/tests/server/src/com/google/refine/tests/model/recon/ReconTests.java b/main/tests/server/src/com/google/refine/tests/model/recon/StandardReconConfigTests.java similarity index 100% rename from main/tests/server/src/com/google/refine/tests/model/recon/ReconTests.java rename to main/tests/server/src/com/google/refine/tests/model/recon/StandardReconConfigTests.java From 2b57350adf7e54b65074533208e2fb870413f964 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Wed, 8 Aug 2018 11:46:05 +0100 Subject: [PATCH 04/26] Cleanup StandardReconConfigTests --- .../model/recon/StandardReconConfigTests.java | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/main/tests/server/src/com/google/refine/tests/model/recon/StandardReconConfigTests.java b/main/tests/server/src/com/google/refine/tests/model/recon/StandardReconConfigTests.java index a60de0294..6f02bbb46 100644 --- a/main/tests/server/src/com/google/refine/tests/model/recon/StandardReconConfigTests.java +++ b/main/tests/server/src/com/google/refine/tests/model/recon/StandardReconConfigTests.java @@ -2,6 +2,7 @@ package com.google.refine.tests.model.recon; import java.util.ArrayList; +import org.json.JSONException; import org.json.JSONObject; import org.slf4j.LoggerFactory; import org.testng.Assert; @@ -11,8 +12,9 @@ import org.testng.annotations.Test; import com.google.refine.model.recon.ReconConfig; import com.google.refine.model.recon.StandardReconConfig; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; -public class ReconTests extends RefineTest { +public class StandardReconConfigTests extends RefineTest { @Override @BeforeTest @@ -20,8 +22,8 @@ public class ReconTests extends RefineTest { logger = LoggerFactory.getLogger(this.getClass()); } - private class StandardReconConfigTest extends StandardReconConfig { - public StandardReconConfigTest() { + private class StandardReconConfigStub extends StandardReconConfig { + public StandardReconConfigStub() { super("", "", "", "", "", false, new ArrayList()); } @@ -32,30 +34,24 @@ public class ReconTests extends RefineTest { @Test public void wordDistance() { - StandardReconConfigTest t = new StandardReconConfigTest(); + StandardReconConfigStub t = new StandardReconConfigStub(); double r = t.wordDistanceTest("Foo", "Foo bar"); - Assert.assertEquals(r,0.5); + Assert.assertEquals(0.5, r); } @Test public void wordDistanceOnlyStopwords() { - StandardReconConfigTest t = new StandardReconConfigTest(); + StandardReconConfigStub t = new StandardReconConfigStub(); double r = t.wordDistanceTest("On and On", "On and On and On"); Assert.assertTrue(!Double.isInfinite(r)); Assert.assertTrue(!Double.isNaN(r)); } - /** - * Regression for issue #1517: - * JSON deserialization exception due to the upgrade of org.json library in data package PR - * @throws Exception - */ @Test - public void limitJSONKeyTest() throws Exception { - JSONObject obj = new JSONObject( - " {\n" + + public void serializeStandardReconConfig() throws Exception { + String json = " {\n" + " \"mode\": \"standard-service\",\n" + " \"service\": \"https://tools.wmflabs.org/openrefine-wikidata/en/api\",\n" + " \"identifierSpace\": \"http://www.wikidata.org/entity/\",\n" + @@ -65,13 +61,21 @@ public class ReconTests extends RefineTest { " \"name\": \"scientific article\"\n" + " },\n" + " \"autoMatch\": true,\n" + - " \"columnDetails\": [],\n" + + " \"columnDetails\": [\n" + + " {\n" + + " \"column\": \"organization_country\",\n" + + " \"propertyName\": \"SPARQL: P17/P297\",\n" + + " \"propertyID\": \"P17/P297\"\n" + + " },\n" + + " {\n" + + " \"column\": \"organization_id\",\n" + + " \"propertyName\": \"SPARQL: P3500|P2427\",\n" + + " \"propertyID\": \"P3500|P2427\"\n" + + " }\n" + + " ],\n" + " \"limit\": 0\n" + - " }"); - - ReconConfig config = StandardReconConfig.reconstruct(obj); - - // Assert the object is created - Assert.assertTrue(config != null); + " }"; + ReconConfig config = StandardReconConfig.reconstruct(new JSONObject(json)); + TestUtils.isSerializedTo(config, json); } } From d9bff34411329a2d287febdf551bddf58eb64e1f Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Wed, 8 Aug 2018 11:49:30 +0100 Subject: [PATCH 05/26] Add testing utilites for JSON serialization --- .../google/refine/tests/util/TestUtils.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/main/tests/server/src/com/google/refine/tests/util/TestUtils.java b/main/tests/server/src/com/google/refine/tests/util/TestUtils.java index d19a10beb..54934925d 100644 --- a/main/tests/server/src/com/google/refine/tests/util/TestUtils.java +++ b/main/tests/server/src/com/google/refine/tests/util/TestUtils.java @@ -1,10 +1,30 @@ package com.google.refine.tests.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.io.File; import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Properties; + +import org.json.JSONException; +import org.json.JSONObject; +import org.json.JSONWriter; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import com.google.refine.Jsonizable; +import com.google.refine.util.ParsingUtilities; public class TestUtils { + + static ObjectMapper mapper = new ObjectMapper(); /** * Create a temporary directory. NOTE: This is a quick and dirty @@ -22,4 +42,37 @@ public class TestUtils { return dir; } + /** + * Compare two JSON strings for equality. + */ + public static void equalAsJson(String expected, String actual) { + try { + JsonNode jsonA = mapper.readValue(expected, JsonNode.class); + JsonNode jsonB = mapper.readValue(actual, JsonNode.class); + assertEquals(jsonA, jsonB); + } catch(JsonMappingException e) { + fail(e.getMessage()); + } catch (JsonParseException e) { + fail(e.getMessage()); + } catch (IOException e) { + fail(e.getMessage()); + } + } + + /** + * Checks that a serializable object is serialized to the target JSON string. + */ + public static void isSerializedTo(Jsonizable o, String targetJson, Properties options) { + Writer w = new StringWriter(); + JSONWriter jsonWriter = new JSONWriter(w); + o.write(jsonWriter, options); + equalAsJson(targetJson, w.toString()); + } + + /** + * Checks that a serializable object is serialized to the target JSON string. + */ + public static void isSerializedTo(Jsonizable o, String targetJson) { + isSerializedTo(o, targetJson, new Properties()); + } } From c6d2b003b18d4f28b3c7a915a17dfa0cf16b81fe Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Wed, 8 Aug 2018 14:38:38 +0100 Subject: [PATCH 06/26] Start serialization tests --- .../tests/model/ReconCandidateTests.java | 18 ++++++ .../refine/tests/model/ReconStatsTests.java | 15 +++++ .../google/refine/tests/model/ReconTests.java | 56 +++++++++++++++++++ .../refine/tests/model/ReconTypeTest.java | 17 ++++++ .../google/refine/tests/util/TestUtils.java | 8 +-- 5 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 main/tests/server/src/com/google/refine/tests/model/ReconCandidateTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/model/ReconStatsTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/model/ReconTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/model/ReconTypeTest.java diff --git a/main/tests/server/src/com/google/refine/tests/model/ReconCandidateTests.java b/main/tests/server/src/com/google/refine/tests/model/ReconCandidateTests.java new file mode 100644 index 000000000..88fed65e4 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/model/ReconCandidateTests.java @@ -0,0 +1,18 @@ +package com.google.refine.tests.model; + +import org.testng.annotations.Test; + +import com.google.refine.model.ReconCandidate; +import com.google.refine.tests.util.TestUtils; + +public class ReconCandidateTests { + @Test + public void serializeReconCandidate() throws Exception { + String json = "{\"id\":\"Q49213\"," + + "\"name\":\"University of Texas at Austin\"," + + "\"score\":100," + + "\"types\":[\"Q875538\",\"Q15936437\",\"Q20971972\",\"Q23002039\"]}"; + ReconCandidate rc = ReconCandidate.loadStreaming(json); + TestUtils.isSerializedTo(rc, json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/model/ReconStatsTests.java b/main/tests/server/src/com/google/refine/tests/model/ReconStatsTests.java new file mode 100644 index 000000000..9baf1b68d --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/model/ReconStatsTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.model; + +import org.testng.annotations.Test; + +import com.google.refine.model.ReconStats; +import com.google.refine.tests.util.TestUtils; + +public class ReconStatsTests { + + @Test + public void serializeReconStats() { + ReconStats rs = new ReconStats(3, 1, 2); + TestUtils.isSerializedTo(rs,"{\"nonBlanks\":3,\"newTopics\":1,\"matchedTopics\":2}"); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/model/ReconTests.java b/main/tests/server/src/com/google/refine/tests/model/ReconTests.java new file mode 100644 index 000000000..a4ad792e8 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/model/ReconTests.java @@ -0,0 +1,56 @@ +package com.google.refine.tests.model; + +import java.util.Properties; + +import org.testng.annotations.Test; + +import com.google.refine.model.Recon; +import com.google.refine.tests.util.TestUtils; + +public class ReconTests { + @Test + public void serializeRecon() throws Exception { + Properties options = new Properties(); + options.put("mode", "save"); + + String fullJson = "{\"id\":1533651559492945033," + + "\"judgmentHistoryEntry\":1533651616890," + + "\"service\":\"https://tools.wmflabs.org/openrefine-wikidata/en/api\"," + + "\"identifierSpace\":\"http://www.wikidata.org/entity/\"," + + "\"schemaSpace\":\"http://www.wikidata.org/prop/direct/\"," + + "\"j\":\"matched\"," + + "\"m\":{" + + " \"id\":\"Q2892284\"," + + " \"name\":\"Baylor College of Medicine\"," + + " \"score\":98.57142857142858," + + " \"types\":[\"Q16917\",\"Q23002054\",\"Q494230\"]" + + "}," + + "\"c\":[" + + " {\"id\":\"Q2892284\",\"name\":\"Baylor College of Medicine\",\"score\":98.57142857142858,\"types\":[\"Q16917\",\"Q23002054\",\"Q494230\"]}," + + " {\"id\":\"Q16165943\",\"name\":\"Baylor College of Medicine Academy at Ryan\",\"score\":82.14285714285715,\"types\":[\"Q149566\"]}," + + " {\"id\":\"Q30284245\",\"name\":\"Baylor College of Medicine Children\\u2019s Foundation\",\"score\":48.57142857142858,\"types\":[\"Q163740\"]}" + + "]," + + "\"f\":[false,false,1,0.6666666666666666]," + + "\"judgmentAction\":\"mass\"," + + "\"judgmentBatchSize\":1," + + "\"matchRank\":0}"; + Recon r = Recon.loadStreaming(fullJson, null); + TestUtils.isSerializedTo(r, fullJson, options); + + String shortJson = "{\"id\":1533651559492945033," + + "\"service\":\"https://tools.wmflabs.org/openrefine-wikidata/en/api\"," + + "\"identifierSpace\":\"http://www.wikidata.org/entity/\"," + + "\"schemaSpace\":\"http://www.wikidata.org/prop/direct/\"," + + "\"j\":\"matched\"," + + "\"m\":{" + + " \"id\":\"Q2892284\"," + + " \"name\":\"Baylor College of Medicine\"," + + " \"score\":98.57142857142858," + + " \"types\":[\"Q16917\",\"Q23002054\",\"Q494230\"]" + + "}}"; + options.put("mode", "normal"); + TestUtils.isSerializedTo(r, shortJson, options); + } + + +} diff --git a/main/tests/server/src/com/google/refine/tests/model/ReconTypeTest.java b/main/tests/server/src/com/google/refine/tests/model/ReconTypeTest.java new file mode 100644 index 000000000..9e66b7ca8 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/model/ReconTypeTest.java @@ -0,0 +1,17 @@ +package com.google.refine.tests.model; + +import org.json.JSONException; +import org.json.JSONObject; +import org.testng.annotations.Test; + +import com.google.refine.model.ReconType; +import com.google.refine.tests.util.TestUtils; + +public class ReconTypeTest { + @Test + public void serializeReconType() throws JSONException, Exception { + String json = "{\"id\":\"Q7540126\",\"name\":\"headquarters\"}"; + ReconType rt = ReconType.load(new JSONObject(json)); + TestUtils.isSerializedTo(rt, json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/util/TestUtils.java b/main/tests/server/src/com/google/refine/tests/util/TestUtils.java index 54934925d..54d772ffd 100644 --- a/main/tests/server/src/com/google/refine/tests/util/TestUtils.java +++ b/main/tests/server/src/com/google/refine/tests/util/TestUtils.java @@ -50,12 +50,8 @@ public class TestUtils { JsonNode jsonA = mapper.readValue(expected, JsonNode.class); JsonNode jsonB = mapper.readValue(actual, JsonNode.class); assertEquals(jsonA, jsonB); - } catch(JsonMappingException e) { - fail(e.getMessage()); - } catch (JsonParseException e) { - fail(e.getMessage()); - } catch (IOException e) { - fail(e.getMessage()); + } catch(Exception e) { + fail("\""+expected+"\" and \""+actual+"\" are not equal as JSON strings."); } } From fac89364117278b7fa6193a0c36e4d6c2c38a881 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Thu, 9 Aug 2018 14:25:09 +0100 Subject: [PATCH 07/26] Serialization tests for model classes --- .../google/refine/tests/model/CellTests.java | 79 +++++++++++++++++++ .../refine/tests/model/ColumnGroupTests.java | 42 ++++++++++ .../refine/tests/model/ColumnModelTests.java | 10 +++ .../refine/tests/model/ColumnTests.java | 47 +++++++++++ .../refine/tests/model/RecordModelTests.java | 18 +++++ .../google/refine/tests/model/RowTests.java | 36 ++++++++- 6 files changed, 230 insertions(+), 2 deletions(-) create mode 100644 main/tests/server/src/com/google/refine/tests/model/CellTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/model/ColumnGroupTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/model/ColumnModelTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/model/ColumnTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/model/RecordModelTests.java diff --git a/main/tests/server/src/com/google/refine/tests/model/CellTests.java b/main/tests/server/src/com/google/refine/tests/model/CellTests.java new file mode 100644 index 000000000..cab82c55d --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/model/CellTests.java @@ -0,0 +1,79 @@ +package com.google.refine.tests.model; + +import org.testng.annotations.Test; + +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.Properties; + +import com.google.refine.model.Cell; +import com.google.refine.model.Recon; +import com.google.refine.tests.util.TestUtils; +import com.google.refine.util.Pool; + +public class CellTests { + + String reconJson = "{\"id\":1533649346002675326," + + "\"judgmentHistoryEntry\":1530278634724," + + "\"service\":\"https://tools.wmflabs.org/openrefine-wikidata/en/api\"," + + "\"identifierSpace\":\"http://www.wikidata.org/entity/\"," + + "\"schemaSpace\":\"http://www.wikidata.org/prop/direct/\"," + + "\"j\":\"matched\"," + + "\"m\":{\"id\":\"Q551479\",\"name\":\"La Monnaie\",\"score\":100,\"types\":[\"Q153562\"]}," + + "\"c\":[{\"id\":\"Q551479\",\"name\":\"La Monnaie\",\"score\":100,\"types\":[\"Q153562\"]}]," + + "\"f\":[false,false,34,0],\"judgmentAction\":\"auto\",\"judgmentBatchSize\":1,\"matchRank\":0}"; + + Pool pool = mock(Pool.class); + Recon recon = null; + + @Test + public void serializeCellWithRecon() throws Exception { + recon = Recon.loadStreaming(reconJson, pool); + when(pool.getRecon("1533649346002675326")).thenReturn(recon); + String json = "{\"v\":\"http://www.wikidata.org/entity/Q41522540\",\"r\":\"1533649346002675326\"}"; + + Properties options = mock(Properties.class); + when(options.get("pool")).thenReturn(pool); + Cell c = Cell.loadStreaming(json, pool); + TestUtils.isSerializedTo(c, json, options); + verify(pool, times(1)).pool(recon); + } + + @Test + public void serializeCellWithString() throws Exception { + String json = "{\"v\":\"0000-0002-5022-0488\"}"; + Cell c = Cell.loadStreaming(json, pool); + TestUtils.isSerializedTo(c, json); + } + + @Test + public void serializeNullCell() throws Exception { + String json = "null"; + Cell c = Cell.loadStreaming(json, pool); + assertNull(c); + } + + @Test + public void serializeEmptyStringCell() throws Exception { + String json = "{\"v\":\"\"}"; + Cell c = Cell.loadStreaming(json, pool); + TestUtils.isSerializedTo(c, json); + } + + @Test + public void serializeErrorCell() throws Exception { + String json = "{\"e\":\"HTTP 403\"}"; + Cell c = Cell.loadStreaming(json, pool); + TestUtils.isSerializedTo(c, json); + } + + @Test + public void serializeDateCell() throws Exception { + String json = "{\"v\":\"2018-03-04T08:09:10Z\",\"t\":\"date\"}"; + TestUtils.isSerializedTo(Cell.loadStreaming(json, pool), json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/model/ColumnGroupTests.java b/main/tests/server/src/com/google/refine/tests/model/ColumnGroupTests.java new file mode 100644 index 000000000..83b6d8761 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/model/ColumnGroupTests.java @@ -0,0 +1,42 @@ +package com.google.refine.tests.model; + +import java.util.Properties; + +import org.testng.annotations.Test; + +import com.google.refine.model.ColumnGroup; +import com.google.refine.tests.util.TestUtils; + +public class ColumnGroupTests { + + String json = "{" + + "\"startColumnIndex\":2," + + "\"columnSpan\":3," + + "\"keyColumnIndex\":1" + + "}"; + @Test + public void serializeColumnGroup() throws Exception { + TestUtils.isSerializedTo(ColumnGroup.load(json), json); + } + + @Test + public void serializeColumnGroupWithSubgroups() throws Exception { + ColumnGroup cg = new ColumnGroup(2,3,1); + ColumnGroup subCg = new ColumnGroup(2,2,1); + cg.subgroups.add(subCg); + String fullJson = "{" + + "\"startColumnIndex\":2," + + "\"columnSpan\":3," + + "\"keyColumnIndex\":1," + + "\"subgroups\":[{" + + " \"startColumnIndex\":2," + + " \"columnSpan\":2," + + " \"keyColumnIndex\":1" + + "}]" + + "}"; + Properties options = new Properties(); + options.setProperty("mode", "save"); + TestUtils.isSerializedTo(cg, json, options); + TestUtils.isSerializedTo(cg, fullJson); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/model/ColumnModelTests.java b/main/tests/server/src/com/google/refine/tests/model/ColumnModelTests.java new file mode 100644 index 000000000..89f986165 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/model/ColumnModelTests.java @@ -0,0 +1,10 @@ +package com.google.refine.tests.model; + +import org.testng.annotations.Test; + +public class ColumnModelTests { + @Test + public void serializeColumnModel() { + String json = ""; + } +} diff --git a/main/tests/server/src/com/google/refine/tests/model/ColumnTests.java b/main/tests/server/src/com/google/refine/tests/model/ColumnTests.java new file mode 100644 index 000000000..162483a24 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/model/ColumnTests.java @@ -0,0 +1,47 @@ +package com.google.refine.tests.model; + +import org.testng.annotations.Test; + +import com.google.refine.model.Column; +import com.google.refine.model.recon.ReconConfig; +import com.google.refine.model.recon.StandardReconConfig; +import com.google.refine.tests.util.TestUtils; + +import edu.mit.simile.butterfly.ButterflyModule; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ColumnTests { + @Test + public void serializeColumn() throws Exception { + ButterflyModule core = mock(ButterflyModule.class); + when(core.getName()).thenReturn("core"); + ReconConfig.registerReconConfig(core, "standard-service", StandardReconConfig.class); + String json = "{\"cellIndex\":4," + + "\"originalName\":\"name\"," + + "\"name\":\"organization_name\"," + + "\"type\":\"\"," + + "\"format\":\"default\"," + + "\"title\":\"\"," + + "\"description\":\"\"," + + "\"constraints\":\"{}\"," + + "\"reconConfig\":{" + + " \"mode\":\"standard-service\"," + + " \"service\":\"https://tools.wmflabs.org/openrefine-wikidata/en/api\"," + + " \"identifierSpace\":\"http://www.wikidata.org/entity/\"," + + " \"schemaSpace\":\"http://www.wikidata.org/prop/direct/\"," + + " \"type\":{\"id\":\"Q43229\",\"name\":\"organization\"}," + + " \"autoMatch\":true," + + " \"columnDetails\":[" + + " {\"column\":\"organization_country\",\"propertyName\":\"SPARQL: P17/P297\",\"propertyID\":\"P17/P297\"}," + + " {\"column\":\"organization_id\",\"propertyName\":\"SPARQL: P3500|P2427\",\"propertyID\":\"P3500|P2427\"}" + + " ]," + + " \"limit\":0}," + + "\"reconStats\":{" + + " \"nonBlanks\":299," + + " \"newTopics\":0," + + " \"matchedTopics\":222" + + "}}"; + TestUtils.isSerializedTo(Column.load(json), json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/model/RecordModelTests.java b/main/tests/server/src/com/google/refine/tests/model/RecordModelTests.java new file mode 100644 index 000000000..2ebb9e2a7 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/model/RecordModelTests.java @@ -0,0 +1,18 @@ +package com.google.refine.tests.model; + +import org.testng.annotations.Test; + +import com.google.refine.model.Project; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class RecordModelTests extends RefineTest { + @Test + public void serializeRecordModel() { + Project proj = createCSVProject("key,val\n" + + "34,first\n" + + ",second" + ); + TestUtils.isSerializedTo(proj.recordModel, "{\"hasRecords\":true}"); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/model/RowTests.java b/main/tests/server/src/com/google/refine/tests/model/RowTests.java index 5607319d3..ef0a765e0 100644 --- a/main/tests/server/src/com/google/refine/tests/model/RowTests.java +++ b/main/tests/server/src/com/google/refine/tests/model/RowTests.java @@ -48,8 +48,11 @@ import org.testng.annotations.Test; import com.google.refine.model.Cell; import com.google.refine.model.Project; +import com.google.refine.model.Recon; import com.google.refine.model.Row; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; +import com.google.refine.util.Pool; public class RowTests extends RefineTest { @@ -104,7 +107,7 @@ public class RowTests extends RefineTest { Row row = new Row(5); row.setCell(0, new Cell("I'm not empty", null)); row.save(writer, options); - Assert.assertEquals(writer.getBuffer().toString(), + TestUtils.equalAsJson(writer.getBuffer().toString(), "{\"flagged\":false,\"starred\":false,\"cells\":[{\"v\":\"I'm not empty\"}]}"); } @@ -117,10 +120,39 @@ public class RowTests extends RefineTest { when(options.containsKey("recordIndex")).thenReturn(true); when(options.get("recordIndex")).thenReturn(1); row.save(writer, options); - Assert.assertEquals( + TestUtils.equalAsJson( writer.getBuffer().toString(), "{\"flagged\":false,\"starred\":false,\"cells\":[{\"v\":\"I'm not empty\"}],\"i\":0,\"j\":1}"); } + + @Test + public void serializeRowTest() throws Exception { + + String reconJson = "{\"id\":1533649346002675326," + + "\"judgmentHistoryEntry\":1530278634724," + + "\"service\":\"https://tools.wmflabs.org/openrefine-wikidata/en/api\"," + + "\"identifierSpace\":\"http://www.wikidata.org/entity/\"," + + "\"schemaSpace\":\"http://www.wikidata.org/prop/direct/\"," + + "\"j\":\"matched\"," + + "\"m\":{\"id\":\"Q551479\",\"name\":\"La Monnaie\",\"score\":100,\"types\":[\"Q153562\"]}," + + "\"c\":[{\"id\":\"Q551479\",\"name\":\"La Monnaie\",\"score\":100,\"types\":[\"Q153562\"]}]," + + "\"f\":[false,false,34,0],\"judgmentAction\":\"auto\",\"judgmentBatchSize\":1,\"matchRank\":0}"; + Pool pool = mock(Pool.class); + Recon recon = Recon.loadStreaming(reconJson, pool); + when(pool.getRecon("1533649346002675326")).thenReturn(recon); + + String json = "{\"flagged\":false," + + "\"starred\":false," + + "\"cells\":[" + + " {\"v\":\"http://www.wikidata.org/entity/Q41522540\",\"r\":\"1533649346002675326\"}," + + " {\"v\":\"0000-0002-5022-0488\"}," + + " null," + + " {\"v\":\"\"}" + + "]}"; + Row row = Row.load(json, pool); + when(options.get("pool")).thenReturn(pool); + TestUtils.isSerializedTo(row, json, options); + } @Test public void toStringTest() { From 2edf83bdf764eec63e388f0dd179db6788742305 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sat, 11 Aug 2018 19:47:58 +0100 Subject: [PATCH 08/26] 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\"}"); + } +} From 8896636017d190944bdd7ccefdef89ca97ae9a1d Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sat, 11 Aug 2018 20:24:23 +0100 Subject: [PATCH 09/26] Add deserialization tests for operations --- .../tests/operations/cell/BlankDownTests.java | 12 +++--- .../tests/operations/cell/FillDownTests.java | 11 +++-- .../cell/JoinMultiValuedCellsTests.java | 40 +++++++++---------- .../cell/KeyValueColumnizeTests.java | 17 +++++--- .../operations/cell/MassOperationTests.java | 14 +++---- .../cell/SplitMultiValuedCellsTests.java | 36 ++++++++--------- .../tests/operations/cell/TransposeTests.java | 13 ++++-- .../column/ColumnMoveOperationTests.java | 14 +++++-- .../column/ColumnRemovalOperationTests.java | 16 +++++--- .../column/ColumnRenameOperationTests.java | 16 +++++--- .../column/ColumnReorderOperationTests.java | 2 + .../row/DenormalizeOperationTests.java | 2 + 12 files changed, 105 insertions(+), 88 deletions(-) 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 2ae32c719..4c3238b3d 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 @@ -4,6 +4,7 @@ import static org.mockito.Mockito.when; import java.util.Properties; +import org.json.JSONException; import org.json.JSONObject; import org.testng.Assert; import org.testng.annotations.AfterMethod; @@ -45,14 +46,13 @@ public class BlankDownTests extends RefineTest { } @Test - public void serializeBlankDownOperation() { - AbstractOperation op = new BlankDownOperation( - new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}"), - "my column"); - TestUtils.isSerializedTo(op, "{\"op\":\"core/blank-down\"," + public void serializeBlankDownOperation() throws JSONException, Exception { + String json = "{\"op\":\"core/blank-down\"," + "\"description\":\"Blank down cells in column my column\"," + "\"engineConfig\":{\"mode\":\"record-based\",\"facets\":[]}," - + "\"columnName\":\"my column\"}"); + + "\"columnName\":\"my column\"}"; + AbstractOperation op = BlankDownOperation.reconstruct(project, new JSONObject(json)); + TestUtils.isSerializedTo(op, json); } @Test 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 fd000c02d..e50a44450 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 @@ -2,6 +2,7 @@ package com.google.refine.tests.operations.cell; import java.util.Properties; +import org.json.JSONException; import org.json.JSONObject; import org.testng.Assert; import org.testng.annotations.AfterMethod; @@ -43,14 +44,12 @@ public class FillDownTests extends RefineTest { } @Test - public void serializeFillDownOperation() { - AbstractOperation op = new FillDownOperation( - new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}"), - "my key"); - TestUtils.isSerializedTo(op, "{\"op\":\"core/fill-down\"," + public void serializeFillDownOperation() throws JSONException, Exception { + String json = "{\"op\":\"core/fill-down\"," + "\"description\":\"Fill down cells in column my key\"," + "\"engineConfig\":{\"mode\":\"record-based\",\"facets\":[]}," - + "\"columnName\":\"my key\"}"); + + "\"columnName\":\"my key\"}"; + TestUtils.isSerializedTo(FillDownOperation.reconstruct(project, new JSONObject(json)), json); } @Test 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 ad5d3d612..d7a147502 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,9 +35,11 @@ package com.google.refine.tests.operations.cell; import java.util.Properties; +import org.json.JSONException; import org.json.JSONObject; import org.slf4j.LoggerFactory; import org.testng.Assert; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeSuite; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -53,6 +55,8 @@ import com.google.refine.tests.util.TestUtils; public class JoinMultiValuedCellsTests extends RefineTest { + + Project project; @Override @BeforeTest @@ -65,17 +69,24 @@ public class JoinMultiValuedCellsTests extends RefineTest { OperationRegistry.registerOperation(getCoreModule(), "multivalued-cell-join", MultiValuedCellJoinOperation.class); } + @BeforeMethod + public void createProject() { + project = createCSVProject( + "Key,Value\n" + + "Record_1,one\n" + + ",two\n" + + ",three\n" + + ",four\n"); + } + @Test - public void serializeMultiValuedCellJoinOperation() { - AbstractOperation op = new MultiValuedCellJoinOperation( - "value column", - "key column", - ","); - TestUtils.isSerializedTo(op, "{\"op\":\"core/multivalued-cell-join\"," + public void serializeMultiValuedCellJoinOperation() throws JSONException, Exception { + String json = "{\"op\":\"core/multivalued-cell-join\"," + "\"description\":\"Join multi-valued cells in column value column\"," + "\"columnName\":\"value column\"," + "\"keyColumnName\":\"key column\"," - + "\"separator\":\",\"}"); + + "\"separator\":\",\"}"; + TestUtils.isSerializedTo(MultiValuedCellJoinOperation.reconstruct(project, new JSONObject(json)), json); } @@ -85,13 +96,6 @@ public class JoinMultiValuedCellsTests extends RefineTest { @Test public void testJoinMultiValuedCells() throws Exception { - Project project = createCSVProject( - "Key,Value\n" - + "Record_1,one\n" - + ",two\n" - + ",three\n" - + ",four\n"); - AbstractOperation op = new MultiValuedCellJoinOperation( "Value", "Key", @@ -108,14 +112,6 @@ public class JoinMultiValuedCellsTests extends RefineTest { @Test public void testJoinMultiValuedCellsMultipleSpaces() throws Exception { - Project project = createCSVProject( - "Key,Value\n" - + "Record_1,one\n" - + ",two\n" - + ",three\n" - + ",four\n"); - - AbstractOperation op = new MultiValuedCellJoinOperation( "Value", "Key", 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 5e70c6815..57b2a6c05 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 @@ -114,15 +114,20 @@ public class KeyValueColumnizeTests extends RefineTest { } @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\"," + public void serializeKeyValueColumnizeOperation() throws JSONException, Exception { + String json = "{\"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}"; + TestUtils.isSerializedTo(KeyValueColumnizeOperation.reconstruct(project, new JSONObject(json)), json); + + String jsonFull = "{\"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\"}"); + + "\"noteColumnName\":\"note column\"}"; + TestUtils.isSerializedTo(KeyValueColumnizeOperation.reconstruct(project, new JSONObject(jsonFull)), jsonFull); } /** 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 bc8bb6e8c..eb1e448e8 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 @@ -7,8 +7,9 @@ import org.json.JSONObject; import org.testng.Assert; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; +import static org.mockito.Mockito.mock; -import com.google.refine.model.AbstractOperation; +import com.google.refine.model.Project; import com.google.refine.operations.OperationRegistry; import com.google.refine.operations.cell.MassEditOperation; import com.google.refine.operations.cell.MassEditOperation.Edit; @@ -28,16 +29,13 @@ public class MassOperationTests extends RefineTest { @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\"," + Project project = mock(Project.class); + String json = "{\"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\"}]}"); + + "\"edits\":[{\"fromBlank\":false,\"fromError\":false,\"from\":[\"String\"],\"to\":\"newString\"}]}"; + TestUtils.isSerializedTo(MassEditOperation.reconstruct(project, new JSONObject(json)), json); } @Test 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 6dca22f64..0d020dbb8 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 @@ -36,8 +36,11 @@ package com.google.refine.tests.operations.cell; import java.util.Properties; +import org.json.JSONException; +import org.json.JSONObject; import org.slf4j.LoggerFactory; import org.testng.Assert; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -52,6 +55,8 @@ import com.google.refine.tests.util.TestUtils; public class SplitMultiValuedCellsTests extends RefineTest { + + Project project; @Override @BeforeTest @@ -60,20 +65,23 @@ public class SplitMultiValuedCellsTests extends RefineTest { OperationRegistry.registerOperation(getCoreModule(), "multivalued-cell-split", MultiValuedCellSplitOperation.class); } + @BeforeMethod + public void createProject() { + project = createCSVProject( + "Key,Value\n" + + "Record_1,one:two;three four\n"); + } + @Test - public void serializeMultiValuedCellSplitOperation() { - AbstractOperation op = new MultiValuedCellSplitOperation( - "Value", - "Key", - ":", - false); - TestUtils.isSerializedTo(op, "{\"op\":\"core/multivalued-cell-split\"," + public void serializeMultiValuedCellSplitOperation() throws JSONException, Exception { + String json = "{\"op\":\"core/multivalued-cell-split\"," + "\"description\":\"Split multi-valued cells in column Value\"," + "\"columnName\":\"Value\"," + "\"keyColumnName\":\"Key\"," + "\"mode\":\"separator\"," + "\"separator\":\":\"," - + "\"regex\":false}"); + + "\"regex\":false}"; + TestUtils.isSerializedTo(MultiValuedCellSplitOperation.reconstruct(project, new JSONObject(json)), json); } /** @@ -83,10 +91,6 @@ public class SplitMultiValuedCellsTests extends RefineTest { @Test public void testSplitMultiValuedCellsTextSeparator() throws Exception { - Project project = createCSVProject( - "Key,Value\n" - + "Record_1,one:two;three four\n"); - AbstractOperation op = new MultiValuedCellSplitOperation( "Value", "Key", @@ -106,10 +110,6 @@ public class SplitMultiValuedCellsTests extends RefineTest { @Test public void testSplitMultiValuedCellsRegExSeparator() throws Exception { - Project project = createCSVProject( - "Key,Value\n" - + "Record_1,one:two;three four\n"); - AbstractOperation op = new MultiValuedCellSplitOperation( "Value", "Key", @@ -133,10 +133,6 @@ public class SplitMultiValuedCellsTests extends RefineTest { @Test public void testSplitMultiValuedCellsLengths() throws Exception { - Project project = createCSVProject( - "Key,Value\n" - + "Record_1,one:two;three four\n"); - int[] lengths = {4,4,6,4}; AbstractOperation op = new MultiValuedCellSplitOperation( 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 0ed17c369..6071a5f09 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,13 +33,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.tests.operations.cell; +import static org.mockito.Mockito.mock; +import org.json.JSONException; +import org.json.JSONObject; import org.slf4j.LoggerFactory; import org.testng.Assert; 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.TransposeRowsIntoColumnsOperation; @@ -57,12 +61,13 @@ public class TransposeTests extends RefineTest { } @Test - public void testTransposeRowsIntoColumnsOperation() { - AbstractOperation op = new TransposeRowsIntoColumnsOperation("start column", 3); - TestUtils.isSerializedTo(op, "{\"op\":\"core/transpose-rows-into-columns\"," + public void testTransposeRowsIntoColumnsOperation() throws JSONException, Exception { + String json = "{\"op\":\"core/transpose-rows-into-columns\"," + "\"description\":\"Transpose every 3 cells in column start column into separate columns\"," + "\"columnName\":\"start column\"," - + "\"rowCount\":3}"); + + "\"rowCount\":3}"; + Project project = mock(Project.class); + TestUtils.isSerializedTo(TransposeRowsIntoColumnsOperation.reconstruct(project , new JSONObject(json)), json); } } 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 index 466c1489d..080f60bd6 100644 --- 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 @@ -1,9 +1,14 @@ package com.google.refine.tests.operations.column; +import static org.mockito.Mockito.mock; + +import org.json.JSONException; +import org.json.JSONObject; import org.testng.annotations.BeforeSuite; 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.column.ColumnMoveOperation; @@ -18,11 +23,12 @@ public class ColumnMoveOperationTests extends RefineTest { } @Test - public void serializeColumnMoveOperation() { - AbstractOperation op = new ColumnMoveOperation("my column", 3); - TestUtils.isSerializedTo(op, "{\"op\":\"core/column-move\"," + public void serializeColumnMoveOperation() throws JSONException, Exception { + String json = "{\"op\":\"core/column-move\"," + "\"description\":\"Move column my column to position 3\"," + "\"columnName\":\"my column\"," - + "\"index\":3}"); + + "\"index\":3}"; + Project project = mock(Project.class); + TestUtils.isSerializedTo(ColumnMoveOperation.reconstruct(project , new JSONObject(json)), json); } } 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 index fd692cc85..36a87e417 100644 --- 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 @@ -1,11 +1,14 @@ package com.google.refine.tests.operations.column; +import static org.mockito.Mockito.mock; + +import org.json.JSONException; +import org.json.JSONObject; import org.testng.annotations.BeforeSuite; 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.column.ColumnMoveOperation; import com.google.refine.operations.column.ColumnRemovalOperation; import com.google.refine.tests.RefineTest; import com.google.refine.tests.util.TestUtils; @@ -19,10 +22,11 @@ public class ColumnRemovalOperationTests extends RefineTest { } @Test - public void serializeColumnRemovalOperation() { - AbstractOperation op = new ColumnRemovalOperation("my column"); - TestUtils.isSerializedTo(op, "{\"op\":\"core/column-removal\"," + public void serializeColumnRemovalOperation() throws JSONException, Exception { + String json = "{\"op\":\"core/column-removal\"," + "\"description\":\"Remove column my column\"," - + "\"columnName\":\"my column\"}"); + + "\"columnName\":\"my column\"}"; + Project project = mock(Project.class); + TestUtils.isSerializedTo(ColumnRemovalOperation.reconstruct(project, new JSONObject(json)), json); } } 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 index 1e17ece03..917d6fdbc 100644 --- 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 @@ -1,11 +1,14 @@ package com.google.refine.tests.operations.column; +import static org.mockito.Mockito.mock; + +import org.json.JSONException; +import org.json.JSONObject; import org.testng.annotations.BeforeSuite; 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.column.ColumnMoveOperation; import com.google.refine.operations.column.ColumnRenameOperation; import com.google.refine.tests.RefineTest; import com.google.refine.tests.util.TestUtils; @@ -19,11 +22,12 @@ public class ColumnRenameOperationTests extends RefineTest { } @Test - public void serializeColumnRenameOperation() { - AbstractOperation op = new ColumnRenameOperation("old name", "new name"); - TestUtils.isSerializedTo(op, "{\"op\":\"core/column-rename\"," + public void serializeColumnRenameOperation() throws JSONException, Exception { + String json = "{\"op\":\"core/column-rename\"," + "\"description\":\"Rename column old name to new name\"," + "\"oldColumnName\":\"old name\"," - + "\"newColumnName\":\"new name\"}"); + + "\"newColumnName\":\"new name\"}"; + Project project = mock(Project.class); + TestUtils.isSerializedTo(ColumnRenameOperation.reconstruct(project, new JSONObject(json)), json); } } 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 index 7a66884be..0d07be1a1 100644 --- 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 @@ -1,5 +1,7 @@ package com.google.refine.tests.operations.column; +import static org.mockito.Mockito.mock; + import java.util.Arrays; import org.testng.annotations.BeforeSuite; 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 index 066edcb7b..8a55cb012 100644 --- 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 @@ -1,5 +1,7 @@ package com.google.refine.tests.operations.row; +import static org.mockito.Mockito.mock; + import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; From dbff74650dcb249ae2031be9dada7f54adf0b4f5 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sat, 11 Aug 2018 20:26:30 +0100 Subject: [PATCH 10/26] Cleanup imports --- .../google/refine/tests/operations/cell/BlankDownTests.java | 2 -- .../tests/operations/cell/JoinMultiValuedCellsTests.java | 1 - .../refine/tests/operations/cell/KeyValueColumnizeTests.java | 1 - .../tests/operations/cell/SplitMultiValuedCellsTests.java | 3 +-- .../google/refine/tests/operations/cell/TransposeTests.java | 4 ---- .../tests/operations/column/ColumnMoveOperationTests.java | 2 -- .../tests/operations/column/ColumnReorderOperationTests.java | 3 --- 7 files changed, 1 insertion(+), 15 deletions(-) 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 4c3238b3d..1bb957f1c 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,7 +1,5 @@ package com.google.refine.tests.operations.cell; -import static org.mockito.Mockito.when; - import java.util.Properties; import org.json.JSONException; 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 d7a147502..c1a87aec7 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 @@ -47,7 +47,6 @@ 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; 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 57b2a6c05..38567d48f 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 @@ -62,7 +62,6 @@ 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; 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 0d020dbb8..2db201031 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 @@ -46,10 +46,9 @@ 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.process.Process; import com.google.refine.tests.RefineTest; import com.google.refine.tests.util.TestUtils; 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 6071a5f09..3c08cb0b3 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 @@ -38,16 +38,12 @@ import static org.mockito.Mockito.mock; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.LoggerFactory; -import org.testng.Assert; 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.TransposeRowsIntoColumnsOperation; -import com.google.refine.process.Process; import com.google.refine.tests.RefineTest; import com.google.refine.tests.util.TestUtils; 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 index 080f60bd6..61d7aef91 100644 --- 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 @@ -7,10 +7,8 @@ import org.json.JSONObject; import org.testng.annotations.BeforeSuite; 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.column.ColumnMoveOperation; import com.google.refine.tests.RefineTest; import com.google.refine.tests.util.TestUtils; 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 index 0d07be1a1..cdf2b25f6 100644 --- 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 @@ -1,7 +1,5 @@ package com.google.refine.tests.operations.column; -import static org.mockito.Mockito.mock; - import java.util.Arrays; import org.testng.annotations.BeforeSuite; @@ -9,7 +7,6 @@ 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; From 4013c0b8c5991190ed4bc4942dd0fbf88fe4053d Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sun, 12 Aug 2018 11:52:18 +0100 Subject: [PATCH 11/26] Add (de)serialization tests to existing operation test classes --- ...AdditionByFetchingURLsOperationTests.java} | 28 +++++++++++++++-- .../recon/ExtendDataOperationTests.java} | 30 +++++++++++++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) rename main/tests/server/src/com/google/refine/{operations/column/UrlFetchingTests.java => tests/operations/column/ColumnAdditionByFetchingURLsOperationTests.java} (84%) rename main/tests/server/src/com/google/refine/tests/{recon/DataExtensionTests.java => operations/recon/ExtendDataOperationTests.java} (84%) diff --git a/main/tests/server/src/com/google/refine/operations/column/UrlFetchingTests.java b/main/tests/server/src/com/google/refine/tests/operations/column/ColumnAdditionByFetchingURLsOperationTests.java similarity index 84% rename from main/tests/server/src/com/google/refine/operations/column/UrlFetchingTests.java rename to main/tests/server/src/com/google/refine/tests/operations/column/ColumnAdditionByFetchingURLsOperationTests.java index 36ccefc08..0e834f6e4 100644 --- a/main/tests/server/src/com/google/refine/operations/column/UrlFetchingTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/column/ColumnAdditionByFetchingURLsOperationTests.java @@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.google.refine.operations.column; +package com.google.refine.tests.operations.column; import java.io.IOException; import java.net.InetAddress; @@ -47,19 +47,22 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.refine.expr.ExpressionUtils; +import com.google.refine.model.AbstractOperation; import com.google.refine.model.Cell; import com.google.refine.model.ModelException; import com.google.refine.model.Project; import com.google.refine.model.Row; import com.google.refine.operations.EngineDependentOperation; import com.google.refine.operations.OnError; +import com.google.refine.operations.OperationRegistry; import com.google.refine.operations.column.ColumnAdditionByFetchingURLsOperation; import com.google.refine.process.Process; import com.google.refine.process.ProcessManager; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; -public class UrlFetchingTests extends RefineTest { +public class ColumnAdditionByFetchingURLsOperationTests extends RefineTest { static final String ENGINE_JSON_URLS = "{\"mode\":\"row-based\"}}"; @@ -67,6 +70,7 @@ public class UrlFetchingTests extends RefineTest { @BeforeTest public void init() { logger = LoggerFactory.getLogger(this.getClass()); + OperationRegistry.registerOperation(getCoreModule(), "column-addition-by-fetching-urls", ColumnAdditionByFetchingURLsOperation.class); } // dependencies @@ -91,6 +95,26 @@ public class UrlFetchingTests extends RefineTest { return state; } + @Test + public void serializeColumnAdditionByFetchingURLsOperation() throws JSONException, Exception { + String json = "{\"op\":\"core/column-addition-by-fetching-urls\"," + + "\"description\":\"Create column employments at index 2 by fetching URLs based on column orcid using expression grel:\\\"https://pub.orcid.org/\\\"+value+\\\"/employments\\\"\"," + + "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]}," + + "\"newColumnName\":\"employments\"," + + "\"columnInsertIndex\":2," + + "\"baseColumnName\":\"orcid\"," + + "\"urlExpression\":\"grel:\\\"https://pub.orcid.org/\\\"+value+\\\"/employments\\\"\"," + + "\"onError\":\"set-to-blank\"," + + "\"delay\":500," + + "\"cacheResponses\":true," + + "\"httpHeadersJson\":[" + + " {\"name\":\"authorization\",\"value\":\"\"}," + + " {\"name\":\"user-agent\",\"value\":\"OpenRefine 3.0 rc.1 [TRUNK]\"}," + + " {\"name\":\"accept\",\"value\":\"application/json\"}" + + "]}"; + TestUtils.isSerializedTo(ColumnAdditionByFetchingURLsOperation.reconstruct(project, new JSONObject(json)), json); + } + /** * Test for caching */ diff --git a/main/tests/server/src/com/google/refine/tests/recon/DataExtensionTests.java b/main/tests/server/src/com/google/refine/tests/operations/recon/ExtendDataOperationTests.java similarity index 84% rename from main/tests/server/src/com/google/refine/tests/recon/DataExtensionTests.java rename to main/tests/server/src/com/google/refine/tests/operations/recon/ExtendDataOperationTests.java index 119c8abcc..f4a2e6d32 100644 --- a/main/tests/server/src/com/google/refine/tests/recon/DataExtensionTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/recon/ExtendDataOperationTests.java @@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.google.refine.tests.recon; +package com.google.refine.tests.operations.recon; import static org.mockito.Mockito.mock; @@ -59,11 +59,13 @@ import com.google.refine.model.Row; import com.google.refine.process.Process; import com.google.refine.process.ProcessManager; import com.google.refine.operations.EngineDependentOperation; +import com.google.refine.operations.OperationRegistry; import com.google.refine.operations.recon.ExtendDataOperation; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; -public class DataExtensionTests extends RefineTest { +public class ExtendDataOperationTests extends RefineTest { static final String ENGINE_JSON_URLS = "{\"mode\":\"row-based\"}}"; static final String RECON_SERVICE = "https://tools.wmflabs.org/openrefine-wikidata/en/api"; @@ -84,6 +86,7 @@ public class DataExtensionTests extends RefineTest { @BeforeMethod public void SetUp() throws JSONException, IOException, ModelException { + OperationRegistry.registerOperation(getCoreModule(), "extend-reconciled-data", ExtendDataOperation.class); project = createProjectWithColumns("DataExtensionTests", "country"); options = mock(Properties.class); @@ -105,6 +108,29 @@ public class DataExtensionTests extends RefineTest { row.setCell(0, reconciledCell("United States of America", "Q30")); project.rows.add(row); } + + @Test + public void serializeExtendDataOperation() throws JSONException, Exception { + String json = "{\"op\":\"core/extend-reconciled-data\"," + + "\"description\":\"Extend data at index 3 based on column organization_name\"," + + "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[" + + " {\"selectNumeric\":true,\"expression\":\"cell.recon.best.score\",\"selectBlank\":false,\"selectNonNumeric\":true,\"selectError\":true,\"name\":\"organization_name: best candidate's score\",\"from\":13,\"to\":101,\"type\":\"range\",\"columnName\":\"organization_name\"}," + + " {\"selectNonTime\":true,\"expression\":\"grel:toDate(value)\",\"selectBlank\":true,\"selectError\":true,\"selectTime\":true,\"name\":\"start_year\",\"from\":410242968000,\"to\":1262309184000,\"type\":\"timerange\",\"columnName\":\"start_year\"}" + + "]}," + + "\"columnInsertIndex\":3," + + "\"baseColumnName\":\"organization_name\"," + + "\"endpoint\":\"https://tools.wmflabs.org/openrefine-wikidata/en/api\"," + + "\"identifierSpace\":\"http://www.wikidata.org/entity/\"," + + "\"schemaSpace\":\"http://www.wikidata.org/prop/direct/\"," + + "\"extension\":{" + + " \"properties\":[" + + " {\"name\":\"inception\",\"id\":\"P571\"}," + + " {\"name\":\"headquarters location\",\"id\":\"P159\"}," + + " {\"name\":\"coordinate location\",\"id\":\"P625\"}" + + " ]" + + "}}"; + TestUtils.isSerializedTo(ExtendDataOperation.reconstruct(project, new JSONObject(json)), json); + } @AfterMethod public void TearDown() { From b4bcf7a1b64f8951f3e9764b1981eeb1e885cc00 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sun, 12 Aug 2018 15:48:17 +0100 Subject: [PATCH 12/26] Fix inconsistency in serialization of ReconMatchSpecificTopicOperation --- .../operations/recon/ReconMatchSpecificTopicOperation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/src/com/google/refine/operations/recon/ReconMatchSpecificTopicOperation.java b/main/src/com/google/refine/operations/recon/ReconMatchSpecificTopicOperation.java index 094056cff..6a509b01b 100644 --- a/main/src/com/google/refine/operations/recon/ReconMatchSpecificTopicOperation.java +++ b/main/src/com/google/refine/operations/recon/ReconMatchSpecificTopicOperation.java @@ -68,7 +68,7 @@ public class ReconMatchSpecificTopicOperation extends EngineDependentMassCellOpe JSONObject match = obj.getJSONObject("match"); - JSONArray types = obj.getJSONArray("types"); + JSONArray types = match.getJSONArray("types"); String[] typeIDs = new String[types.length()]; for (int i = 0; i < typeIDs.length; i++) { typeIDs[i] = types.getString(i); From 73171755f36d33eecfbbe7c6209d97a68d4d97f7 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sun, 12 Aug 2018 15:48:52 +0100 Subject: [PATCH 13/26] More JSON tests for operations --- .../column/ColumnAdditionOperationTests.java | 34 +++++++++++++++ .../column/ColumnSplitOperationTests.java | 42 ++++++++++++++++++ .../ReconClearSimilarCellsOperationTests.java | 30 +++++++++++++ .../ReconCopyAcrossColumnsOperationTests.java | 32 ++++++++++++++ .../ReconDiscardJudgmentsOperationTests.java | 35 +++++++++++++++ .../ReconJudgeSimilarCellsOperationTests.java | 33 ++++++++++++++ .../recon/ReconJudgeSimilarCellsTests.java | 2 - .../ReconMarkNewTopicsOperationTests.java | 32 ++++++++++++++ ...econMatchBestCandidatesOperationTests.java | 34 +++++++++++++++ ...ReconMatchSpecificTopicOperationTests.java | 43 +++++++++++++++++++ .../operations/recon/ReconOperationTests.java | 43 +++++++++++++++++++ 11 files changed, 358 insertions(+), 2 deletions(-) create mode 100644 main/tests/server/src/com/google/refine/tests/operations/column/ColumnAdditionOperationTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/operations/column/ColumnSplitOperationTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/operations/recon/ReconClearSimilarCellsOperationTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/operations/recon/ReconCopyAcrossColumnsOperationTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/operations/recon/ReconDiscardJudgmentsOperationTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsOperationTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/operations/recon/ReconMarkNewTopicsOperationTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/operations/recon/ReconMatchBestCandidatesOperationTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/operations/recon/ReconMatchSpecificTopicOperationTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/operations/recon/ReconOperationTests.java diff --git a/main/tests/server/src/com/google/refine/tests/operations/column/ColumnAdditionOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/column/ColumnAdditionOperationTests.java new file mode 100644 index 000000000..d150adafb --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/column/ColumnAdditionOperationTests.java @@ -0,0 +1,34 @@ +package com.google.refine.tests.operations.column; + +import static org.mockito.Mockito.mock; + +import org.json.JSONException; +import org.json.JSONObject; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.column.ColumnAdditionOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class ColumnAdditionOperationTests extends RefineTest { + + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "column-addition", ColumnAdditionOperation.class); + } + + @Test + public void serializeColumnAdditionOperation() throws JSONException, Exception { + String json = "{" + + " \"op\":\"core/column-addition\"," + + " \"description\":\"Create column organization_json at index 3 based on column employments using expression grel:value.parseJson()[\\\"employment-summary\\\"].join('###')\",\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]},\"newColumnName\":\"organization_json\",\"columnInsertIndex\":3,\"baseColumnName\":\"employments\"," + + " \"expression\":\"grel:value.parseJson()[\\\"employment-summary\\\"].join('###')\"," + + " \"onError\":\"set-to-blank\"" + + "}"; + Project project = mock(Project.class); + TestUtils.isSerializedTo(ColumnAdditionOperation.reconstruct(project, new JSONObject(json)), json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/operations/column/ColumnSplitOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/column/ColumnSplitOperationTests.java new file mode 100644 index 000000000..1aa3a997c --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/column/ColumnSplitOperationTests.java @@ -0,0 +1,42 @@ +package com.google.refine.tests.operations.column; + +import static org.mockito.Mockito.mock; + +import org.json.JSONException; +import org.json.JSONObject; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.column.ColumnSplitOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class ColumnSplitOperationTests extends RefineTest { + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "column-split", ColumnSplitOperation.class); + } + + @Test + public void serializeColumnSplitOperation() throws JSONException, Exception { + String json = "{\n" + + " \"op\": \"core/column-split\",\n" + + " \"description\": \"Split column ea by separator\",\n" + + " \"engineConfig\": {\n" + + " \"mode\": \"row-based\",\n" + + " \"facets\": []\n" + + " },\n" + + " \"columnName\": \"ea\",\n" + + " \"guessCellType\": true,\n" + + " \"removeOriginalColumn\": true,\n" + + " \"mode\": \"separator\",\n" + + " \"separator\": \"e\",\n" + + " \"regex\": false,\n" + + " \"maxColumns\": 0\n" + + " }"; + Project project = mock(Project.class); + TestUtils.isSerializedTo(ColumnSplitOperation.reconstruct(project, new JSONObject(json)), json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/operations/recon/ReconClearSimilarCellsOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconClearSimilarCellsOperationTests.java new file mode 100644 index 000000000..bddfb4fed --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconClearSimilarCellsOperationTests.java @@ -0,0 +1,30 @@ +package com.google.refine.tests.operations.recon; +import static org.mockito.Mockito.mock; + +import org.json.JSONObject; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.recon.ReconClearSimilarCellsOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class ReconClearSimilarCellsOperationTests extends RefineTest { + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "recon-clear-similar-cells", ReconClearSimilarCellsOperation.class); + } + + @Test + public void serializeReconClearSimilarCellsOperation() throws Exception { + String json = "{\"op\":\"core/recon-clear-similar-cells\"," + + "\"description\":\"Clear recon data for cells containing \\\"some value\\\" in column my column\"," + + "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]}," + + "\"columnName\":\"my column\"," + + "\"similarValue\":\"some value\"}"; + Project project = mock(Project.class); + TestUtils.isSerializedTo(ReconClearSimilarCellsOperation.reconstruct(project, new JSONObject(json)), json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/operations/recon/ReconCopyAcrossColumnsOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconCopyAcrossColumnsOperationTests.java new file mode 100644 index 000000000..7b79a8164 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconCopyAcrossColumnsOperationTests.java @@ -0,0 +1,32 @@ +package com.google.refine.tests.operations.recon; +import static org.mockito.Mockito.mock; + +import org.json.JSONObject; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.recon.ReconCopyAcrossColumnsOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class ReconCopyAcrossColumnsOperationTests extends RefineTest { + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "recon-copy-across-columns", ReconCopyAcrossColumnsOperation.class); + } + + @Test + public void serializeReconCopyAcrossColumnsOperation() throws Exception { + String json = "{\"op\":\"core/recon-copy-across-columns\"," + + "\"description\":\"Copy recon judgments from column source column to firstsecond\"," + + "\"engineConfig\":{\"mode\":\"row-based\"}," + + "\"fromColumnName\":\"source column\"," + + "\"toColumnNames\":[\"first\",\"second\"]," + + "\"judgments\":[\"matched\",\"new\"]," + + "\"applyToJudgedCells\":true}"; + Project project = mock(Project.class); + TestUtils.isSerializedTo(ReconCopyAcrossColumnsOperation.reconstruct(project, new JSONObject(json)), json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/operations/recon/ReconDiscardJudgmentsOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconDiscardJudgmentsOperationTests.java new file mode 100644 index 000000000..ce44bb9cd --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconDiscardJudgmentsOperationTests.java @@ -0,0 +1,35 @@ +package com.google.refine.tests.operations.recon; +import static org.mockito.Mockito.mock; + +import org.json.JSONObject; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.recon.ReconDiscardJudgmentsOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class ReconDiscardJudgmentsOperationTests extends RefineTest { + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "recon-discard-judgments", ReconDiscardJudgmentsOperation.class); + } + + @Test + public void serializeReconDiscardJudgmentsOperation() throws Exception { + String json = "{\n" + + " \"op\": \"core/recon-discard-judgments\",\n" + + " \"description\": \"Discard recon judgments and clear recon data for cells in column researcher\",\n" + + " \"engineConfig\": {\n" + + " \"mode\": \"record-based\",\n" + + " \"facets\": []\n" + + " },\n" + + " \"columnName\": \"researcher\",\n" + + " \"clearData\": true\n" + + " }"; + Project project = mock(Project.class); + TestUtils.isSerializedTo(ReconDiscardJudgmentsOperation.reconstruct(project, new JSONObject(json)), json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsOperationTests.java new file mode 100644 index 000000000..117193d58 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsOperationTests.java @@ -0,0 +1,33 @@ +package com.google.refine.tests.operations.recon; +import static org.mockito.Mockito.mock; + +import org.json.JSONObject; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.recon.ReconJudgeSimilarCellsOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class ReconJudgeSimilarCellsOperationTests extends RefineTest { + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "recon-judge-similar-cells", ReconJudgeSimilarCellsOperation.class); + } + + @Test + public void serializeReconJudgeSimilarCellsOperation() throws Exception { + String json = "{\"op\":\"core/recon-judge-similar-cells\"," + + "\"description\":\"Match item Unicef Indonesia (Q7884717) for cells containing \\\"UNICEF Indonesia\\\" in column organization_name\"," + + "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]}," + + "\"columnName\":\"organization_name\"," + + "\"similarValue\":\"UNICEF Indonesia\"," + + "\"judgment\":\"matched\"," + + "\"match\":{\"id\":\"Q7884717\",\"name\":\"Unicef Indonesia\",\"score\":71.42857142857143,\"types\":[\"Q43229\"]}," + + "\"shareNewTopics\":false}"; + Project project = mock(Project.class); + TestUtils.isSerializedTo(ReconJudgeSimilarCellsOperation.reconstruct(project, new JSONObject(json)), json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsTests.java b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsTests.java index dd304ff45..5a8234e31 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsTests.java @@ -8,7 +8,6 @@ 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; @@ -20,7 +19,6 @@ 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; diff --git a/main/tests/server/src/com/google/refine/tests/operations/recon/ReconMarkNewTopicsOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconMarkNewTopicsOperationTests.java new file mode 100644 index 000000000..382eb47fc --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconMarkNewTopicsOperationTests.java @@ -0,0 +1,32 @@ +package com.google.refine.tests.operations.recon; +import static org.mockito.Mockito.mock; + +import org.json.JSONObject; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.recon.ReconMarkNewTopicsOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class ReconMarkNewTopicsOperationTests extends RefineTest { + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "recon-mark-new-topics", ReconMarkNewTopicsOperation.class); + } + + @Test + public void serializeReconMarkNewTopicsOperation() throws Exception { + String json = "{" + + "\"op\":\"core/recon-mark-new-topics\"," + + "\"engineConfig\":{\"mode\":\"row-based\"}," + + "\"columnName\":\"my column\"," + + "\"shareNewTopics\":true," + + "\"description\":\"Mark to create new items for cells in column my column, one item for each group of similar cells\"" + + "}"; + Project project = mock(Project.class); + TestUtils.isSerializedTo(ReconMarkNewTopicsOperation.reconstruct(project, new JSONObject(json)), json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/operations/recon/ReconMatchBestCandidatesOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconMatchBestCandidatesOperationTests.java new file mode 100644 index 000000000..63274e487 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconMatchBestCandidatesOperationTests.java @@ -0,0 +1,34 @@ +package com.google.refine.tests.operations.recon; +import static org.mockito.Mockito.mock; + +import org.json.JSONObject; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.recon.ReconMatchBestCandidatesOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class ReconMatchBestCandidatesOperationTests extends RefineTest { + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "recon-match-best-candidates", ReconMatchBestCandidatesOperation.class); + } + + @Test + public void serializeReconMatchBestCandidatesOperation() throws Exception { + String json = "{" + + "\"op\":\"core/recon-match-best-candidates\"," + + "\"description\":\"Match each cell to its best recon candidate in column organization_name\"," + + "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[" + + " {\"selectNumeric\":true,\"expression\":\"cell.recon.best.score\",\"selectBlank\":false,\"selectNonNumeric\":true,\"selectError\":true,\"name\":\"organization_name: best candidate's score\",\"from\":13,\"to\":101,\"type\":\"range\",\"columnName\":\"organization_name\"}," + + " {\"selectNonTime\":true,\"expression\":\"grel:toDate(value)\",\"selectBlank\":true,\"selectError\":true,\"selectTime\":true,\"name\":\"start_year\",\"from\":410242968000,\"to\":1262309184000,\"type\":\"timerange\",\"columnName\":\"start_year\"}" + + "]}," + + "\"columnName\":\"organization_name\"" + + "}"; + Project project = mock(Project.class); + TestUtils.isSerializedTo(ReconMatchBestCandidatesOperation.reconstruct(project, new JSONObject(json)), json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/operations/recon/ReconMatchSpecificTopicOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconMatchSpecificTopicOperationTests.java new file mode 100644 index 000000000..1e1c51386 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconMatchSpecificTopicOperationTests.java @@ -0,0 +1,43 @@ +package com.google.refine.tests.operations.recon; +import static org.mockito.Mockito.mock; + +import org.json.JSONObject; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.recon.ReconMatchSpecificTopicOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class ReconMatchSpecificTopicOperationTests extends RefineTest { + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "recon-match-specific-topic-to-cells", ReconMatchSpecificTopicOperation.class); + } + + @Test + public void serializeReconMatchSpecificTopicOperation() throws Exception { + String json = "{\n" + + " \"op\": \"core/recon-match-specific-topic-to-cells\",\n" + + " \"description\": \"Match specific item Gangnam (Q489941) to cells in column researcher\",\n" + + " \"engineConfig\": {\n" + + " \"mode\": \"record-based\",\n" + + " \"facets\": []\n" + + " },\n" + + " \"columnName\": \"researcher\",\n" + + " \"match\": {\n" + + " \"id\": \"Q489941\",\n" + + " \"name\": \"Gangnam\",\n" + + " \"types\": [\n" + + " \"Q5\"\n" + + " ]\n" + + " },\n" + + " \"identifierSpace\": \"http://www.wikidata.org/entity/\",\n" + + " \"schemaSpace\": \"http://www.wikidata.org/prop/direct/\"\n" + + " }"; + Project project = mock(Project.class); + TestUtils.isSerializedTo(ReconMatchSpecificTopicOperation.reconstruct(project, new JSONObject(json)), json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/operations/recon/ReconOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconOperationTests.java new file mode 100644 index 000000000..d5f16b420 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconOperationTests.java @@ -0,0 +1,43 @@ +package com.google.refine.tests.operations.recon; + +import static org.mockito.Mockito.mock; + +import org.json.JSONException; +import org.json.JSONObject; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.recon.ReconOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + + +public class ReconOperationTests extends RefineTest { + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "recon", ReconOperation.class); + } + + @Test + public void serializeReconOperation() throws JSONException, Exception { + String json = "{" + + "\"op\":\"core/recon\"," + + "\"description\":\"Reconcile cells in column researcher to type Q5\"," + + "\"columnName\":\"researcher\"," + + "\"config\":{" + + " \"mode\":\"standard-service\"," + + " \"service\":\"https://tools.wmflabs.org/openrefine-wikidata/en/api\"," + + " \"identifierSpace\":\"http://www.wikidata.org/entity/\"," + + " \"schemaSpace\":\"http://www.wikidata.org/prop/direct/\"," + + " \"type\":{\"id\":\"Q5\",\"name\":\"human\"}," + + " \"autoMatch\":true," + + " \"columnDetails\":[]," + + " \"limit\":0" + + "}," + + "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]}}"; + Project project = mock(Project.class); + TestUtils.isSerializedTo(ReconOperation.reconstruct(project, new JSONObject(json)), json); + } +} From 6ccd8ea9eeb420301083ece44cad6166fa8db377 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Thu, 16 Aug 2018 09:48:51 +0100 Subject: [PATCH 14/26] Deserialization test for Denormalize operation --- .../operations/row/DenormalizeOperationTests.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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 index 8a55cb012..d5a344fe2 100644 --- 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 @@ -2,12 +2,13 @@ package com.google.refine.tests.operations.row; import static org.mockito.Mockito.mock; +import org.json.JSONException; +import org.json.JSONObject; import org.testng.annotations.BeforeSuite; 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.MultiValuedCellSplitOperation; import com.google.refine.operations.row.DenormalizeOperation; import com.google.refine.tests.RefineTest; import com.google.refine.tests.util.TestUtils; @@ -20,10 +21,11 @@ public class DenormalizeOperationTests extends RefineTest { } @Test - public void serializeDenormalizeOperation() { - AbstractOperation op = new DenormalizeOperation(); - TestUtils.isSerializedTo(op, "{" + public void serializeDenormalizeOperation() throws JSONException, Exception { + Project project = mock(Project.class); + String json = "{" + "\"op\":\"core/denormalize\"," - + "\"description\":\"Denormalize\"}"); + + "\"description\":\"Denormalize\"}"; + TestUtils.isSerializedTo(DenormalizeOperation.reconstruct(project, new JSONObject(json)), json); } } From 14233b8ea8981d3c00ac65ac2c4aa2bc88c5d425 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Thu, 16 Aug 2018 13:33:26 +0100 Subject: [PATCH 15/26] Serialization tests for operations.row --- .../operations/row/RowFlagOperationTests.java | 32 +++++++++++++++++++ .../row/RowRemovalOperationTests.java | 31 ++++++++++++++++++ .../row/RowReorderOperationTests.java | 32 ++++++++++++++++++- .../operations/row/RowStarOperationTests.java | 31 ++++++++++++++++++ 4 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 main/tests/server/src/com/google/refine/tests/operations/row/RowFlagOperationTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/operations/row/RowRemovalOperationTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/operations/row/RowStarOperationTests.java diff --git a/main/tests/server/src/com/google/refine/tests/operations/row/RowFlagOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/row/RowFlagOperationTests.java new file mode 100644 index 000000000..e7c625706 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/row/RowFlagOperationTests.java @@ -0,0 +1,32 @@ +package com.google.refine.tests.operations.row; + +import static org.mockito.Mockito.mock; + +import org.json.JSONException; +import org.json.JSONObject; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.row.RowFlagOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class RowFlagOperationTests extends RefineTest { + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "row-flag", RowFlagOperation.class); + } + + @Test + public void serializeRowFlagOperation() throws JSONException, Exception { + Project project = mock(Project.class); + String json = "{" + + "\"op\":\"core/row-flag\"," + + "\"description\":\"Flag rows\"," + + "\"flagged\":true," + + "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]}}"; + TestUtils.isSerializedTo(RowFlagOperation.reconstruct(project, new JSONObject(json)), json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/operations/row/RowRemovalOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/row/RowRemovalOperationTests.java new file mode 100644 index 000000000..375e2aca9 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/row/RowRemovalOperationTests.java @@ -0,0 +1,31 @@ +package com.google.refine.tests.operations.row; + +import static org.mockito.Mockito.mock; + +import org.json.JSONException; +import org.json.JSONObject; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.row.RowRemovalOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class RowRemovalOperationTests extends RefineTest { + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "row-removal", RowRemovalOperation.class); + } + + @Test + public void serializeRowRemovalOperation() throws JSONException, Exception { + Project project = mock(Project.class); + String json = "{" + + "\"op\":\"core/row-removal\"," + + "\"description\":\"Remove rows\"," + + "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]}}"; + TestUtils.isSerializedTo(RowRemovalOperation.reconstruct(project, new JSONObject(json)), json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/operations/row/RowReorderOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/row/RowReorderOperationTests.java index c8cbc882e..bbc03c3af 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/row/RowReorderOperationTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/row/RowReorderOperationTests.java @@ -20,6 +20,11 @@ import com.google.refine.tests.RefineTest; public class RowReorderOperationTests extends RefineTest { Project project = null; + + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "row-reorder", RowReorderOperation.class); + } @BeforeMethod public void setUp() { @@ -50,4 +55,29 @@ public class RowReorderOperationTests extends RefineTest { Assert.assertEquals("b", project.rows.get(2).cells.get(1).value); Assert.assertEquals("d", project.rows.get(3).cells.get(1).value); } -} \ No newline at end of file + + + @Test + public void serializeRowReorderOperation() throws JSONException, Exception { + Project project = mock(Project.class); + String json = " {\n" + + " \"op\": \"core/row-reorder\",\n" + + " \"description\": \"Reorder rows\",\n" + + " \"mode\": \"record-based\",\n" + + " \"sorting\": {\n" + + " \"criteria\": [\n" + + " {\n" + + " \"errorPosition\": 1,\n" + + " \"valueType\": \"number\",\n" + + " \"column\": \"start_year\",\n" + + " \"blankPosition\": 2,\n" + + " \"reverse\": false\n" + + " }\n" + + " ]\n" + + " }\n" + + " }"; + TestUtils.isSerializedTo(RowReorderOperation.reconstruct(project, new JSONObject(json)), json); + } + +} + diff --git a/main/tests/server/src/com/google/refine/tests/operations/row/RowStarOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/row/RowStarOperationTests.java new file mode 100644 index 000000000..84e829f69 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/operations/row/RowStarOperationTests.java @@ -0,0 +1,31 @@ +package com.google.refine.tests.operations.row; + +import static org.mockito.Mockito.mock; + +import org.json.JSONException; +import org.json.JSONObject; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; +import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.row.RowStarOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class RowStarOperationTests extends RefineTest { + @BeforeSuite + public void registerOperation() { + OperationRegistry.registerOperation(getCoreModule(), "row-star", RowStarOperation.class); + } + + @Test + public void serializeRowStarOperation() throws JSONException, Exception { + Project project = mock(Project.class); + String json = "{" + + "\"op\":\"core/row-star\"," + + "\"description\":\"Star rows\"," + + "\"starred\":true," + + "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]}}"; + TestUtils.isSerializedTo(RowStarOperation.reconstruct(project, new JSONObject(json)), json); + } +} From a2c0ac9bccc87c6550cc5e4377c7a88dc6850ada Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Thu, 16 Aug 2018 14:01:15 +0100 Subject: [PATCH 16/26] Drop Jsonizable for DatabaseModuleImpl, not needed --- .../refine/extension/database/DatabaseModuleImpl.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/extensions/database/src/com/google/refine/extension/database/DatabaseModuleImpl.java b/extensions/database/src/com/google/refine/extension/database/DatabaseModuleImpl.java index 45bb6aff7..d26fefcf8 100644 --- a/extensions/database/src/com/google/refine/extension/database/DatabaseModuleImpl.java +++ b/extensions/database/src/com/google/refine/extension/database/DatabaseModuleImpl.java @@ -45,7 +45,7 @@ import com.google.refine.Jsonizable; import edu.mit.simile.butterfly.ButterflyModuleImpl; -public class DatabaseModuleImpl extends ButterflyModuleImpl implements Jsonizable { +public class DatabaseModuleImpl extends ButterflyModuleImpl { private static final Logger logger = LoggerFactory.getLogger("DatabaseModuleImpl"); @@ -132,13 +132,6 @@ public class DatabaseModuleImpl extends ButterflyModuleImpl implements Jsonizabl } return ps; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - // TODO Auto-generated method stub - - } } From 2dde302a903a9172474e69ffd65108dd6773d0b7 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sat, 18 Aug 2018 20:19:36 +0100 Subject: [PATCH 17/26] Add JSON serialization tests for refine.history and refine.browsing --- .../tests/browsing/DecoratedValueTests.java | 17 +++++ .../refine/tests/browsing/EngineTests.java | 20 ++++++ .../tests/history/HistoryEntryTests.java | 66 +++++++++++++++++++ .../refine/tests/history/HistoryTests.java | 59 +++++++++++++++-- 4 files changed, 156 insertions(+), 6 deletions(-) create mode 100644 main/tests/server/src/com/google/refine/tests/browsing/DecoratedValueTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/browsing/EngineTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/history/HistoryEntryTests.java diff --git a/main/tests/server/src/com/google/refine/tests/browsing/DecoratedValueTests.java b/main/tests/server/src/com/google/refine/tests/browsing/DecoratedValueTests.java new file mode 100644 index 000000000..25eb4f5e2 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/browsing/DecoratedValueTests.java @@ -0,0 +1,17 @@ +package com.google.refine.tests.browsing; + +import java.time.OffsetDateTime; + +import org.testng.annotations.Test; + +import com.google.refine.browsing.DecoratedValue; +import com.google.refine.tests.util.TestUtils; + +public class DecoratedValueTests { + @Test + public void serializeDecoratedValue() { + OffsetDateTime date = OffsetDateTime.parse("2017-03-04T12:56:32Z"); + DecoratedValue dv = new DecoratedValue(date, "[date 2017-03-04T12:56:32Z]"); + TestUtils.isSerializedTo(dv, "{\"v\":\"2017-03-04T12:56:32Z\",\"l\":\"[date 2017-03-04T12:56:32Z]\"}"); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/browsing/EngineTests.java b/main/tests/server/src/com/google/refine/tests/browsing/EngineTests.java new file mode 100644 index 000000000..39ddb15bb --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/browsing/EngineTests.java @@ -0,0 +1,20 @@ +package com.google.refine.tests.browsing; + +import static org.mockito.Mockito.mock; +import org.testng.annotations.Test; + +import com.google.refine.browsing.Engine; +import com.google.refine.model.Project; +import com.google.refine.tests.util.TestUtils; + +// TODO Engine and engine config should be separated +// create an EngineConfig class that can be used in operations directly (to avoid manipulating JSONObject) + +public class EngineTests { + @Test + public void serializeEngine() { + Project project = mock(Project.class); + Engine engine = new Engine(project); + TestUtils.isSerializedTo(engine, "{\"mode\":\"row-based\",\"facets\":[]}"); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/history/HistoryEntryTests.java b/main/tests/server/src/com/google/refine/tests/history/HistoryEntryTests.java new file mode 100644 index 000000000..5d1123fbb --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/history/HistoryEntryTests.java @@ -0,0 +1,66 @@ +package com.google.refine.tests.history; + +import static org.mockito.Mockito.mock; + +import java.util.Properties; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import com.google.refine.history.HistoryEntry; +import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; +import com.google.refine.operations.column.ColumnAdditionOperation; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class HistoryEntryTests extends RefineTest { + + Project project; + + @BeforeTest + public void register() { + OperationRegistry.registerOperation(getCoreModule(), "column-addition", ColumnAdditionOperation.class); + } + + @BeforeMethod + public void setUp() { + project = mock(Project.class); + } + + @Test + public void serializeHistoryEntry() throws Exception { + String json = "{\"id\":1533651837506," + + "\"description\":\"Discard recon judgment for single cell on row 76, column organization_name, containing \\\"Catholic University Leuven\\\"\"," + + "\"time\":\"2018-08-07T14:18:29Z\"}"; + TestUtils.isSerializedTo(HistoryEntry.load(project, json), json); + } + + @Test + public void serializeHistoryEntryWithOperation() throws Exception { + String json = "{" + + "\"id\":1533633623158," + + "\"description\":\"Create new column uri based on column country by filling 269 rows with grel:\\\"https://www.wikidata.org/wiki/\\\"+cell.recon.match.id\"," + + "\"time\":\"2018-08-07T09:06:37Z\"," + + "\"operation\":{\"op\":\"core/column-addition\"," + + " \"description\":\"Create column uri at index 2 based on column country using expression grel:\\\"https://www.wikidata.org/wiki/\\\"+cell.recon.match.id\"," + + " \"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]}," + + " \"newColumnName\":\"uri\"," + + " \"columnInsertIndex\":2," + + " \"baseColumnName\":\"country\"," + + " \"expression\":\"grel:\\\"https://www.wikidata.org/wiki/\\\"+cell.recon.match.id\"," + + " \"onError\":\"set-to-blank\"}" + + "}"; + String jsonSimple = "{" + + "\"id\":1533633623158," + + "\"description\":\"Create new column uri based on column country by filling 269 rows with grel:\\\"https://www.wikidata.org/wiki/\\\"+cell.recon.match.id\"," + + "\"time\":\"2018-08-07T09:06:37Z\"}"; + + HistoryEntry historyEntry = HistoryEntry.load(project, json); + TestUtils.isSerializedTo(historyEntry, jsonSimple); + Properties options = new Properties(); + options.setProperty("mode", "save"); + TestUtils.isSerializedTo(historyEntry, json, options); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/history/HistoryTests.java b/main/tests/server/src/com/google/refine/tests/history/HistoryTests.java index 70e093de7..759fa8273 100644 --- a/main/tests/server/src/com/google/refine/tests/history/HistoryTests.java +++ b/main/tests/server/src/com/google/refine/tests/history/HistoryTests.java @@ -49,9 +49,12 @@ import org.testng.annotations.Test; import com.google.refine.ProjectManager; import com.google.refine.history.History; import com.google.refine.history.HistoryEntry; +import com.google.refine.history.HistoryEntryManager; import com.google.refine.model.Project; import com.google.refine.model.metadata.ProjectMetadata; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; +import com.google.refine.history.Change; public class HistoryTests extends RefineTest { @@ -66,13 +69,23 @@ public class HistoryTests extends RefineTest { //dependencies Project proj; + ProjectMetadata projectMetadata; ProjectManager projectManager; + HistoryEntryManager historyEntryManager; @BeforeMethod public void SetUp(){ projectManager = mock(ProjectManager.class); + historyEntryManager = mock(HistoryEntryManager.class); ProjectManager.singleton = projectManager; + proj = new Project(); + projectMetadata = mock(ProjectMetadata.class); + + when(projectManager.getProject(Mockito.anyLong())).thenReturn(proj); + when(projectManager.getProjectMetadata(Mockito.anyLong())).thenReturn(projectMetadata); + when(projectManager.getHistoryEntryManager()).thenReturn(historyEntryManager); + SUT = new History(proj); } @@ -86,17 +99,51 @@ public class HistoryTests extends RefineTest { public void canAddEntry(){ //local dependencies HistoryEntry entry = mock(HistoryEntry.class); - Project project = mock(Project.class); - ProjectMetadata projectMetadata = mock(ProjectMetadata.class); - - when(projectManager.getProject(Mockito.anyLong())).thenReturn(project); - when(projectManager.getProjectMetadata(Mockito.anyLong())).thenReturn(projectMetadata); SUT.addEntry(entry); verify(projectManager, times(1)).getProject(Mockito.anyLong()); - verify(entry, times(1)).apply(project); + verify(entry, times(1)).apply(proj); verify(projectMetadata, times(1)).updateModified(); Assert.assertEquals(SUT.getLastPastEntries(1).get(0), entry); } + + @Test + public void serializeHistory() throws Exception { + String json1 = "{\"id\":1533650900300," + + "\"description\":\"Reconcile cells in column organization_name to type Q43229\"," + + "\"time\":\"2018-08-07T13:57:17Z\"," + + "\"operation\":{" + + " \"op\":\"core/recon\"," + + " \"description\":\"Reconcile cells in column organization_name to type Q43229\"," + + " \"columnName\":\"organization_name\"," + + " \"config\":{" + + " \"mode\":\"standard-service\"," + + " \"service\":\"https://tools.wmflabs.org/openrefine-wikidata/en/api\"," + + " \"identifierSpace\":\"http://www.wikidata.org/entity/\"," + + " \"schemaSpace\":\"http://www.wikidata.org/prop/direct/\"," + + " \"type\":{\"id\":\"Q43229\",\"name\":\"organization\"}," + + " \"autoMatch\":true," + + " \"columnDetails\":[]," + + " \"limit\":0}," + + "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]}}}"; + String json1simple = "{\"id\":1533650900300," + + "\"description\":\"Reconcile cells in column organization_name to type Q43229\"," + + "\"time\":\"2018-08-07T13:57:17Z\"}"; + String json2 = "{\"id\":1533651586483," + + "\"description\":\"Edit single cell on row 94, column organization_id\"," + + "\"time\":\"2018-08-07T14:18:21Z\"}"; + + String targetJson = "{\"past\":["+json1simple+","+json2+"],\"future\":[]}"; + + com.google.refine.history.Change dummyChange = mock(Change.class); + + HistoryEntry firstEntry = HistoryEntry.load(proj, json1); + firstEntry.setChange(dummyChange); + HistoryEntry secondEntry = HistoryEntry.load(proj, json2); + secondEntry.setChange(dummyChange); + SUT.addEntry(firstEntry); + SUT.addEntry(secondEntry); + TestUtils.isSerializedTo(SUT, targetJson); + } } From debe9bde373f7797a0d22c567d0a4a331bb6dbdd Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Tue, 21 Aug 2018 15:43:36 +0100 Subject: [PATCH 18/26] Serialization test for EvalError --- .../src/com/google/refine/expr/EvalErrorTests.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 main/tests/server/src/com/google/refine/expr/EvalErrorTests.java diff --git a/main/tests/server/src/com/google/refine/expr/EvalErrorTests.java b/main/tests/server/src/com/google/refine/expr/EvalErrorTests.java new file mode 100644 index 000000000..3156e3a93 --- /dev/null +++ b/main/tests/server/src/com/google/refine/expr/EvalErrorTests.java @@ -0,0 +1,13 @@ +package com.google.refine.expr; + +import org.testng.annotations.Test; + +import com.google.refine.tests.util.TestUtils; + +public class EvalErrorTests { + @Test + public void serializeEvalError() { + EvalError e = new EvalError("this is a critical error"); + TestUtils.isSerializedTo(e, "{\"type\":\"error\",\"message\":\"This is a critical error\"}"); + } +} From 580fd92c10a8d00482fbea0dc10f88bd0cfa44e7 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Tue, 21 Aug 2018 16:08:05 +0100 Subject: [PATCH 19/26] Add JSON serialization tests for processes --- .../tests/process/HistoryProcessTests.java | 44 +++++++++++++++++++ .../process/LongRunningProcessTests.java | 33 ++++++++++++++ .../tests/process/ProcessManagerTests.java | 31 +++++++++++++ .../QuickHistoryEntryProcessTests.java | 40 +++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 main/tests/server/src/com/google/refine/tests/process/HistoryProcessTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/process/LongRunningProcessTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/process/ProcessManagerTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/process/QuickHistoryEntryProcessTests.java diff --git a/main/tests/server/src/com/google/refine/tests/process/HistoryProcessTests.java b/main/tests/server/src/com/google/refine/tests/process/HistoryProcessTests.java new file mode 100644 index 000000000..0c4da94da --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/process/HistoryProcessTests.java @@ -0,0 +1,44 @@ +package com.google.refine.tests.process; + +import static org.mockito.Mockito.mock; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.google.refine.ProjectManager; +import com.google.refine.history.Change; +import com.google.refine.history.HistoryEntry; +import com.google.refine.history.HistoryProcess; +import com.google.refine.model.AbstractOperation; +import com.google.refine.model.Project; +import com.google.refine.model.metadata.ProjectMetadata; +import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; + +public class HistoryProcessTests extends RefineTest { + + private Project project; + private ProjectMetadata projectMetadata; + + @BeforeMethod + public void setUp() { + project = new Project(); + projectMetadata = mock(ProjectMetadata.class); + ProjectManager.singleton.registerProject(project, projectMetadata); + AbstractOperation op = mock(AbstractOperation.class); + Change ch = mock(Change.class); + HistoryEntry entry = new HistoryEntry(1234L, project, "first operation", op, ch); + project.history.addEntry(entry); + entry = new HistoryEntry(5678L, project, "second operation", op, ch); + project.history.addEntry(entry); + } + + @Test + public void serializeHistoryProcess() { + HistoryProcess process = new HistoryProcess(project, 1234L); + TestUtils.isSerializedTo(process, "{" + + "\"description\":\"Undo/redo until after first operation\"," + + "\"immediate\":true," + + "\"status\":\"pending\"}"); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/process/LongRunningProcessTests.java b/main/tests/server/src/com/google/refine/tests/process/LongRunningProcessTests.java new file mode 100644 index 000000000..6afab6845 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/process/LongRunningProcessTests.java @@ -0,0 +1,33 @@ +package com.google.refine.tests.process; + +import org.testng.annotations.Test; + +import com.google.refine.process.LongRunningProcess; +import com.google.refine.tests.util.TestUtils; + +public class LongRunningProcessTests { + + public static class LongRunningProcessStub extends LongRunningProcess { + + protected LongRunningProcessStub(String description) { + super(description); + } + + @Override + protected Runnable getRunnable() { + return null; + } + + } + @Test + public void serializeLongRunningProcess() { + LongRunningProcess process = new LongRunningProcessStub("some description"); + int hashCode = process.hashCode(); + TestUtils.isSerializedTo(process, "{" + + "\"id\":"+hashCode+"," + + "\"description\":\"some description\"," + + "\"immediate\":false," + + "\"status\":\"pending\"," + + "\"progress\":0}"); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/process/ProcessManagerTests.java b/main/tests/server/src/com/google/refine/tests/process/ProcessManagerTests.java new file mode 100644 index 000000000..6a366518b --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/process/ProcessManagerTests.java @@ -0,0 +1,31 @@ +package com.google.refine.tests.process; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.google.refine.process.LongRunningProcess; +import com.google.refine.process.ProcessManager; +import com.google.refine.process.Process; +import com.google.refine.tests.util.TestUtils; +import com.google.refine.util.JSONUtilities; + +public class ProcessManagerTests { + + ProcessManager processManager; + Process process; + + @BeforeMethod + public void setUp() { + processManager = new ProcessManager(); + process = new LongRunningProcessTests.LongRunningProcessStub("some description"); + + } + + @Test + public void serializeProcessManager() throws Exception { + processManager.queueProcess(process); + String processJson = JSONUtilities.serialize(process); + TestUtils.isSerializedTo(processManager, "{" + + "\"processes\":["+processJson+"]}"); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/process/QuickHistoryEntryProcessTests.java b/main/tests/server/src/com/google/refine/tests/process/QuickHistoryEntryProcessTests.java new file mode 100644 index 000000000..538eb3b01 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/process/QuickHistoryEntryProcessTests.java @@ -0,0 +1,40 @@ +package com.google.refine.tests.process; + +import static org.mockito.Mockito.mock; +import org.testng.annotations.Test; + +import com.google.refine.history.HistoryEntry; +import com.google.refine.model.Project; +import com.google.refine.process.QuickHistoryEntryProcess; +import com.google.refine.tests.util.TestUtils; +import com.google.refine.process.Process; + +public class QuickHistoryEntryProcessTests { + public static class QuickHistoryEntryProcessStub extends QuickHistoryEntryProcess { + + public QuickHistoryEntryProcessStub(Project project, String briefDescription) { + super(project, briefDescription); + + } + + @Override + protected HistoryEntry createHistoryEntry(long historyEntryID) + throws Exception { + return null; + } + + } + + @Test + public void serializeQuickHistoryEntryProcess() { + Project project = mock(Project.class); + Process process = new QuickHistoryEntryProcessStub(project, "quick description"); + int hashCode = process.hashCode(); + TestUtils.isSerializedTo(process, "{" + + "\"id\":"+hashCode+"," + + "\"description\":" + + "\"quick description\"," + + "\"immediate\":true," + + "\"status\":\"pending\"}"); + } +} From da9978b365ef7f379eb2a7cb411fd322042e8d80 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Tue, 21 Aug 2018 17:26:14 +0200 Subject: [PATCH 20/26] Add serialization tests for preference classes --- .../com/google/refine/util/JSONUtilities.java | 17 ++++++++++++ .../preference/PreferenceStoreTests.java | 24 +++++++++++++++++ .../refine/tests/preference/TopListTests.java | 27 +++++++++++++++++++ .../google/refine/tests/util/TestUtils.java | 6 ++--- 4 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 main/tests/server/src/com/google/refine/tests/preference/PreferenceStoreTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/preference/TopListTests.java diff --git a/main/src/com/google/refine/util/JSONUtilities.java b/main/src/com/google/refine/util/JSONUtilities.java index 967633cdb..db88eeb79 100644 --- a/main/src/com/google/refine/util/JSONUtilities.java +++ b/main/src/com/google/refine/util/JSONUtilities.java @@ -33,6 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.util; +import java.io.StringWriter; +import java.io.Writer; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.OffsetDateTime; @@ -42,12 +44,15 @@ import java.util.Calendar; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Properties; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONWriter; +import com.google.refine.Jsonizable; + public class JSONUtilities { static public JSONObject getObject(JSONObject obj, String key) { try { @@ -371,4 +376,16 @@ public class JSONUtilities { destArray.put(srcArray.get(i)); } } + + static public String serialize(Jsonizable obj, Properties options) { + Writer w = new StringWriter(); + JSONWriter jsonWriter = new JSONWriter(w); + obj.write(jsonWriter, options); + return w.toString(); + } + + static public String serialize(Jsonizable obj) { + Properties options = new Properties(); + return serialize(obj, options); + } } diff --git a/main/tests/server/src/com/google/refine/tests/preference/PreferenceStoreTests.java b/main/tests/server/src/com/google/refine/tests/preference/PreferenceStoreTests.java new file mode 100644 index 000000000..f71a42016 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/preference/PreferenceStoreTests.java @@ -0,0 +1,24 @@ +package com.google.refine.tests.preference; + +import org.json.JSONObject; +import org.testng.annotations.Test; + +import com.google.refine.preference.PreferenceStore; +import com.google.refine.tests.util.TestUtils; + +public class PreferenceStoreTests { + @Test + public void serializePreferenceStore() { + String json = "{" + + "\"entries\":{" + + " \"reconciliation.standardServices\":[" + + " {\"propose_properties\":{\"service_url\":\"https://tools.wmflabs.org/openrefine-wikidata\",\"service_path\":\"/en/propose_properties\"}},\"preview\":{\"width\":320,\"url\":\"https://tools.wmflabs.org/openrefine-wikidata/en/preview?id={{id}}\",\"height\":90},\"view\":{\"url\":\"https://www.wikidata.org/wiki/{{id}}\"},\"ui\":{\"handler\":\"ReconStandardServicePanel\"},\"identifierSpace\":\"http://www.wikidata.org/entity/\",\"name\":\"Wikidata Reconciliation for OpenRefine (en)\",\"suggest\":{\"property\":{\"flyout_service_path\":\"/en/flyout/property?id=${id}\",\"service_url\":\"https://tools.wmflabs.org/openrefine-wikidata\",\"service_path\":\"/en/suggest/property\"},\"type\":{\"flyout_service_path\":\"/en/flyout/type?id=${id}\",\"service_url\":\"https://tools.wmflabs.org/openrefine-wikidata\",\"service_path\":\"/en/suggest/type\"},\"entity\":{\"flyout_service_path\":\"/en/flyout/entity?id=${id}\",\"service_url\":\"https://tools.wmflabs.org/openrefine-wikidata\",\"service_path\":\"/en/suggest/entity\"}},\"defaultTypes\":[{\"name\":\"entity\",\"id\":\"Q35120\"}],\"url\":\"https://tools.wmflabs.org/openrefine-wikidata/en/api\",\"schemaSpace\":\"http://www.wikidata.org/prop/direct/\"}" + + " ]," + + " \"scripting.starred-expressions\":{\"class\":\"com.google.refine.preference.TopList\",\"top\":2147483647,\"list\":[]}," + + " \"scripting.expressions\":{\"class\":\"com.google.refine.preference.TopList\",\"top\":100,\"list\":[]}" + + "}}"; + PreferenceStore prefStore = new PreferenceStore(); + prefStore.load(new JSONObject(json)); + TestUtils.isSerializedTo(prefStore, json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/preference/TopListTests.java b/main/tests/server/src/com/google/refine/tests/preference/TopListTests.java new file mode 100644 index 000000000..e9ed000d5 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/preference/TopListTests.java @@ -0,0 +1,27 @@ +package com.google.refine.tests.preference; + +import org.json.JSONObject; +import org.testng.annotations.Test; + +import com.google.refine.preference.TopList; +import com.google.refine.tests.util.TestUtils; + +public class TopListTests { + @Test + public void serializeTopList() { + String json = "{" + + "\"class\":\"com.google.refine.preference.TopList\"," + + "\"top\":100," + + "\"list\":[" + + " \"grel:value.parseJson()[\\\"end-date\\\"][\\\"year\\\"][\\\"value\\\"]\"," + + " \"grel:value.parseJson()[\\\"start-date\\\"][\\\"year\\\"][\\\"value\\\"]\"," + + " \"grel:value.parseJson()[\\\"organization\\\"][\\\"disambiguated-organization\\\"][\\\"disambiguated-organization-identifier\\\"]\"," + + " \"grel:value.parseJson()[\\\"organization\\\"][\\\"address\\\"][\\\"country\\\"]\",\"grel:value.parseJson()[\\\"organization\\\"][\\\"name\\\"]\"," + + " \"grel:value.parseJson()[\\\"employment-summary\\\"].join('###')\"," + + " \"grel:\\\"https://pub.orcid.org/\\\"+value+\\\"/employments\\\"\"" + + "]}"; + TestUtils.isSerializedTo( + TopList.load(new JSONObject(json)), + json); + } +} diff --git a/main/tests/server/src/com/google/refine/tests/util/TestUtils.java b/main/tests/server/src/com/google/refine/tests/util/TestUtils.java index 54d772ffd..e148f8252 100644 --- a/main/tests/server/src/com/google/refine/tests/util/TestUtils.java +++ b/main/tests/server/src/com/google/refine/tests/util/TestUtils.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.refine.Jsonizable; +import com.google.refine.util.JSONUtilities; import com.google.refine.util.ParsingUtilities; @@ -59,10 +60,7 @@ public class TestUtils { * Checks that a serializable object is serialized to the target JSON string. */ public static void isSerializedTo(Jsonizable o, String targetJson, Properties options) { - Writer w = new StringWriter(); - JSONWriter jsonWriter = new JSONWriter(w); - o.write(jsonWriter, options); - equalAsJson(targetJson, w.toString()); + equalAsJson(targetJson, JSONUtilities.serialize(o, options)); } /** From 953a7380fe17ea4f8df678b4644f6efb4a2ec95d Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Tue, 21 Aug 2018 17:31:21 +0200 Subject: [PATCH 21/26] Cleanup imports --- .../src/com/google/refine/tests/ProjectManagerStub.java | 2 -- .../refine/tests/expr/functions/FunctionTests.java | 1 - .../tests/expr/functions/booleans/BooleanTests.java | 1 - .../com/google/refine/tests/importers/ImporterTest.java | 5 ++--- .../refine/tests/importing/ImportingUtilitiesTests.java | 1 - .../tests/model/recon/StandardReconConfigTests.java | 1 - .../ColumnAdditionByFetchingURLsOperationTests.java | 1 - .../google/refine/tests/process/ProcessManagerTests.java | 3 +-- .../src/com/google/refine/tests/util/TestUtils.java | 9 --------- 9 files changed, 3 insertions(+), 21 deletions(-) diff --git a/main/tests/server/src/com/google/refine/tests/ProjectManagerStub.java b/main/tests/server/src/com/google/refine/tests/ProjectManagerStub.java index 92f8e685f..983631935 100644 --- a/main/tests/server/src/com/google/refine/tests/ProjectManagerStub.java +++ b/main/tests/server/src/com/google/refine/tests/ProjectManagerStub.java @@ -35,7 +35,6 @@ package com.google.refine.tests; import java.io.IOException; import java.io.InputStream; -import java.util.Map; import org.apache.tools.tar.TarOutputStream; @@ -43,7 +42,6 @@ import com.google.refine.ProjectManager; import com.google.refine.history.HistoryEntryManager; import com.google.refine.model.Project; import com.google.refine.model.metadata.IMetadata; -import com.google.refine.model.metadata.MetadataFormat; /** * Stub used to make protected methods public for testing diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/FunctionTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/FunctionTests.java index 31815ab96..dd185f47d 100644 --- a/main/tests/server/src/com/google/refine/tests/expr/functions/FunctionTests.java +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/FunctionTests.java @@ -52,7 +52,6 @@ import com.google.refine.model.Cell; import com.google.refine.model.ModelException; import com.google.refine.model.Project; import com.google.refine.model.Row; -import com.google.refine.model.metadata.ProjectMetadata; import com.google.refine.tests.RefineTest; diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/booleans/BooleanTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/booleans/BooleanTests.java index 6279475a4..7862688c7 100644 --- a/main/tests/server/src/com/google/refine/tests/expr/functions/booleans/BooleanTests.java +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/booleans/BooleanTests.java @@ -50,7 +50,6 @@ import com.google.refine.model.Cell; import com.google.refine.model.ModelException; import com.google.refine.model.Project; import com.google.refine.model.Row; -import com.google.refine.model.metadata.ProjectMetadata; import com.google.refine.tests.RefineTest; diff --git a/main/tests/server/src/com/google/refine/tests/importers/ImporterTest.java b/main/tests/server/src/com/google/refine/tests/importers/ImporterTest.java index 7aca54e25..46161e043 100644 --- a/main/tests/server/src/com/google/refine/tests/importers/ImporterTest.java +++ b/main/tests/server/src/com/google/refine/tests/importers/ImporterTest.java @@ -1,15 +1,14 @@ package com.google.refine.tests.importers; +import static org.mockito.Mockito.when; + import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; -import static org.mockito.Mockito.when; -import org.json.JSONArray; import org.json.JSONObject; import org.mockito.Mockito; diff --git a/main/tests/server/src/com/google/refine/tests/importing/ImportingUtilitiesTests.java b/main/tests/server/src/com/google/refine/tests/importing/ImportingUtilitiesTests.java index 9e591609c..7bcf306bc 100644 --- a/main/tests/server/src/com/google/refine/tests/importing/ImportingUtilitiesTests.java +++ b/main/tests/server/src/com/google/refine/tests/importing/ImportingUtilitiesTests.java @@ -15,7 +15,6 @@ import com.google.refine.importers.tree.TreeImportingParserBase; import com.google.refine.importing.ImportingJob; import com.google.refine.importing.ImportingManager; import com.google.refine.importing.ImportingUtilities; -import com.google.refine.model.Column; import com.google.refine.model.metadata.ProjectMetadata; import com.google.refine.tests.importers.ImporterTest; import com.google.refine.util.JSONUtilities; diff --git a/main/tests/server/src/com/google/refine/tests/model/recon/StandardReconConfigTests.java b/main/tests/server/src/com/google/refine/tests/model/recon/StandardReconConfigTests.java index 6f02bbb46..470f1ecfe 100644 --- a/main/tests/server/src/com/google/refine/tests/model/recon/StandardReconConfigTests.java +++ b/main/tests/server/src/com/google/refine/tests/model/recon/StandardReconConfigTests.java @@ -2,7 +2,6 @@ package com.google.refine.tests.model.recon; import java.util.ArrayList; -import org.json.JSONException; import org.json.JSONObject; import org.slf4j.LoggerFactory; import org.testng.Assert; diff --git a/main/tests/server/src/com/google/refine/tests/operations/column/ColumnAdditionByFetchingURLsOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/column/ColumnAdditionByFetchingURLsOperationTests.java index 0e834f6e4..0d28b1fc9 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/column/ColumnAdditionByFetchingURLsOperationTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/column/ColumnAdditionByFetchingURLsOperationTests.java @@ -47,7 +47,6 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.refine.expr.ExpressionUtils; -import com.google.refine.model.AbstractOperation; import com.google.refine.model.Cell; import com.google.refine.model.ModelException; import com.google.refine.model.Project; diff --git a/main/tests/server/src/com/google/refine/tests/process/ProcessManagerTests.java b/main/tests/server/src/com/google/refine/tests/process/ProcessManagerTests.java index 6a366518b..2e34388c9 100644 --- a/main/tests/server/src/com/google/refine/tests/process/ProcessManagerTests.java +++ b/main/tests/server/src/com/google/refine/tests/process/ProcessManagerTests.java @@ -3,9 +3,8 @@ package com.google.refine.tests.process; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import com.google.refine.process.LongRunningProcess; -import com.google.refine.process.ProcessManager; import com.google.refine.process.Process; +import com.google.refine.process.ProcessManager; import com.google.refine.tests.util.TestUtils; import com.google.refine.util.JSONUtilities; diff --git a/main/tests/server/src/com/google/refine/tests/util/TestUtils.java b/main/tests/server/src/com/google/refine/tests/util/TestUtils.java index e148f8252..630385195 100644 --- a/main/tests/server/src/com/google/refine/tests/util/TestUtils.java +++ b/main/tests/server/src/com/google/refine/tests/util/TestUtils.java @@ -5,22 +5,13 @@ import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONObject; -import org.json.JSONWriter; - -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.refine.Jsonizable; import com.google.refine.util.JSONUtilities; -import com.google.refine.util.ParsingUtilities; public class TestUtils { From 326fda7999451e1577bee8aec930a291d8bb588c Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Tue, 21 Aug 2018 17:44:45 +0200 Subject: [PATCH 22/26] Add JSON serialization tests for NominalFacetChoice --- .../facets/NominalFacetChoiceTests.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 main/tests/server/src/com/google/refine/tests/browsing/facets/NominalFacetChoiceTests.java diff --git a/main/tests/server/src/com/google/refine/tests/browsing/facets/NominalFacetChoiceTests.java b/main/tests/server/src/com/google/refine/tests/browsing/facets/NominalFacetChoiceTests.java new file mode 100644 index 000000000..d0af0b29c --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/browsing/facets/NominalFacetChoiceTests.java @@ -0,0 +1,23 @@ +package com.google.refine.tests.browsing.facets; + +import org.testng.annotations.Test; + +import com.google.refine.browsing.DecoratedValue; +import com.google.refine.browsing.facets.NominalFacetChoice; +import com.google.refine.tests.util.TestUtils; + +public class NominalFacetChoiceTests { + @Test + public void serializeNominalFacetChoice() { + DecoratedValue value = new DecoratedValue("some string", "some string"); + NominalFacetChoice choice = new NominalFacetChoice(value); + choice.count = 3; + choice.selected = true; + TestUtils.isSerializedTo(choice, "{" + + "\"v\":" + + " {\"v\":\"some string\"," + + " \"l\":\"some string\"}," + + "\"c\":3," + + "\"s\":true}"); + } +} From 802ad77ec50863390c48df922055ba893bd266cd Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Tue, 21 Aug 2018 18:13:06 +0200 Subject: [PATCH 23/26] Add serialization tests for GREL controls --- .../refine/tests/grel/controls/FilterTests.java | 15 +++++++++++++++ .../tests/grel/controls/ForEachIndexTests.java | 15 +++++++++++++++ .../refine/tests/grel/controls/ForEachTests.java | 15 +++++++++++++++ .../tests/grel/controls/ForNonBlankTests.java | 15 +++++++++++++++ .../refine/tests/grel/controls/ForRangeTests.java | 15 +++++++++++++++ .../refine/tests/grel/controls/IfTests.java | 15 +++++++++++++++ .../refine/tests/grel/controls/IsBlankTests.java | 15 +++++++++++++++ .../tests/grel/controls/IsEmptyStringTests.java | 15 +++++++++++++++ .../refine/tests/grel/controls/IsErrorTests.java | 15 +++++++++++++++ .../tests/grel/controls/IsNonBlankTests.java | 15 +++++++++++++++ .../tests/grel/controls/IsNotNullTests.java | 15 +++++++++++++++ .../refine/tests/grel/controls/IsNullTests.java | 15 +++++++++++++++ .../tests/grel/controls/IsNumericTests.java | 15 +++++++++++++++ .../refine/tests/grel/controls/WithTests.java | 15 +++++++++++++++ 14 files changed, 210 insertions(+) create mode 100644 main/tests/server/src/com/google/refine/tests/grel/controls/FilterTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/grel/controls/ForEachIndexTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/grel/controls/ForEachTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/grel/controls/ForNonBlankTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/grel/controls/ForRangeTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/grel/controls/IfTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/grel/controls/IsBlankTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/grel/controls/IsEmptyStringTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/grel/controls/IsErrorTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/grel/controls/IsNonBlankTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/grel/controls/IsNotNullTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/grel/controls/IsNullTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/grel/controls/IsNumericTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/grel/controls/WithTests.java diff --git a/main/tests/server/src/com/google/refine/tests/grel/controls/FilterTests.java b/main/tests/server/src/com/google/refine/tests/grel/controls/FilterTests.java new file mode 100644 index 000000000..fb8cc5d49 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/grel/controls/FilterTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.grel.controls; + +import org.testng.annotations.Test; + +import com.google.refine.grel.controls.Filter; +import com.google.refine.tests.util.TestUtils; + +public class FilterTests { + @Test + public void serializeFilter() { + String json = "{\"description\":\"Evaluates expression a to an array. Then for each array element, binds its value to variable name v, evaluates expression test which should return a boolean. If the boolean is true, pushes v onto the result array.\",\"params\":\"expression a, variable v, expression test\",\"returns\":\"array\"}"; + TestUtils.isSerializedTo(new Filter(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/grel/controls/ForEachIndexTests.java b/main/tests/server/src/com/google/refine/tests/grel/controls/ForEachIndexTests.java new file mode 100644 index 000000000..9cc789ed4 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/grel/controls/ForEachIndexTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.grel.controls; + +import org.testng.annotations.Test; + +import com.google.refine.grel.controls.ForEachIndex; +import com.google.refine.tests.util.TestUtils; + +public class ForEachIndexTests { + @Test + public void serializeForEachIndex() { + String json = "{\"description\":\"Evaluates expression a to an array. Then for each array element, binds its index to variable i and its value to variable name v, evaluates expression e, and pushes the result onto the result array.\",\"params\":\"expression a, variable i, variable v, expression e\",\"returns\":\"array\"}"; + TestUtils.isSerializedTo(new ForEachIndex(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/grel/controls/ForEachTests.java b/main/tests/server/src/com/google/refine/tests/grel/controls/ForEachTests.java new file mode 100644 index 000000000..26b72aad4 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/grel/controls/ForEachTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.grel.controls; + +import org.testng.annotations.Test; + +import com.google.refine.grel.controls.ForEach; +import com.google.refine.tests.util.TestUtils; + +public class ForEachTests { + @Test + public void serializeForEach() { + String json = "{\"description\":\"Evaluates expression a to an array. Then for each array element, binds its value to variable name v, evaluates expression e, and pushes the result onto the result array.\",\"params\":\"expression a, variable v, expression e\",\"returns\":\"array\"}"; + TestUtils.isSerializedTo(new ForEach(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/grel/controls/ForNonBlankTests.java b/main/tests/server/src/com/google/refine/tests/grel/controls/ForNonBlankTests.java new file mode 100644 index 000000000..e1e74ac5a --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/grel/controls/ForNonBlankTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.grel.controls; + +import org.testng.annotations.Test; + +import com.google.refine.grel.controls.ForNonBlank; +import com.google.refine.tests.util.TestUtils; + +public class ForNonBlankTests { + @Test + public void serializeForNonBlank() { + String json = "{\"description\":\"Evaluates expression o. If it is non-blank, binds its value to variable name v, evaluates expression eNonBlank and returns the result. Otherwise (if o evaluates to blank), evaluates expression eBlank and returns that result instead.\",\"params\":\"expression o, variable v, expression eNonBlank, expression eBlank\",\"returns\":\"Depends on actual arguments\"}"; + TestUtils.isSerializedTo(new ForNonBlank(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/grel/controls/ForRangeTests.java b/main/tests/server/src/com/google/refine/tests/grel/controls/ForRangeTests.java new file mode 100644 index 000000000..6a35eda85 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/grel/controls/ForRangeTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.grel.controls; + +import org.testng.annotations.Test; + +import com.google.refine.grel.controls.ForRange; +import com.google.refine.tests.util.TestUtils; + +public class ForRangeTests { + @Test + public void serializeForRange() { + String json = "{\"description\":\"Iterates over the variable v starting at \\\"from\\\", incrementing by \\\"step\\\" each time while less than \\\"to\\\". At each iteration, evaluates expression e, and pushes the result onto the result array.\",\"params\":\"number from, number to, number step, variable v, expression e\",\"returns\":\"array\"}"; + TestUtils.isSerializedTo(new ForRange(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/grel/controls/IfTests.java b/main/tests/server/src/com/google/refine/tests/grel/controls/IfTests.java new file mode 100644 index 000000000..70b36f5e8 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/grel/controls/IfTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.grel.controls; + +import org.testng.annotations.Test; + +import com.google.refine.grel.controls.If; +import com.google.refine.tests.util.TestUtils; + +public class IfTests { + @Test + public void serializeIf() { + String json = "{\"description\":\"Evaluates expression o. If it is true, evaluates expression eTrue and returns the result. Otherwise, evaluates expression eFalse and returns that result instead.\",\"params\":\"expression o, expression eTrue, expression eFalse\",\"returns\":\"Depends on actual arguments\"}"; + TestUtils.isSerializedTo(new If(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/grel/controls/IsBlankTests.java b/main/tests/server/src/com/google/refine/tests/grel/controls/IsBlankTests.java new file mode 100644 index 000000000..f2bd422c4 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/grel/controls/IsBlankTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.grel.controls; + +import org.testng.annotations.Test; + +import com.google.refine.grel.controls.IsBlank; +import com.google.refine.tests.util.TestUtils; + +public class IsBlankTests { + @Test + public void serializeIsBlank() { + String json = "{\"description\":\"Returns whether o is null or an empty string\",\"params\":\"expression o\",\"returns\":\"boolean\"}"; + TestUtils.isSerializedTo(new IsBlank(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/grel/controls/IsEmptyStringTests.java b/main/tests/server/src/com/google/refine/tests/grel/controls/IsEmptyStringTests.java new file mode 100644 index 000000000..54df66954 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/grel/controls/IsEmptyStringTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.grel.controls; + +import org.testng.annotations.Test; + +import com.google.refine.grel.controls.IsEmptyString; +import com.google.refine.tests.util.TestUtils; + +public class IsEmptyStringTests { + @Test + public void serializeIsEmptyString() { + String json = "{\"description\":\"Returns whether o is an empty string\",\"params\":\"expression o\",\"returns\":\"boolean\"}"; + TestUtils.isSerializedTo(new IsEmptyString(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/grel/controls/IsErrorTests.java b/main/tests/server/src/com/google/refine/tests/grel/controls/IsErrorTests.java new file mode 100644 index 000000000..036d06771 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/grel/controls/IsErrorTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.grel.controls; + +import org.testng.annotations.Test; + +import com.google.refine.grel.controls.IsError; +import com.google.refine.tests.util.TestUtils; + +public class IsErrorTests { + @Test + public void serializeIsError() { + String json = "{\"description\":\"Returns whether o is an error\",\"params\":\"expression o\",\"returns\":\"boolean\"}"; + TestUtils.isSerializedTo(new IsError(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/grel/controls/IsNonBlankTests.java b/main/tests/server/src/com/google/refine/tests/grel/controls/IsNonBlankTests.java new file mode 100644 index 000000000..4ae8127ff --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/grel/controls/IsNonBlankTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.grel.controls; + +import org.testng.annotations.Test; + +import com.google.refine.grel.controls.IsNonBlank; +import com.google.refine.tests.util.TestUtils; + +public class IsNonBlankTests { + @Test + public void serializeIsNonBlank() { + String json = "{\"description\":\"Returns whether o is not null and not an empty string\",\"params\":\"expression o\",\"returns\":\"boolean\"}"; + TestUtils.isSerializedTo(new IsNonBlank(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/grel/controls/IsNotNullTests.java b/main/tests/server/src/com/google/refine/tests/grel/controls/IsNotNullTests.java new file mode 100644 index 000000000..d0a272e33 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/grel/controls/IsNotNullTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.grel.controls; + +import org.testng.annotations.Test; + +import com.google.refine.grel.controls.IsNotNull; +import com.google.refine.tests.util.TestUtils; + +public class IsNotNullTests { + @Test + public void serializeIsNotNull() { + String json = "{\"description\":\"Returns whether o is not null\",\"params\":\"expression o\",\"returns\":\"boolean\"}"; + TestUtils.isSerializedTo(new IsNotNull(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/grel/controls/IsNullTests.java b/main/tests/server/src/com/google/refine/tests/grel/controls/IsNullTests.java new file mode 100644 index 000000000..7b35aa9a8 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/grel/controls/IsNullTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.grel.controls; + +import org.testng.annotations.Test; + +import com.google.refine.grel.controls.IsNull; +import com.google.refine.tests.util.TestUtils; + +public class IsNullTests { + @Test + public void serializeIsNull() { + String json = "{\"description\":\"Returns whether o is null\",\"params\":\"expression o\",\"returns\":\"boolean\"}"; + TestUtils.isSerializedTo(new IsNull(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/grel/controls/IsNumericTests.java b/main/tests/server/src/com/google/refine/tests/grel/controls/IsNumericTests.java new file mode 100644 index 000000000..e43e4f0c4 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/grel/controls/IsNumericTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.grel.controls; + +import org.testng.annotations.Test; + +import com.google.refine.grel.controls.IsNumeric; +import com.google.refine.tests.util.TestUtils; + +public class IsNumericTests { + @Test + public void serializeIsNumeric() { + String json = "{\"description\":\"Returns whether o can represent a number\",\"params\":\"expression o\",\"returns\":\"boolean\"}"; + TestUtils.isSerializedTo(new IsNumeric(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/grel/controls/WithTests.java b/main/tests/server/src/com/google/refine/tests/grel/controls/WithTests.java new file mode 100644 index 000000000..0899f30fa --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/grel/controls/WithTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.grel.controls; + +import org.testng.annotations.Test; + +import com.google.refine.grel.controls.With; +import com.google.refine.tests.util.TestUtils; + +public class WithTests { + @Test + public void serializeWith() { + String json = "{\"description\":\"Evaluates expression o and binds its value to variable name v. Then evaluates expression e and returns that result\",\"params\":\"expression o, variable v, expression e\",\"returns\":\"Depends on actual arguments\"}"; + TestUtils.isSerializedTo(new With(), json); + } +} + From eb0a37a22a448b94c5a2d364489d395dcb528c51 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Fri, 31 Aug 2018 11:36:46 +0200 Subject: [PATCH 24/26] Fix PreferenceStore serialization test --- .../google/refine/tests/preference/PreferenceStoreTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/tests/server/src/com/google/refine/tests/preference/PreferenceStoreTests.java b/main/tests/server/src/com/google/refine/tests/preference/PreferenceStoreTests.java index f71a42016..42911dfc5 100644 --- a/main/tests/server/src/com/google/refine/tests/preference/PreferenceStoreTests.java +++ b/main/tests/server/src/com/google/refine/tests/preference/PreferenceStoreTests.java @@ -12,7 +12,7 @@ public class PreferenceStoreTests { String json = "{" + "\"entries\":{" + " \"reconciliation.standardServices\":[" - + " {\"propose_properties\":{\"service_url\":\"https://tools.wmflabs.org/openrefine-wikidata\",\"service_path\":\"/en/propose_properties\"}},\"preview\":{\"width\":320,\"url\":\"https://tools.wmflabs.org/openrefine-wikidata/en/preview?id={{id}}\",\"height\":90},\"view\":{\"url\":\"https://www.wikidata.org/wiki/{{id}}\"},\"ui\":{\"handler\":\"ReconStandardServicePanel\"},\"identifierSpace\":\"http://www.wikidata.org/entity/\",\"name\":\"Wikidata Reconciliation for OpenRefine (en)\",\"suggest\":{\"property\":{\"flyout_service_path\":\"/en/flyout/property?id=${id}\",\"service_url\":\"https://tools.wmflabs.org/openrefine-wikidata\",\"service_path\":\"/en/suggest/property\"},\"type\":{\"flyout_service_path\":\"/en/flyout/type?id=${id}\",\"service_url\":\"https://tools.wmflabs.org/openrefine-wikidata\",\"service_path\":\"/en/suggest/type\"},\"entity\":{\"flyout_service_path\":\"/en/flyout/entity?id=${id}\",\"service_url\":\"https://tools.wmflabs.org/openrefine-wikidata\",\"service_path\":\"/en/suggest/entity\"}},\"defaultTypes\":[{\"name\":\"entity\",\"id\":\"Q35120\"}],\"url\":\"https://tools.wmflabs.org/openrefine-wikidata/en/api\",\"schemaSpace\":\"http://www.wikidata.org/prop/direct/\"}" + + " {\"propose_properties\":{\"service_url\":\"https://tools.wmflabs.org/openrefine-wikidata\",\"service_path\":\"/en/propose_properties\"},\"preview\":{\"width\":320,\"url\":\"https://tools.wmflabs.org/openrefine-wikidata/en/preview?id={{id}}\",\"height\":90},\"view\":{\"url\":\"https://www.wikidata.org/wiki/{{id}}\"},\"ui\":{\"handler\":\"ReconStandardServicePanel\"},\"identifierSpace\":\"http://www.wikidata.org/entity/\",\"name\":\"Wikidata Reconciliation for OpenRefine (en)\",\"suggest\":{\"property\":{\"flyout_service_path\":\"/en/flyout/property?id=${id}\",\"service_url\":\"https://tools.wmflabs.org/openrefine-wikidata\",\"service_path\":\"/en/suggest/property\"},\"type\":{\"flyout_service_path\":\"/en/flyout/type?id=${id}\",\"service_url\":\"https://tools.wmflabs.org/openrefine-wikidata\",\"service_path\":\"/en/suggest/type\"},\"entity\":{\"flyout_service_path\":\"/en/flyout/entity?id=${id}\",\"service_url\":\"https://tools.wmflabs.org/openrefine-wikidata\",\"service_path\":\"/en/suggest/entity\"}},\"defaultTypes\":[{\"name\":\"entity\",\"id\":\"Q35120\"}],\"url\":\"https://tools.wmflabs.org/openrefine-wikidata/en/api\",\"schemaSpace\":\"http://www.wikidata.org/prop/direct/\"}" + " ]," + " \"scripting.starred-expressions\":{\"class\":\"com.google.refine.preference.TopList\",\"top\":2147483647,\"list\":[]}," + " \"scripting.expressions\":{\"class\":\"com.google.refine.preference.TopList\",\"top\":100,\"list\":[]}" From 851d24c39b5115fc7f04e397937f71cee6f7c19e Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Fri, 31 Aug 2018 11:38:32 +0200 Subject: [PATCH 25/26] Add serialization tests for GREL functions --- .../tests/expr/functions/CoalesceTests.java | 8 ++++++++ .../refine/tests/expr/functions/CrossTests.java | 15 +++++++++++++++ .../tests/expr/functions/FacetCountTests.java | 15 +++++++++++++++ .../refine/tests/expr/functions/GetTests.java | 15 +++++++++++++++ .../tests/expr/functions/HasFieldTests.java | 15 +++++++++++++++ .../refine/tests/expr/functions/JsonizeTests.java | 15 +++++++++++++++ .../refine/tests/expr/functions/LengthTests.java | 15 +++++++++++++++ .../refine/tests/expr/functions/SliceTests.java | 15 +++++++++++++++ .../refine/tests/expr/functions/ToDateTests.java | 15 +++++++++++++++ .../tests/expr/functions/ToNumberTests.java | 15 +++++++++++++++ .../tests/expr/functions/ToStringTests.java | 15 +++++++++++++++ .../refine/tests/expr/functions/TypeTests.java | 15 +++++++++++++++ .../tests/expr/functions/arrays/JoinTests.java | 15 +++++++++++++++ .../tests/expr/functions/arrays/ReverseTests.java | 15 +++++++++++++++ .../tests/expr/functions/arrays/SortTests.java | 15 +++++++++++++++ .../tests/expr/functions/arrays/UniquesTests.java | 15 +++++++++++++++ .../tests/expr/functions/booleans/AndTests.java | 15 +++++++++++++++ .../tests/expr/functions/booleans/NotTests.java | 15 +++++++++++++++ .../tests/expr/functions/booleans/OrTests.java | 15 +++++++++++++++ .../tests/expr/functions/booleans/XorTests.java | 15 +++++++++++++++ .../tests/expr/functions/date/DatePartTests.java | 9 +++++++++ .../tests/expr/functions/date/IncTests.java | 9 +++++++++ .../tests/expr/functions/date/NowTests.java | 9 +++++++++ .../tests/expr/functions/html/HtmlAttrTests.java | 15 +++++++++++++++ .../tests/expr/functions/html/HtmlTextTests.java | 15 +++++++++++++++ .../tests/expr/functions/html/InnerHtmlTests.java | 15 +++++++++++++++ .../tests/expr/functions/html/OwnTextTests.java | 15 +++++++++++++++ .../tests/expr/functions/html/ParseHtmlTests.java | 15 +++++++++++++++ .../expr/functions/html/SelectHtmlTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/ACosTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/ASinTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/ATan2Tests.java | 15 +++++++++++++++ .../tests/expr/functions/math/ATanTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/AbsTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/CeilTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/CombinTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/CosTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/CoshTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/DegreesTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/EvenTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/ExpTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/FactNTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/FactTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/FloorTests.java | 15 +++++++++++++++ .../math/GreatestCommonDenominatorTests.java | 15 +++++++++++++++ .../functions/math/LeastCommonMultipleTests.java | 15 +++++++++++++++ .../refine/tests/expr/functions/math/LnTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/LogTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/MaxTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/MinTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/ModTests.java | 15 +++++++++++++++ .../expr/functions/math/MultinomialTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/OddTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/PowTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/QuotientTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/RadiansTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/RoundTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/SinTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/SinhTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/SumTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/TanTests.java | 15 +++++++++++++++ .../tests/expr/functions/math/TanhTests.java | 15 +++++++++++++++ .../tests/expr/functions/strings/ChompTests.java | 15 +++++++++++++++ .../expr/functions/strings/ContainsTests.java | 15 +++++++++++++++ .../tests/expr/functions/strings/DiffTests.java | 9 +++++++++ .../expr/functions/strings/EndsWithTests.java | 15 +++++++++++++++ .../tests/expr/functions/strings/EscapeTests.java | 15 +++++++++++++++ .../tests/expr/functions/strings/FindTests.java | 15 +++++++++++++++ .../expr/functions/strings/FingerprintTests.java | 10 ++++++++++ .../expr/functions/strings/IndexOfTests.java | 15 +++++++++++++++ .../expr/functions/strings/LastIndexOfTests.java | 15 +++++++++++++++ .../tests/expr/functions/strings/MD5Tests.java | 15 +++++++++++++++ .../tests/expr/functions/strings/MatchTests.java | 15 +++++++++++++++ .../functions/strings/NGramFingerprintTests.java | 15 +++++++++++++++ .../tests/expr/functions/strings/NGramTests.java | 15 +++++++++++++++ .../expr/functions/strings/ParseJsonTests.java | 15 +++++++++++++++ .../expr/functions/strings/PartitionTests.java | 15 +++++++++++++++ .../expr/functions/strings/PhoneticTests.java | 15 +++++++++++++++ .../expr/functions/strings/RPartitionTests.java | 15 +++++++++++++++ .../tests/expr/functions/strings/RangeTests.java | 9 +++++++++ .../expr/functions/strings/ReinterpretTests.java | 15 +++++++++++++++ .../expr/functions/strings/ReplaceCharsTests.java | 15 +++++++++++++++ .../expr/functions/strings/ReplaceTests.java | 15 +++++++++++++++ .../tests/expr/functions/strings/SHA1Tests.java | 15 +++++++++++++++ .../expr/functions/strings/SmartSplitTests.java | 15 +++++++++++++++ .../functions/strings/SplitByCharTypeTests.java | 15 +++++++++++++++ .../functions/strings/SplitByLengthsTests.java | 15 +++++++++++++++ .../tests/expr/functions/strings/SplitTests.java | 15 +++++++++++++++ .../expr/functions/strings/StartsWithTests.java | 15 +++++++++++++++ .../expr/functions/strings/ToLowercaseTests.java | 15 +++++++++++++++ .../expr/functions/strings/ToTitlecaseTests.java | 15 +++++++++++++++ .../expr/functions/strings/ToUppercaseTests.java | 15 +++++++++++++++ .../tests/expr/functions/strings/TrimTests.java | 8 ++++++++ .../expr/functions/strings/UnescapeTests.java | 15 +++++++++++++++ .../expr/functions/strings/UnicodeTests.java | 15 +++++++++++++++ .../expr/functions/strings/UnicodeTypeTests.java | 15 +++++++++++++++ 96 files changed, 1391 insertions(+) create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/CrossTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/FacetCountTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/GetTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/HasFieldTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/JsonizeTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/LengthTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/SliceTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/ToDateTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/ToNumberTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/ToStringTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/TypeTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/arrays/JoinTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/arrays/ReverseTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/arrays/SortTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/arrays/UniquesTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/booleans/AndTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/booleans/NotTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/booleans/OrTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/booleans/XorTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/html/HtmlAttrTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/html/HtmlTextTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/html/InnerHtmlTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/html/OwnTextTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/html/ParseHtmlTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/html/SelectHtmlTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/ACosTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/ASinTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/ATan2Tests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/ATanTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/AbsTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/CeilTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/CombinTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/CosTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/CoshTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/DegreesTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/EvenTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/ExpTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/FactNTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/FactTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/FloorTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/GreatestCommonDenominatorTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/LeastCommonMultipleTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/LnTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/LogTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/MaxTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/MinTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/ModTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/MultinomialTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/OddTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/PowTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/QuotientTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/RadiansTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/RoundTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/SinTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/SinhTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/SumTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/TanTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/math/TanhTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/ChompTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/ContainsTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/EndsWithTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/EscapeTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/FindTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/IndexOfTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/LastIndexOfTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/MD5Tests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/MatchTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/NGramFingerprintTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/NGramTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/ParseJsonTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/PartitionTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/PhoneticTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/RPartitionTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/ReinterpretTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/ReplaceCharsTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/ReplaceTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/SHA1Tests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/SmartSplitTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/SplitByCharTypeTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/SplitByLengthsTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/SplitTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/StartsWithTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToLowercaseTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToTitlecaseTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToUppercaseTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/UnescapeTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/UnicodeTests.java create mode 100644 main/tests/server/src/com/google/refine/tests/expr/functions/strings/UnicodeTypeTests.java diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/CoalesceTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/CoalesceTests.java index 3d1877b8a..c84bd9d13 100644 --- a/main/tests/server/src/com/google/refine/tests/expr/functions/CoalesceTests.java +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/CoalesceTests.java @@ -43,9 +43,11 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.refine.expr.EvalError; +import com.google.refine.expr.functions.Coalesce; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; public class CoalesceTests extends RefineTest { @@ -100,4 +102,10 @@ public class CoalesceTests extends RefineTest { Assert.assertEquals(invoke("coalesce", (Object) null, ZERO_TO_TWO),ZERO_TO_TWO); } + @Test + public void serializeCoalesce() { + String json = "{\"description\":\"Returns the first non-null from a series of values\",\"params\":\"two or more objects\",\"returns\":\"object or null\"}"; + TestUtils.isSerializedTo(new Coalesce(), json); + } + } diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/CrossTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/CrossTests.java new file mode 100644 index 000000000..e6a220c40 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/CrossTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.Cross; +import com.google.refine.tests.util.TestUtils; + +public class CrossTests { + @Test + public void serializeCross() { + String json = "{\"description\":\"join with another project by column\",\"params\":\"cell c or string value, string projectName, string columnName\",\"returns\":\"array\"}"; + TestUtils.isSerializedTo(new Cross(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/FacetCountTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/FacetCountTests.java new file mode 100644 index 000000000..1c8aad131 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/FacetCountTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.FacetCount; +import com.google.refine.tests.util.TestUtils; + +public class FacetCountTests { + @Test + public void serializeFacetCount() { + String json = "{\"description\":\"Returns the facet count corresponding to the given choice value\",\"params\":\"choiceValue, string facetExpression, string columnName\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new FacetCount(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/GetTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/GetTests.java new file mode 100644 index 000000000..c5f2701f1 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/GetTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.Get; +import com.google.refine.tests.util.TestUtils; + +public class GetTests { + @Test + public void serializeGet() { + String json = "{\"description\":\"If o has fields, returns the field named 'from' of o. If o is an array, returns o[from, to]. if o is a string, returns o.substring(from, to)\",\"params\":\"o, number or string from, optional number to\",\"returns\":\"Depends on actual arguments\"}"; + TestUtils.isSerializedTo(new Get(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/HasFieldTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/HasFieldTests.java new file mode 100644 index 000000000..eba07d540 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/HasFieldTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.HasField; +import com.google.refine.tests.util.TestUtils; + +public class HasFieldTests { + @Test + public void serializeHasField() { + String json = "{\"description\":\"Returns whether o has field name\",\"params\":\"o, string name\",\"returns\":\"boolean\"}"; + TestUtils.isSerializedTo(new HasField(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/JsonizeTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/JsonizeTests.java new file mode 100644 index 000000000..c9dc05877 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/JsonizeTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.Jsonize; +import com.google.refine.tests.util.TestUtils; + +public class JsonizeTests { + @Test + public void serializeJsonize() { + String json = "{\"description\":\"Quotes a value as a JSON literal value\",\"params\":\"value\",\"returns\":\"JSON literal value\"}"; + TestUtils.isSerializedTo(new Jsonize(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/LengthTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/LengthTests.java new file mode 100644 index 000000000..646827529 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/LengthTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.Length; +import com.google.refine.tests.util.TestUtils; + +public class LengthTests { + @Test + public void serializeLength() { + String json = "{\"description\":\"Returns the length of o\",\"params\":\"array or string o\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Length(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/SliceTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/SliceTests.java new file mode 100644 index 000000000..a9f238e54 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/SliceTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.Slice; +import com.google.refine.tests.util.TestUtils; + +public class SliceTests { + @Test + public void serializeSlice() { + String json = "{\"description\":\"If o is an array, returns o[from, to]. if o is a string, returns o.substring(from, to)\",\"params\":\"o, number from, optional number to\",\"returns\":\"Depends on actual arguments\"}"; + TestUtils.isSerializedTo(new Slice(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/ToDateTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/ToDateTests.java new file mode 100644 index 000000000..456760936 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/ToDateTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.ToDate; +import com.google.refine.tests.util.TestUtils; + +public class ToDateTests { + @Test + public void serializeToDate() { + String json = "{\"description\":\"Returns o converted to a date object, you can hint if the day or the month is listed first, or give an ordered list of possible formats using this syntax: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html\",\"params\":\"o, boolean month_first / format1, format2, ... (all optional)\",\"returns\":\"date\"}"; + TestUtils.isSerializedTo(new ToDate(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/ToNumberTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/ToNumberTests.java new file mode 100644 index 000000000..4e2dd9871 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/ToNumberTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.ToNumber; +import com.google.refine.tests.util.TestUtils; + +public class ToNumberTests { + @Test + public void serializeToNumber() { + String json = "{\"description\":\"Returns o converted to a number\",\"params\":\"o\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new ToNumber(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/ToStringTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/ToStringTests.java new file mode 100644 index 000000000..4698fa15b --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/ToStringTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.ToString; +import com.google.refine.tests.util.TestUtils; + +public class ToStringTests { + @Test + public void serializeToString() { + String json = "{\"description\":\"Returns o converted to a string\",\"params\":\"o, string format (optional)\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new ToString(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/TypeTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/TypeTests.java new file mode 100644 index 000000000..63784289d --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/TypeTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.Type; +import com.google.refine.tests.util.TestUtils; + +public class TypeTests { + @Test + public void serializeType() { + String json = "{\"description\":\"Returns the type of o\",\"params\":\"object o\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new Type(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/arrays/JoinTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/arrays/JoinTests.java new file mode 100644 index 000000000..d298c156e --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/arrays/JoinTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.arrays; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.arrays.Join; +import com.google.refine.tests.util.TestUtils; + +public class JoinTests { + @Test + public void serializeJoin() { + String json = "{\"description\":\"Returns the string obtained by joining the array a with the separator sep\",\"params\":\"array a, string sep\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new Join(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/arrays/ReverseTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/arrays/ReverseTests.java new file mode 100644 index 000000000..df0a14055 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/arrays/ReverseTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.arrays; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.arrays.Reverse; +import com.google.refine.tests.util.TestUtils; + +public class ReverseTests { + @Test + public void serializeReverse() { + String json = "{\"description\":\"Reverses array a\",\"params\":\"array a\",\"returns\":\"array\"}"; + TestUtils.isSerializedTo(new Reverse(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/arrays/SortTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/arrays/SortTests.java new file mode 100644 index 000000000..50eac7c3a --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/arrays/SortTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.arrays; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.arrays.Sort; +import com.google.refine.tests.util.TestUtils; + +public class SortTests { + @Test + public void serializeSort() { + String json = "{\"description\":\"Sorts array a\",\"params\":\"array a\",\"returns\":\"array\"}"; + TestUtils.isSerializedTo(new Sort(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/arrays/UniquesTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/arrays/UniquesTests.java new file mode 100644 index 000000000..37b1c26c7 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/arrays/UniquesTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.arrays; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.arrays.Uniques; +import com.google.refine.tests.util.TestUtils; + +public class UniquesTests { + @Test + public void serializeUniques() { + String json = "{\"description\":\"Returns array a with duplicates removed\",\"params\":\"array a\",\"returns\":\"array\"}"; + TestUtils.isSerializedTo(new Uniques(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/booleans/AndTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/booleans/AndTests.java new file mode 100644 index 000000000..772581812 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/booleans/AndTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.booleans; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.booleans.And; +import com.google.refine.tests.util.TestUtils; + +public class AndTests { + @Test + public void serializeAnd() { + String json = "{\"description\":\"AND two or more booleans to yield a boolean\",\"params\":\"boolean a, boolean b\",\"returns\":\"boolean\"}"; + TestUtils.isSerializedTo(new And(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/booleans/NotTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/booleans/NotTests.java new file mode 100644 index 000000000..4f1bec2ba --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/booleans/NotTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.booleans; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.booleans.Not; +import com.google.refine.tests.util.TestUtils; + +public class NotTests { + @Test + public void serializeNot() { + String json = "{\"description\":\"Returns the opposite of b\",\"params\":\"boolean b\",\"returns\":\"boolean\"}"; + TestUtils.isSerializedTo(new Not(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/booleans/OrTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/booleans/OrTests.java new file mode 100644 index 000000000..86d861254 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/booleans/OrTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.booleans; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.booleans.Or; +import com.google.refine.tests.util.TestUtils; + +public class OrTests { + @Test + public void serializeOr() { + String json = "{\"description\":\"OR two or more booleans to yield a boolean\",\"params\":\"boolean a, boolean b\",\"returns\":\"boolean\"}"; + TestUtils.isSerializedTo(new Or(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/booleans/XorTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/booleans/XorTests.java new file mode 100644 index 000000000..21328c05f --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/booleans/XorTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.booleans; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.booleans.Xor; +import com.google.refine.tests.util.TestUtils; + +public class XorTests { + @Test + public void serializeXor() { + String json = "{\"description\":\"XORs two or more boolean values\",\"params\":\"boolean a, boolean b\",\"returns\":\"boolean\"}"; + TestUtils.isSerializedTo(new Xor(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/date/DatePartTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/date/DatePartTests.java index f6a459882..98621d841 100644 --- a/main/tests/server/src/com/google/refine/tests/expr/functions/date/DatePartTests.java +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/date/DatePartTests.java @@ -15,9 +15,11 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import com.google.refine.expr.functions.date.DatePart; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; public class DatePartTests extends RefineTest { @@ -125,4 +127,11 @@ public class DatePartTests extends RefineTest { calendar.setTime(date); return calendar; } + + @Test + public void serializeDatePart() { + String json = "{\"description\":\"Returns part of a date\",\"params\":\"date d, string part\",\"returns\":\"date\"}"; + TestUtils.isSerializedTo(new DatePart(), json); + } + } \ No newline at end of file diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/date/IncTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/date/IncTests.java index 84138e438..5d746094d 100644 --- a/main/tests/server/src/com/google/refine/tests/expr/functions/date/IncTests.java +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/date/IncTests.java @@ -14,9 +14,11 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.refine.expr.EvalError; +import com.google.refine.expr.functions.date.Inc; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; public class IncTests extends RefineTest { @@ -115,4 +117,11 @@ public class IncTests extends RefineTest { Assert.assertTrue(invoke("inc", source, 99) instanceof EvalError); Assert.assertTrue(invoke("inc", source.toInstant().toEpochMilli(), 99, "h") instanceof EvalError); } + + @Test + public void serializeInc() { + String json = "{\"description\":\"Returns a date changed by the given amount in the given unit of time\",\"params\":\"date d, number value, string unit (default to 'hour')\",\"returns\":\"date\"}"; + TestUtils.isSerializedTo(new Inc(), json); + } + } \ No newline at end of file diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/date/NowTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/date/NowTests.java index 0a103d54f..733d1534b 100644 --- a/main/tests/server/src/com/google/refine/tests/expr/functions/date/NowTests.java +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/date/NowTests.java @@ -12,9 +12,11 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import com.google.refine.expr.functions.date.Now; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; public class NowTests extends RefineTest { @@ -67,4 +69,11 @@ public class NowTests extends RefineTest { Assert.assertTrue(invoke("now") instanceof OffsetDateTime); Assert.assertTrue(((OffsetDateTime)invoke("now")).isAfter(source)); } + + @Test + public void serializeNow() { + String json = "{\"description\":\"Returns the current time\",\"returns\":\"date\"}"; + TestUtils.isSerializedTo(new Now(), json); + } + } \ No newline at end of file diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/html/HtmlAttrTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/html/HtmlAttrTests.java new file mode 100644 index 000000000..a73b22ebc --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/html/HtmlAttrTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.html; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.html.HtmlAttr; +import com.google.refine.tests.util.TestUtils; + +public class HtmlAttrTests { + @Test + public void serializeHtmlAttr() { + String json = "{\"description\":\"Selects a value from an attribute on an Html Element\",\"params\":\"Element e, String s\",\"returns\":\"String attribute Value\"}"; + TestUtils.isSerializedTo(new HtmlAttr(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/html/HtmlTextTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/html/HtmlTextTests.java new file mode 100644 index 000000000..af0ea8678 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/html/HtmlTextTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.html; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.html.HtmlText; +import com.google.refine.tests.util.TestUtils; + +public class HtmlTextTests { + @Test + public void serializeHtmlText() { + String json = "{\"description\":\"Selects the text from within an element (including all child elements)\",\"params\":\"Element e\",\"returns\":\"String text\"}"; + TestUtils.isSerializedTo(new HtmlText(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/html/InnerHtmlTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/html/InnerHtmlTests.java new file mode 100644 index 000000000..e1ab67d16 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/html/InnerHtmlTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.html; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.html.InnerHtml; +import com.google.refine.tests.util.TestUtils; + +public class InnerHtmlTests { + @Test + public void serializeInnerHtml() { + String json = "{\"description\":\"The innerHtml of an HTML element\",\"params\":\"Element e\",\"returns\":\"String innerHtml\"}"; + TestUtils.isSerializedTo(new InnerHtml(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/html/OwnTextTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/html/OwnTextTests.java new file mode 100644 index 000000000..8eb8bb01e --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/html/OwnTextTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.html; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.html.OwnText; +import com.google.refine.tests.util.TestUtils; + +public class OwnTextTests { + @Test + public void serializeOwnText() { + String json = "{\"description\":\"Gets the text owned by this HTML element only; does not get the combined text of all children.\",\"params\":\"Element e\",\"returns\":\"String ownText\"}"; + TestUtils.isSerializedTo(new OwnText(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/html/ParseHtmlTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/html/ParseHtmlTests.java new file mode 100644 index 000000000..3182a9ee1 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/html/ParseHtmlTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.html; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.html.ParseHtml; +import com.google.refine.tests.util.TestUtils; + +public class ParseHtmlTests { + @Test + public void serializeParseHtml() { + String json = "{\"description\":\"Parses a string as HTML\",\"params\":\"string s\",\"returns\":\"HTML object\"}"; + TestUtils.isSerializedTo(new ParseHtml(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/html/SelectHtmlTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/html/SelectHtmlTests.java new file mode 100644 index 000000000..62e237c65 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/html/SelectHtmlTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.html; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.html.SelectHtml; +import com.google.refine.tests.util.TestUtils; + +public class SelectHtmlTests { + @Test + public void serializeSelectHtml() { + String json = "{\"description\":\"Selects an element from an HTML elementn using selector syntax\",\"params\":\"Element e, String s\",\"returns\":\"HTML Elements\"}"; + TestUtils.isSerializedTo(new SelectHtml(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/ACosTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/ACosTests.java new file mode 100644 index 000000000..83c2498f1 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/ACosTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.ACos; +import com.google.refine.tests.util.TestUtils; + +public class ACosTests { + @Test + public void serializeACos() { + String json = "{\"description\":\"Returns the arc cosine of an angle, in the range 0 through PI\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new ACos(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/ASinTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/ASinTests.java new file mode 100644 index 000000000..ffa829155 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/ASinTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.ASin; +import com.google.refine.tests.util.TestUtils; + +public class ASinTests { + @Test + public void serializeASin() { + String json = "{\"description\":\"Returns the arc sine of an angle in the range of -PI/2 through PI/2\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new ASin(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/ATan2Tests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/ATan2Tests.java new file mode 100644 index 000000000..f466c6f4f --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/ATan2Tests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.ATan2; +import com.google.refine.tests.util.TestUtils; + +public class ATan2Tests { + @Test + public void serializeATan2() { + String json = "{\"description\":\"Converts rectangular coordinates (x, y) to polar (r, theta)\",\"params\":\"number x, number y\",\"returns\":\"number theta\"}"; + TestUtils.isSerializedTo(new ATan2(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/ATanTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/ATanTests.java new file mode 100644 index 000000000..925a209a9 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/ATanTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.ATan; +import com.google.refine.tests.util.TestUtils; + +public class ATanTests { + @Test + public void serializeATan() { + String json = "{\"description\":\"Returns the arc tangent of an angle in the range of -PI/2 through PI/2\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new ATan(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/AbsTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/AbsTests.java new file mode 100644 index 000000000..91930e056 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/AbsTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Abs; +import com.google.refine.tests.util.TestUtils; + +public class AbsTests { + @Test + public void serializeAbs() { + String json = "{\"description\":\"Returns the absolute value of a number\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Abs(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/CeilTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/CeilTests.java new file mode 100644 index 000000000..9f8a60fb6 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/CeilTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Ceil; +import com.google.refine.tests.util.TestUtils; + +public class CeilTests { + @Test + public void serializeCeil() { + String json = "{\"description\":\"Returns the ceiling of a number\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Ceil(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/CombinTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/CombinTests.java new file mode 100644 index 000000000..64de72130 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/CombinTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Combin; +import com.google.refine.tests.util.TestUtils; + +public class CombinTests { + @Test + public void serializeCombin() { + String json = "{\"description\":\"Returns the number of combinations for n elements as divided into k\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Combin(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/CosTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/CosTests.java new file mode 100644 index 000000000..a103e19d5 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/CosTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Cos; +import com.google.refine.tests.util.TestUtils; + +public class CosTests { + @Test + public void serializeCos() { + String json = "{\"description\":\"Returns the trigonometric cosine of an angle\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Cos(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/CoshTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/CoshTests.java new file mode 100644 index 000000000..0081dc185 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/CoshTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Cosh; +import com.google.refine.tests.util.TestUtils; + +public class CoshTests { + @Test + public void serializeCosh() { + String json = "{\"description\":\"Returns the hyperbolic cosine of a value\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Cosh(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/DegreesTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/DegreesTests.java new file mode 100644 index 000000000..6b173ad19 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/DegreesTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Degrees; +import com.google.refine.tests.util.TestUtils; + +public class DegreesTests { + @Test + public void serializeDegrees() { + String json = "{\"description\":\"Converts an angle from radians to degrees.\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Degrees(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/EvenTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/EvenTests.java new file mode 100644 index 000000000..a2bc7c2ae --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/EvenTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Even; +import com.google.refine.tests.util.TestUtils; + +public class EvenTests { + @Test + public void serializeEven() { + String json = "{\"description\":\"Rounds the number up to the nearest even integer\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Even(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/ExpTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/ExpTests.java new file mode 100644 index 000000000..e701af706 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/ExpTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Exp; +import com.google.refine.tests.util.TestUtils; + +public class ExpTests { + @Test + public void serializeExp() { + String json = "{\"description\":\"Returns e^n\",\"params\":\"number n\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Exp(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/FactNTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/FactNTests.java new file mode 100644 index 000000000..d69348cf2 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/FactNTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.FactN; +import com.google.refine.tests.util.TestUtils; + +public class FactNTests { + @Test + public void serializeFactN() { + String json = "{\"description\":\"Returns the factorial of a number\",\"params\":\"number i\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new FactN(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/FactTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/FactTests.java new file mode 100644 index 000000000..001c093bb --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/FactTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Fact; +import com.google.refine.tests.util.TestUtils; + +public class FactTests { + @Test + public void serializeFact() { + String json = "{\"description\":\"Returns the factorial of a number\",\"params\":\"number i\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Fact(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/FloorTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/FloorTests.java new file mode 100644 index 000000000..02396d86b --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/FloorTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Floor; +import com.google.refine.tests.util.TestUtils; + +public class FloorTests { + @Test + public void serializeFloor() { + String json = "{\"description\":\"Returns the floor of a number as an integer\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Floor(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/GreatestCommonDenominatorTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/GreatestCommonDenominatorTests.java new file mode 100644 index 000000000..945aa58b2 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/GreatestCommonDenominatorTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.GreatestCommonDenominator; +import com.google.refine.tests.util.TestUtils; + +public class GreatestCommonDenominatorTests { + @Test + public void serializeGreatestCommonDenominator() { + String json = "{\"description\":\"Returns the greatest common denominator of the two numbers\",\"params\":\"number d, number e\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new GreatestCommonDenominator(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/LeastCommonMultipleTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/LeastCommonMultipleTests.java new file mode 100644 index 000000000..ddbf5bc3f --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/LeastCommonMultipleTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.LeastCommonMultiple; +import com.google.refine.tests.util.TestUtils; + +public class LeastCommonMultipleTests { + @Test + public void serializeLeastCommonMultiple() { + String json = "{\"description\":\"Returns the greatest common denominator of the two numbers\",\"params\":\"number d, number e\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new LeastCommonMultiple(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/LnTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/LnTests.java new file mode 100644 index 000000000..bb39df737 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/LnTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Ln; +import com.google.refine.tests.util.TestUtils; + +public class LnTests { + @Test + public void serializeLn() { + String json = "{\"description\":\"Returns the natural log of n\",\"params\":\"number n\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Ln(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/LogTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/LogTests.java new file mode 100644 index 000000000..45542f8aa --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/LogTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Log; +import com.google.refine.tests.util.TestUtils; + +public class LogTests { + @Test + public void serializeLog() { + String json = "{\"description\":\"Returns the base 10 log of n\",\"params\":\"number n\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Log(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/MaxTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/MaxTests.java new file mode 100644 index 000000000..83c765029 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/MaxTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Max; +import com.google.refine.tests.util.TestUtils; + +public class MaxTests { + @Test + public void serializeMax() { + String json = "{\"description\":\"Returns the greater of two numbers\",\"params\":\"number a, number b\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Max(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/MinTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/MinTests.java new file mode 100644 index 000000000..8b7f3d9ad --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/MinTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Min; +import com.google.refine.tests.util.TestUtils; + +public class MinTests { + @Test + public void serializeMin() { + String json = "{\"description\":\"Returns the smaller of two numbers\",\"params\":\"number a, number b\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Min(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/ModTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/ModTests.java new file mode 100644 index 000000000..8a44e8113 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/ModTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Mod; +import com.google.refine.tests.util.TestUtils; + +public class ModTests { + @Test + public void serializeMod() { + String json = "{\"description\":\"Returns a modulus b\",\"params\":\"number a, number b\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Mod(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/MultinomialTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/MultinomialTests.java new file mode 100644 index 000000000..4c3226aaf --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/MultinomialTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Multinomial; +import com.google.refine.tests.util.TestUtils; + +public class MultinomialTests { + @Test + public void serializeMultinomial() { + String json = "{\"description\":\"Calculates the multinomial of a series of numbers\",\"params\":\"one or more numbers\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Multinomial(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/OddTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/OddTests.java new file mode 100644 index 000000000..f7feaf310 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/OddTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Odd; +import com.google.refine.tests.util.TestUtils; + +public class OddTests { + @Test + public void serializeOdd() { + String json = "{\"description\":\"Rounds the number up to the nearest even integer\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Odd(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/PowTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/PowTests.java new file mode 100644 index 000000000..ff0d12f5a --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/PowTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Pow; +import com.google.refine.tests.util.TestUtils; + +public class PowTests { + @Test + public void serializePow() { + String json = "{\"description\":\"Returns a^b\",\"params\":\"number a, number b\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Pow(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/QuotientTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/QuotientTests.java new file mode 100644 index 000000000..94a8a029b --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/QuotientTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Quotient; +import com.google.refine.tests.util.TestUtils; + +public class QuotientTests { + @Test + public void serializeQuotient() { + String json = "{\"description\":\"Returns the integer portion of a division\",\"params\":\"number numerator, number denominator\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Quotient(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/RadiansTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/RadiansTests.java new file mode 100644 index 000000000..dc4ec73b8 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/RadiansTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Radians; +import com.google.refine.tests.util.TestUtils; + +public class RadiansTests { + @Test + public void serializeRadians() { + String json = "{\"description\":\"Converts an angle in degrees to radians\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Radians(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/RoundTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/RoundTests.java new file mode 100644 index 000000000..865b9cbee --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/RoundTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Round; +import com.google.refine.tests.util.TestUtils; + +public class RoundTests { + @Test + public void serializeRound() { + String json = "{\"description\":\"Returns n rounded\",\"params\":\"number n\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Round(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/SinTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/SinTests.java new file mode 100644 index 000000000..daa8c935d --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/SinTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Sin; +import com.google.refine.tests.util.TestUtils; + +public class SinTests { + @Test + public void serializeSin() { + String json = "{\"description\":\"Returns the trigonometric sine of an angle\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Sin(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/SinhTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/SinhTests.java new file mode 100644 index 000000000..badca7566 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/SinhTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Sinh; +import com.google.refine.tests.util.TestUtils; + +public class SinhTests { + @Test + public void serializeSinh() { + String json = "{\"description\":\"Returns the hyperbolic sine of an angle\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Sinh(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/SumTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/SumTests.java new file mode 100644 index 000000000..8f4331e19 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/SumTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Sum; +import com.google.refine.tests.util.TestUtils; + +public class SumTests { + @Test + public void serializeSum() { + String json = "{\"description\":\"Sums numbers in array a\",\"params\":\"array a\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Sum(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/TanTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/TanTests.java new file mode 100644 index 000000000..dabb5b3ff --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/TanTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Tan; +import com.google.refine.tests.util.TestUtils; + +public class TanTests { + @Test + public void serializeTan() { + String json = "{\"description\":\"Returns the trigonometric tangent of an angle\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Tan(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/math/TanhTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/math/TanhTests.java new file mode 100644 index 000000000..dc494b73c --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/math/TanhTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.math; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.math.Tanh; +import com.google.refine.tests.util.TestUtils; + +public class TanhTests { + @Test + public void serializeTanh() { + String json = "{\"description\":\"Returns the hyperbolic tangent of a value\",\"params\":\"number d\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new Tanh(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ChompTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ChompTests.java new file mode 100644 index 000000000..3ae7f6d69 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ChompTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.Chomp; +import com.google.refine.tests.util.TestUtils; + +public class ChompTests { + @Test + public void serializeChomp() { + String json = "{\"description\":\"Removes separator from the end of str if it's there, otherwise leave it alone.\",\"params\":\"string str, string separator\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new Chomp(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ContainsTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ContainsTests.java new file mode 100644 index 000000000..b8c02f82d --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ContainsTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.Contains; +import com.google.refine.tests.util.TestUtils; + +public class ContainsTests { + @Test + public void serializeContains() { + String json = "{\"description\":\"Returns whether s contains frag\",\"params\":\"string s, string frag\",\"returns\":\"boolean\"}"; + TestUtils.isSerializedTo(new Contains(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/DiffTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/DiffTests.java index 92f44c6c7..95bcef402 100644 --- a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/DiffTests.java +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/DiffTests.java @@ -12,9 +12,11 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.refine.expr.EvalError; +import com.google.refine.expr.functions.strings.Diff; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; public class DiffTests extends RefineTest { @@ -80,4 +82,11 @@ public class DiffTests extends RefineTest { Assert.assertEquals(invoke("diff",odt2,odt1,"milliseconds"),Long.valueOf(7948860000011l)); Assert.assertEquals(invoke("diff",odt2,odt1,"nanos"),Long.valueOf(7948860000011000l)); } + + @Test + public void serializeDiff() { + String json = "{\"description\":\"For strings, returns the portion where they differ. For dates, it returns the difference in given time units\",\"params\":\"o1, o2, time unit (optional)\",\"returns\":\"string for strings, number for dates\"}"; + TestUtils.isSerializedTo(new Diff(), json); + } + } diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/EndsWithTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/EndsWithTests.java new file mode 100644 index 000000000..831f203e2 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/EndsWithTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.EndsWith; +import com.google.refine.tests.util.TestUtils; + +public class EndsWithTests { + @Test + public void serializeEndsWith() { + String json = "{\"description\":\"Returns whether s ends with sub\",\"params\":\"string s, string sub\",\"returns\":\"boolean\"}"; + TestUtils.isSerializedTo(new EndsWith(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/EscapeTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/EscapeTests.java new file mode 100644 index 000000000..6a1d4e61d --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/EscapeTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.Escape; +import com.google.refine.tests.util.TestUtils; + +public class EscapeTests { + @Test + public void serializeEscape() { + String json = "{\"description\":\"Escapes a string depending on the given escaping mode.\",\"params\":\"string s, string mode ['html','xml','csv','url','javascript']\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new Escape(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/FindTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/FindTests.java new file mode 100644 index 000000000..0ba389a63 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/FindTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.Find; +import com.google.refine.tests.util.TestUtils; + +public class FindTests { + @Test + public void serializeFind() { + String json = "{\"description\":\"Returns all the occurances of match given regular expression\",\"params\":\"string or regexp\",\"returns\":\"array of strings\"}"; + TestUtils.isSerializedTo(new Find(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/FingerprintTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/FingerprintTests.java index 3c7b6dd69..e1a542450 100644 --- a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/FingerprintTests.java +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/FingerprintTests.java @@ -40,9 +40,11 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import com.google.refine.expr.functions.strings.Fingerprint; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; public class FingerprintTests extends RefineTest { @@ -110,4 +112,12 @@ public class FingerprintTests extends RefineTest { "Fingerprint for string: " + ss[0] + " failed"); } } + + @Test + public void serializeFingerprint() { + String json = "{\"description\":\"Returns the fingerprint of s, a derived string that aims to be a more canonical form of it (this is mostly useful for finding clusters of strings related to the same information).\",\"params\":\"string s\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new Fingerprint(), json); + } + + } diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/IndexOfTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/IndexOfTests.java new file mode 100644 index 000000000..63b67938c --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/IndexOfTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.IndexOf; +import com.google.refine.tests.util.TestUtils; + +public class IndexOfTests { + @Test + public void serializeIndexOf() { + String json = "{\"description\":\"Returns the index of sub first ocurring in s\",\"params\":\"string s, string sub\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new IndexOf(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/LastIndexOfTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/LastIndexOfTests.java new file mode 100644 index 000000000..b5a9c27dd --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/LastIndexOfTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.LastIndexOf; +import com.google.refine.tests.util.TestUtils; + +public class LastIndexOfTests { + @Test + public void serializeLastIndexOf() { + String json = "{\"description\":\"Returns the index of sub last ocurring in s\",\"params\":\"string s, string sub\",\"returns\":\"number\"}"; + TestUtils.isSerializedTo(new LastIndexOf(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/MD5Tests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/MD5Tests.java new file mode 100644 index 000000000..8ecb11af6 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/MD5Tests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.MD5; +import com.google.refine.tests.util.TestUtils; + +public class MD5Tests { + @Test + public void serializeMD5() { + String json = "{\"description\":\"Returns the MD5 hash of s\",\"params\":\"string s\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new MD5(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/MatchTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/MatchTests.java new file mode 100644 index 000000000..bd9076a3b --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/MatchTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.Match; +import com.google.refine.tests.util.TestUtils; + +public class MatchTests { + @Test + public void serializeMatch() { + String json = "{\"description\":\"Returns an array of the groups matching the given regular expression\",\"params\":\"string or regexp\",\"returns\":\"array of strings\"}"; + TestUtils.isSerializedTo(new Match(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/NGramFingerprintTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/NGramFingerprintTests.java new file mode 100644 index 000000000..5790e048f --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/NGramFingerprintTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.NGramFingerprint; +import com.google.refine.tests.util.TestUtils; + +public class NGramFingerprintTests { + @Test + public void serializeNGramFingerprint() { + String json = "{\"description\":\"Returns the n-gram fingerprint of s\",\"params\":\"string s, number n\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new NGramFingerprint(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/NGramTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/NGramTests.java new file mode 100644 index 000000000..40a78411f --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/NGramTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.NGram; +import com.google.refine.tests.util.TestUtils; + +public class NGramTests { + @Test + public void serializeNGram() { + String json = "{\"description\":\"Returns an array of the word ngrams of s\",\"params\":\"string s, number n\",\"returns\":\"array of strings\"}"; + TestUtils.isSerializedTo(new NGram(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ParseJsonTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ParseJsonTests.java new file mode 100644 index 000000000..1ce62790b --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ParseJsonTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.ParseJson; +import com.google.refine.tests.util.TestUtils; + +public class ParseJsonTests { + @Test + public void serializeParseJson() { + String json = "{\"description\":\"Parses a string as JSON\",\"params\":\"string s\",\"returns\":\"JSON object\"}"; + TestUtils.isSerializedTo(new ParseJson(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/PartitionTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/PartitionTests.java new file mode 100644 index 000000000..5ed5673e4 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/PartitionTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.Partition; +import com.google.refine.tests.util.TestUtils; + +public class PartitionTests { + @Test + public void serializePartition() { + String json = "{\"description\":\"Returns an array of strings [a,frag,b] where a is the string part before the first occurrence of frag in s and b is what's left. If omitFragment is true, frag is not returned.\",\"params\":\"string s, string or regex frag, optional boolean omitFragment\",\"returns\":\"array\"}"; + TestUtils.isSerializedTo(new Partition(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/PhoneticTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/PhoneticTests.java new file mode 100644 index 000000000..a9409cf44 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/PhoneticTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.Phonetic; +import com.google.refine.tests.util.TestUtils; + +public class PhoneticTests { + @Test + public void serializePhonetic() { + String json = "{\"description\":\"Returns the a phonetic encoding of s (optionally indicating which encoding to use')\",\"params\":\"string s, string encoding (optional, defaults to 'metaphone3')\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new Phonetic(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/RPartitionTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/RPartitionTests.java new file mode 100644 index 000000000..a1f8966ab --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/RPartitionTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.RPartition; +import com.google.refine.tests.util.TestUtils; + +public class RPartitionTests { + @Test + public void serializeRPartition() { + String json = "{\"description\":\"Returns an array of strings [a,frag,b] where a is the string part before the last occurrence of frag in s and b is what's left. If omitFragment is true, frag is not returned.\",\"params\":\"string s, string or regex frag, optional boolean omitFragment\",\"returns\":\"array\"}"; + TestUtils.isSerializedTo(new RPartition(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/RangeTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/RangeTests.java index 10117e17b..edb589e18 100644 --- a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/RangeTests.java +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/RangeTests.java @@ -10,9 +10,11 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.refine.expr.EvalError; +import com.google.refine.expr.functions.strings.Range; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; /** * Tests for the range function. @@ -319,4 +321,11 @@ public class RangeTests extends RefineTest { Assert.assertEquals(((Integer[]) (invoke("range", 5, "1", "-1"))), FIVE_TO_TWO); Assert.assertEquals(((Integer[]) (invoke("range", 5, "1", "-2"))), FIVE_AND_THREE); } + + @Test + public void serializeRange() { + String json = "{\"description\":\"Returns an array where a and b are the start and the end of the range respectively and c is the step (increment).\",\"params\":\"A single string 'a', 'a, b' or 'a, b, c' or one, two or three integers a or a, b or a, b, c\",\"returns\":\"array\"}"; + TestUtils.isSerializedTo(new Range(), json); + } + } diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ReinterpretTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ReinterpretTests.java new file mode 100644 index 000000000..574d94fbd --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ReinterpretTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.Reinterpret; +import com.google.refine.tests.util.TestUtils; + +public class ReinterpretTests { + @Test + public void serializeReinterpret() { + String json = "{\"description\":\"Returns s reinterpreted thru the given encoder.\",\"params\":\"string s, string encoder\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new Reinterpret(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ReplaceCharsTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ReplaceCharsTests.java new file mode 100644 index 000000000..af5abb7bf --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ReplaceCharsTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.ReplaceChars; +import com.google.refine.tests.util.TestUtils; + +public class ReplaceCharsTests { + @Test + public void serializeReplaceChars() { + String json = "{\"description\":\"Returns the string obtained by replacing all chars in f with the char in s at that same position\",\"params\":\"string s, string f, string r\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new ReplaceChars(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ReplaceTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ReplaceTests.java new file mode 100644 index 000000000..aad1c2523 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ReplaceTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.Replace; +import com.google.refine.tests.util.TestUtils; + +public class ReplaceTests { + @Test + public void serializeReplace() { + String json = "{\"description\":\"Returns the string obtained by replacing f with r in s\",\"params\":\"string s, string or regex f, string r\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new Replace(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/SHA1Tests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/SHA1Tests.java new file mode 100644 index 000000000..00843a392 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/SHA1Tests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.SHA1; +import com.google.refine.tests.util.TestUtils; + +public class SHA1Tests { + @Test + public void serializeSHA1() { + String json = "{\"description\":\"Returns the SHA-1 hash of s\",\"params\":\"string s\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new SHA1(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/SmartSplitTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/SmartSplitTests.java new file mode 100644 index 000000000..31f0b858f --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/SmartSplitTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.SmartSplit; +import com.google.refine.tests.util.TestUtils; + +public class SmartSplitTests { + @Test + public void serializeSmartSplit() { + String json = "{\"description\":\"Returns the array of strings obtained by splitting s with separator sep. Handles quotes properly. Guesses tab or comma separator if \\\"sep\\\" is not given.\",\"params\":\"string s, optional string sep\",\"returns\":\"array\"}"; + TestUtils.isSerializedTo(new SmartSplit(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/SplitByCharTypeTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/SplitByCharTypeTests.java new file mode 100644 index 000000000..cb2781692 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/SplitByCharTypeTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.SplitByCharType; +import com.google.refine.tests.util.TestUtils; + +public class SplitByCharTypeTests { + @Test + public void serializeSplitByCharType() { + String json = "{\"description\":\"Returns an array of strings obtained by splitting s grouping consecutive chars by their unicode type\",\"params\":\"string s\",\"returns\":\"array\"}"; + TestUtils.isSerializedTo(new SplitByCharType(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/SplitByLengthsTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/SplitByLengthsTests.java new file mode 100644 index 000000000..9cabc53a9 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/SplitByLengthsTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.SplitByLengths; +import com.google.refine.tests.util.TestUtils; + +public class SplitByLengthsTests { + @Test + public void serializeSplitByLengths() { + String json = "{\"description\":\"Returns the array of strings obtained by splitting s into substrings with the given lengths\",\"params\":\"string s, number n, ...\",\"returns\":\"array\"}"; + TestUtils.isSerializedTo(new SplitByLengths(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/SplitTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/SplitTests.java new file mode 100644 index 000000000..46db91690 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/SplitTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.Split; +import com.google.refine.tests.util.TestUtils; + +public class SplitTests { + @Test + public void serializeSplit() { + String json = "{\"description\":\"Returns the array of strings obtained by splitting s with separator sep. If preserveAllTokens is true, then empty segments are preserved.\",\"params\":\"string s, string or regex sep, optional boolean preserveAllTokens\",\"returns\":\"array\"}"; + TestUtils.isSerializedTo(new Split(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/StartsWithTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/StartsWithTests.java new file mode 100644 index 000000000..46344c161 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/StartsWithTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.StartsWith; +import com.google.refine.tests.util.TestUtils; + +public class StartsWithTests { + @Test + public void serializeStartsWith() { + String json = "{\"description\":\"Returns whether s starts with sub\",\"params\":\"string s, string sub\",\"returns\":\"boolean\"}"; + TestUtils.isSerializedTo(new StartsWith(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToLowercaseTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToLowercaseTests.java new file mode 100644 index 000000000..42f2e7174 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToLowercaseTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.ToLowercase; +import com.google.refine.tests.util.TestUtils; + +public class ToLowercaseTests { + @Test + public void serializeToLowercase() { + String json = "{\"description\":\"Returns s converted to lowercase\",\"params\":\"string s\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new ToLowercase(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToTitlecaseTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToTitlecaseTests.java new file mode 100644 index 000000000..de1d2b444 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToTitlecaseTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.ToTitlecase; +import com.google.refine.tests.util.TestUtils; + +public class ToTitlecaseTests { + @Test + public void serializeToTitlecase() { + String json = "{\"description\":\"Returns s converted to titlecase\",\"params\":\"string s\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new ToTitlecase(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToUppercaseTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToUppercaseTests.java new file mode 100644 index 000000000..f5a769175 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToUppercaseTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.ToUppercase; +import com.google.refine.tests.util.TestUtils; + +public class ToUppercaseTests { + @Test + public void serializeToUppercase() { + String json = "{\"description\":\"Returns s converted to uppercase\",\"params\":\"string s\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new ToUppercase(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/TrimTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/TrimTests.java index baec2def1..4fdfcfdb9 100644 --- a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/TrimTests.java +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/TrimTests.java @@ -10,9 +10,11 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.refine.expr.EvalError; +import com.google.refine.expr.functions.strings.Trim; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; public class TrimTests extends RefineTest { @@ -103,4 +105,10 @@ public class TrimTests extends RefineTest { } } + + @Test + public void serializeTrim() { + String json = "{\"description\":\"Returns copy of the string, with leading and trailing whitespace omitted.\",\"params\":\"string s\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new Trim(), json); + } } diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/UnescapeTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/UnescapeTests.java new file mode 100644 index 000000000..0d8b0e312 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/UnescapeTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.Unescape; +import com.google.refine.tests.util.TestUtils; + +public class UnescapeTests { + @Test + public void serializeUnescape() { + String json = "{\"description\":\"Unescapes all escaped parts of the string depending on the given escaping mode.\",\"params\":\"string s, string mode ['html','xml','csv','url','javascript']\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new Unescape(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/UnicodeTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/UnicodeTests.java new file mode 100644 index 000000000..6868e902f --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/UnicodeTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.Unicode; +import com.google.refine.tests.util.TestUtils; + +public class UnicodeTests { + @Test + public void serializeUnicode() { + String json = "{\"description\":\"Returns an array of strings describing each character of s in their full unicode notation\",\"params\":\"string s\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new Unicode(), json); + } +} + diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/UnicodeTypeTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/UnicodeTypeTests.java new file mode 100644 index 000000000..83272c2f9 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/UnicodeTypeTests.java @@ -0,0 +1,15 @@ +package com.google.refine.tests.expr.functions.strings; + +import org.testng.annotations.Test; + +import com.google.refine.expr.functions.strings.UnicodeType; +import com.google.refine.tests.util.TestUtils; + +public class UnicodeTypeTests { + @Test + public void serializeUnicodeType() { + String json = "{\"description\":\"Returns an array of strings describing each character of s in their full unicode notation\",\"params\":\"string s\",\"returns\":\"string\"}"; + TestUtils.isSerializedTo(new UnicodeType(), json); + } +} + From f6bbb64c98a87f44e7fb495fff8f4f80afff61a1 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sat, 1 Sep 2018 14:55:37 +0200 Subject: [PATCH 26/26] Fix import errors --- .../tests/operations/row/RowReorderOperationTests.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main/tests/server/src/com/google/refine/tests/operations/row/RowReorderOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/row/RowReorderOperationTests.java index bbc03c3af..0bc492d24 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/row/RowReorderOperationTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/row/RowReorderOperationTests.java @@ -1,11 +1,15 @@ package com.google.refine.tests.operations.row; +import static org.mockito.Mockito.mock; + import java.util.Properties; +import org.json.JSONException; 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; @@ -13,9 +17,11 @@ import com.google.refine.browsing.Engine.Mode; import com.google.refine.model.AbstractOperation; import com.google.refine.model.Cell; import com.google.refine.model.Project; +import com.google.refine.operations.OperationRegistry; import com.google.refine.operations.row.RowReorderOperation; import com.google.refine.process.Process; import com.google.refine.tests.RefineTest; +import com.google.refine.tests.util.TestUtils; public class RowReorderOperationTests extends RefineTest {