diff --git a/main/tests/server/src/com/google/refine/RefineTest.java b/main/tests/server/src/com/google/refine/RefineTest.java index 6e71efd52f99..995750164138 100644 --- a/main/tests/server/src/com/google/refine/RefineTest.java +++ b/main/tests/server/src/com/google/refine/RefineTest.java @@ -62,9 +62,6 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeSuite; -import com.google.refine.expr.Evaluable; -import com.google.refine.expr.MetaParser; -import com.google.refine.expr.ParsingException; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; import com.google.refine.grel.Parser; @@ -381,39 +378,6 @@ protected static Object invoke(String name, Object... args) { } } - /** - * Parse and evaluate a GREL expression and compare the result to the expect value - * - * @param bindings - * @param test - * @throws ParsingException - */ - protected void parseEval(Properties bindings, String[] test) - throws ParsingException { - Evaluable eval = MetaParser.parse("grel:" + test[0]); - Object result = eval.evaluate(bindings); - if (test[1] != null) { - Assert.assertNotNull(result, "Expected " + test[1] + " for test " + test[0]); - Assert.assertEquals(result.toString(), test[1], "Wrong result for expression: " + test[0]); - } else { - Assert.assertNull(result, "Wrong result for expression: " + test[0]); - } - } - - /** - * Parse and evaluate a GREL expression and compare the result an expected type using instanceof - * - * @param bindings - * @param test - * @throws ParsingException - */ - protected void parseEvalType(Properties bindings, String test, @SuppressWarnings("rawtypes") Class clazz) - throws ParsingException { - Evaluable eval = MetaParser.parse("grel:" + test); - Object result = eval.evaluate(bindings); - Assert.assertTrue(clazz.isInstance(result), "Wrong result type for expression: " + test); - } - @AfterMethod public void TearDown() throws Exception { bindings = null; diff --git a/main/tests/server/src/com/google/refine/expr/EvalErrorTests.java b/main/tests/server/src/com/google/refine/expr/EvalErrorTests.java index d6fbdacaf751..09f5c00c93f8 100644 --- a/main/tests/server/src/com/google/refine/expr/EvalErrorTests.java +++ b/main/tests/server/src/com/google/refine/expr/EvalErrorTests.java @@ -27,9 +27,6 @@ package com.google.refine.expr; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.refine.RefineTest; @@ -37,45 +34,10 @@ public class EvalErrorTests extends RefineTest { - @Override - @BeforeTest - public void init() { - logger = LoggerFactory.getLogger(this.getClass()); - } - @Test public void serializeEvalError() { EvalError e = new EvalError("This is a critical error"); TestUtils.isSerializedTo(e, "{\"type\":\"error\",\"message\":\"This is a critical error\"}"); } - @Test - public void testInnerHtml() { - Assert.assertTrue(invoke("innerHtml") instanceof EvalError); - Assert.assertTrue(invoke("innerHtml", "test") instanceof EvalError); - - EvalError evalError = (EvalError) invoke("innerHtml", "test"); - Assert.assertEquals(evalError.toString(), - "innerHtml() cannot work with this \'string\'. The first parameter is not an HTML Element. Please first use parseHtml(string) and select(query) prior to using this function"); - } - - @Test - public void testWholeText() { - Assert.assertTrue(invoke("wholeText") instanceof EvalError); - Assert.assertTrue(invoke("wholeText", "test") instanceof EvalError); - - EvalError evalError = (EvalError) invoke("wholeText", "test"); - Assert.assertEquals(evalError.toString(), - "wholeText() cannot work with this \'string\' and failed as the first parameter is not an XML or HTML Element. Please first use parseXml() or parseHtml() and select(query) prior to using this function"); - } - - @Test - public void testXmlText() { - Assert.assertTrue(invoke("xmlText") instanceof EvalError); - Assert.assertTrue(invoke("xmlText", "test") instanceof EvalError); - - EvalError evalError = (EvalError) invoke("xmlText", "test"); - Assert.assertEquals(evalError.toString(), - "xmlText() cannot work with this \'string\' and failed as the first parameter is not an XML or HTML Element. Please first use parseXml() or parseHtml() and select(query) prior to using this function"); - } } diff --git a/main/tests/server/src/com/google/refine/expr/functions/CoalesceTests.java b/main/tests/server/src/com/google/refine/expr/functions/CoalesceTests.java index e7bccb288fc0..f9410edae72a 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/CoalesceTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/CoalesceTests.java @@ -33,38 +33,16 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT package com.google.refine.expr.functions; -import java.util.Properties; - -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.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class CoalesceTests extends RefineTest { +public class CoalesceTests extends GrelTestBase { private static final Integer[] ZERO_TO_TWO = new Integer[] { 0, 1, 2 }; - @Override - @BeforeTest - public void init() { - logger = LoggerFactory.getLogger(this.getClass()); - } - - @BeforeMethod - public void setUp() { - bindings = new Properties(); - } - - @AfterMethod - public void tearDown() { - bindings = null; - } - @Test public void testCoalesceInvalidParams() { Assert.assertTrue(invoke("coalesce") instanceof EvalError); diff --git a/main/tests/server/src/com/google/refine/expr/functions/CrossTests.java b/main/tests/server/src/com/google/refine/expr/functions/CrossTests.java index 2bd1042494be..ec44018051d0 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/CrossTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/CrossTests.java @@ -35,17 +35,15 @@ import java.util.List; import java.util.Properties; -import org.slf4j.LoggerFactory; import org.testng.Assert; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; import com.google.refine.expr.HasFieldsListImpl; import com.google.refine.expr.WrappedCell; import com.google.refine.expr.WrappedRow; +import com.google.refine.grel.GrelTestBase; import com.google.refine.model.Cell; import com.google.refine.model.Project; import com.google.refine.model.Row; @@ -53,18 +51,12 @@ /** * Test cases for cross function. */ -public class CrossTests extends RefineTest { +public class CrossTests extends GrelTestBase { private static final String ERROR_MSG = "cross expects a cell or value, a project name to look up (optional), and a column name in that project (optional)"; private static final OffsetDateTime dateTimeValue = OffsetDateTime.parse("2017-05-12T05:45:00+00:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME); - @Override - @BeforeTest - public void init() { - logger = LoggerFactory.getLogger(this.getClass()); - } - private HasFieldsListImpl emptyList; // dependencies diff --git a/main/tests/server/src/com/google/refine/expr/functions/GetTests.java b/main/tests/server/src/com/google/refine/expr/functions/GetTests.java index d94650c7e95a..d022d4a4e221 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/GetTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/GetTests.java @@ -27,44 +27,15 @@ package com.google.refine.expr.functions; -import java.util.Properties; - -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.RefineTest; import com.google.refine.expr.Evaluable; -import com.google.refine.expr.ExpressionUtils; import com.google.refine.expr.MetaParser; import com.google.refine.expr.ParsingException; -import com.google.refine.model.Project; - -public class GetTests extends RefineTest { - - Project project; - Properties bindings; - - @Override - @BeforeTest - public void init() { - logger = LoggerFactory.getLogger(this.getClass()); - } - - @BeforeMethod - public void SetUp() { - project = new Project(); - bindings = ExpressionUtils.createBindings(project); - } +import com.google.refine.grel.GrelTestBase; - @AfterMethod - public void TearDown() { - project = null; - bindings = null; - } +public class GetTests extends GrelTestBase { @Test public void testGetJsonFieldExists() throws ParsingException { diff --git a/main/tests/server/src/com/google/refine/expr/functions/JsonizeTests.java b/main/tests/server/src/com/google/refine/expr/functions/JsonizeTests.java index 06f4bc9c738c..79a9f9a299f5 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/JsonizeTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/JsonizeTests.java @@ -32,11 +32,11 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; import com.google.refine.expr.util.CalendarParserException; +import com.google.refine.grel.GrelTestBase; -public class JsonizeTests extends RefineTest { +public class JsonizeTests extends GrelTestBase { @Test public void testToString() throws CalendarParserException { diff --git a/main/tests/server/src/com/google/refine/expr/functions/ToDateTests.java b/main/tests/server/src/com/google/refine/expr/functions/ToDateTests.java index 3a719f161fbc..189fe1dfd6dd 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/ToDateTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/ToDateTests.java @@ -35,12 +35,12 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; import com.google.refine.expr.util.CalendarParser; import com.google.refine.expr.util.CalendarParserException; +import com.google.refine.grel.GrelTestBase; -public class ToDateTests extends RefineTest { +public class ToDateTests extends GrelTestBase { @Test public void testToDate() throws CalendarParserException { diff --git a/main/tests/server/src/com/google/refine/expr/functions/ToNumberTests.java b/main/tests/server/src/com/google/refine/expr/functions/ToNumberTests.java index 65dc898d36de..d1ec3f595b00 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/ToNumberTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/ToNumberTests.java @@ -34,11 +34,11 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; import com.google.refine.grel.Function; +import com.google.refine.grel.GrelTestBase; -public class ToNumberTests extends RefineTest { +public class ToNumberTests extends GrelTestBase { private static final Double EPSILON = 0.000001; static Properties bindings = new Properties(); diff --git a/main/tests/server/src/com/google/refine/expr/functions/ToStringTests.java b/main/tests/server/src/com/google/refine/expr/functions/ToStringTests.java index 0d0c654c2a72..1b7974011ca9 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/ToStringTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/ToStringTests.java @@ -32,12 +32,12 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; import com.google.refine.expr.util.CalendarParser; import com.google.refine.expr.util.CalendarParserException; +import com.google.refine.grel.GrelTestBase; -public class ToStringTests extends RefineTest { +public class ToStringTests extends GrelTestBase { @Test public void testToString() throws CalendarParserException { diff --git a/main/tests/server/src/com/google/refine/expr/functions/TypeTests.java b/main/tests/server/src/com/google/refine/expr/functions/TypeTests.java index cea55a5d50b5..ffb63622c20c 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/TypeTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/TypeTests.java @@ -31,39 +31,18 @@ import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.List; -import java.util.Properties; -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.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class TypeTests extends RefineTest { +public class TypeTests extends GrelTestBase { static final List listArray = Arrays.asList("v1", "v2", "v3"); private static OffsetDateTime dateTimeValue = OffsetDateTime.parse("2017-05-12T05:45:00+00:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME); - @Override - @BeforeTest - public void init() { - logger = LoggerFactory.getLogger(this.getClass()); - } - - @BeforeMethod - public void setUp() { - bindings = new Properties(); - } - - @AfterMethod - public void tearDown() { - bindings = null; - } - @Test public void testTypeInvalidParams() { Assert.assertTrue(invoke("type") instanceof EvalError); diff --git a/main/tests/server/src/com/google/refine/expr/functions/arrays/InArrayTests.java b/main/tests/server/src/com/google/refine/expr/functions/arrays/InArrayTests.java index eb3515e25535..748c52640a9d 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/arrays/InArrayTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/arrays/InArrayTests.java @@ -36,10 +36,10 @@ import org.testng.Assert; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class InArrayTests extends RefineTest { +public class InArrayTests extends GrelTestBase { static Properties bindings; static final List listArray = Arrays.asList("v1", "v2", "v3"); diff --git a/main/tests/server/src/com/google/refine/expr/functions/arrays/JoinTests.java b/main/tests/server/src/com/google/refine/expr/functions/arrays/JoinTests.java index a629e43a093e..8453cf7da002 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/arrays/JoinTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/arrays/JoinTests.java @@ -29,10 +29,10 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.ParsingException; +import com.google.refine.grel.GrelTestBase; -public class JoinTests extends RefineTest { +public class JoinTests extends GrelTestBase { @Test public void joinArray() throws ParsingException { diff --git a/main/tests/server/src/com/google/refine/expr/functions/arrays/ReverseTests.java b/main/tests/server/src/com/google/refine/expr/functions/arrays/ReverseTests.java index b1c185db97d0..5483482c1598 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/arrays/ReverseTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/arrays/ReverseTests.java @@ -29,10 +29,10 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.ParsingException; +import com.google.refine.grel.GrelTestBase; -public class ReverseTests extends RefineTest { +public class ReverseTests extends GrelTestBase { @Test public void reverseJsonArray() throws ParsingException { diff --git a/main/tests/server/src/com/google/refine/expr/functions/arrays/SortTests.java b/main/tests/server/src/com/google/refine/expr/functions/arrays/SortTests.java index d4b40414557d..b4fb13434e48 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/arrays/SortTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/arrays/SortTests.java @@ -29,11 +29,11 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; import com.google.refine.expr.ParsingException; +import com.google.refine.grel.GrelTestBase; -public class SortTests extends RefineTest { +public class SortTests extends GrelTestBase { @Test public void sortJsonArray() throws ParsingException { diff --git a/main/tests/server/src/com/google/refine/expr/functions/arrays/UniquesTests.java b/main/tests/server/src/com/google/refine/expr/functions/arrays/UniquesTests.java index faab68920ad9..9e4467143531 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/arrays/UniquesTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/arrays/UniquesTests.java @@ -29,10 +29,10 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.ParsingException; +import com.google.refine.grel.GrelTestBase; -public class UniquesTests extends RefineTest { +public class UniquesTests extends GrelTestBase { @Test public void uniquesJsonArray() throws ParsingException { diff --git a/main/tests/server/src/com/google/refine/expr/functions/booleans/BooleanTests.java b/main/tests/server/src/com/google/refine/expr/functions/booleans/BooleanTests.java index e0a5d865b82e..727c41dc291c 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/booleans/BooleanTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/booleans/BooleanTests.java @@ -38,10 +38,10 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class BooleanTests extends RefineTest { +public class BooleanTests extends GrelTestBase { private static String TRUTH_TABLE[][] = { { "and", "true", "true", "true", "true" }, diff --git a/main/tests/server/src/com/google/refine/expr/functions/date/DatePartTests.java b/main/tests/server/src/com/google/refine/expr/functions/date/DatePartTests.java index 6dacbe750866..461185905f79 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/date/DatePartTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/date/DatePartTests.java @@ -39,9 +39,9 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.refine.RefineTest; +import com.google.refine.grel.GrelTestBase; -public class DatePartTests extends RefineTest { +public class DatePartTests extends GrelTestBase { static Properties bindings; diff --git a/main/tests/server/src/com/google/refine/expr/functions/date/IncTests.java b/main/tests/server/src/com/google/refine/expr/functions/date/IncTests.java index cdd449c22862..547149c14678 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/date/IncTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/date/IncTests.java @@ -36,10 +36,10 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class IncTests extends RefineTest { +public class IncTests extends GrelTestBase { private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd-HH:mm:ss.SSSSSSSSSX"); diff --git a/main/tests/server/src/com/google/refine/expr/functions/date/NowTests.java b/main/tests/server/src/com/google/refine/expr/functions/date/NowTests.java index 1d434a6ef0c4..fd0ca95c5967 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/date/NowTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/date/NowTests.java @@ -35,9 +35,9 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.refine.RefineTest; +import com.google.refine.grel.GrelTestBase; -public class NowTests extends RefineTest { +public class NowTests extends GrelTestBase { private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd-HH:mm:ss.SSSSSSSSSX"); diff --git a/main/tests/server/src/com/google/refine/expr/functions/html/InnerHtmlTests.java b/main/tests/server/src/com/google/refine/expr/functions/html/InnerHtmlTests.java new file mode 100644 index 000000000000..efe84f7ac9fa --- /dev/null +++ b/main/tests/server/src/com/google/refine/expr/functions/html/InnerHtmlTests.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (C) 2018, OpenRefine contributors + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. 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. + * + * 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 HOLDER 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.expr.functions.html; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; + +public class InnerHtmlTests extends GrelTestBase { + + @Test + public void testInnerHtml() { + Assert.assertTrue(invoke("innerHtml") instanceof EvalError); + Assert.assertTrue(invoke("innerHtml", "test") instanceof EvalError); + + EvalError evalError = (EvalError) invoke("innerHtml", "test"); + Assert.assertEquals(evalError.toString(), + "innerHtml() cannot work with this \'string\'. The first parameter is not an HTML Element. Please first use parseHtml(string) and select(query) prior to using this function"); + } + +} diff --git a/main/tests/server/src/com/google/refine/expr/functions/html/ParseHtmlTests.java b/main/tests/server/src/com/google/refine/expr/functions/html/ParseHtmlTests.java index 15a0f90b666b..aa62334de89c 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/html/ParseHtmlTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/html/ParseHtmlTests.java @@ -35,10 +35,10 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class ParseHtmlTests extends RefineTest { +public class ParseHtmlTests extends GrelTestBase { static Properties bindings; static String h = "\n" + diff --git a/main/tests/server/src/com/google/refine/expr/functions/math/RandomNumberTest.java b/main/tests/server/src/com/google/refine/expr/functions/math/RandomNumberTest.java index cbddf90a284d..a5fa7d412375 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/math/RandomNumberTest.java +++ b/main/tests/server/src/com/google/refine/expr/functions/math/RandomNumberTest.java @@ -33,35 +33,13 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT package com.google.refine.expr.functions.math; -import java.util.Properties; - -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.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class RandomNumberTest extends RefineTest { - - @Override - @BeforeTest - public void init() { - logger = LoggerFactory.getLogger(this.getClass()); - } - - @BeforeMethod - public void setUp() throws Exception { - bindings = new Properties(); - } - - @AfterMethod - public void tearDown() throws Exception { - bindings = null; - } +public class RandomNumberTest extends GrelTestBase { @Test public void testCall() { diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/ChompTests.java b/main/tests/server/src/com/google/refine/expr/functions/strings/ChompTests.java index db514b2a1792..b37b0e472540 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/ChompTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/ChompTests.java @@ -31,9 +31,9 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; +import com.google.refine.grel.GrelTestBase; -public class ChompTests extends RefineTest { +public class ChompTests extends GrelTestBase { @Test public void testChomp() { diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/ContainsTests.java b/main/tests/server/src/com/google/refine/expr/functions/strings/ContainsTests.java index 58ef6c06099c..b1555abb9bf7 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/ContainsTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/ContainsTests.java @@ -29,23 +29,15 @@ import java.util.regex.Pattern; -import org.slf4j.LoggerFactory; import org.testng.Assert; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.refine.RefineTest; +import com.google.refine.grel.GrelTestBase; /** * Test cases for find function. */ -public class ContainsTests extends RefineTest { - - @Override - @BeforeTest - public void init() { - logger = LoggerFactory.getLogger(this.getClass()); - } +public class ContainsTests extends GrelTestBase { @Test public void testContainsFunction() { diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/DecodeTest.java b/main/tests/server/src/com/google/refine/expr/functions/strings/DecodeTest.java index 00d9d2b7968a..b074652b6c5a 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/DecodeTest.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/DecodeTest.java @@ -4,10 +4,10 @@ import org.testng.Assert; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class DecodeTest extends RefineTest { +public class DecodeTest extends GrelTestBase { @Test public void testDecode() { diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/DetectLanguageTest.java b/main/tests/server/src/com/google/refine/expr/functions/strings/DetectLanguageTest.java index 72f2b6ac4095..cf8a63b65240 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/DetectLanguageTest.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/DetectLanguageTest.java @@ -1,25 +1,20 @@ package com.google.refine.expr.functions.strings; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + import java.util.Map; import com.optimaize.langdetect.i18n.LdLocale; -import org.junit.Assert; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class DetectLanguageTest extends RefineTest { - - String functionName; +public class DetectLanguageTest extends GrelTestBase { - @Override - @BeforeTest - public void init() { - functionName = "detectLanguage"; - } + String functionName = "detectLanguage"; @Test public void testDetectLanguage() { @@ -30,15 +25,15 @@ public void testDetectLanguage() { "Ich bin sehr sicher dass dies funktioniert", LdLocale.fromString("de")); samples.forEach((s, ldLocale) -> { - Assert.assertEquals(invoke(functionName, s), ldLocale.getLanguage()); - Assert.assertTrue(invoke(functionName, s) instanceof String); + assertEquals(invoke(functionName, s), ldLocale.getLanguage()); + assertTrue(invoke(functionName, s) instanceof String); }); } @Test public void testDetectLanguageInvalidParams() { - Assert.assertTrue(invoke(functionName) instanceof EvalError); - Assert.assertTrue(invoke(functionName, + assertTrue(invoke(functionName) instanceof EvalError); + assertTrue(invoke(functionName, "Estoy muy seguro de que esto funciona", "Ich bin sehr sicher dass dies funktioniert") instanceof EvalError); } diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/DiffTests.java b/main/tests/server/src/com/google/refine/expr/functions/strings/DiffTests.java index be7f159dc7e5..f6e90f0549ed 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/DiffTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/DiffTests.java @@ -37,10 +37,10 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class DiffTests extends RefineTest { +public class DiffTests extends GrelTestBase { static Properties bindings; @@ -53,9 +53,8 @@ public class DiffTests extends RefineTest { private OffsetDateTime odt7; private OffsetDateTime odt8; - @Override @BeforeTest - public void init() { + public void initDates() { logger = LoggerFactory.getLogger(this.getClass()); odt1 = OffsetDateTime.parse("2011-09-01T10:15:30.123456+01:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME); odt2 = OffsetDateTime.parse("2011-12-02T10:16:30.123467+01:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME); diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/EncodeTest.java b/main/tests/server/src/com/google/refine/expr/functions/strings/EncodeTest.java index 80f0ea689c66..460689856290 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/EncodeTest.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/EncodeTest.java @@ -4,10 +4,10 @@ import org.testng.Assert; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class EncodeTest extends RefineTest { +public class EncodeTest extends GrelTestBase { @Test public void testEncode() { diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/EndsWithTests.java b/main/tests/server/src/com/google/refine/expr/functions/strings/EndsWithTests.java index a33663606a99..8471dd161591 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/EndsWithTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/EndsWithTests.java @@ -32,9 +32,9 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; +import com.google.refine.grel.GrelTestBase; -public class EndsWithTests extends RefineTest { +public class EndsWithTests extends GrelTestBase { @Test public void testStartsWith() { diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/EscapeTests.java b/main/tests/server/src/com/google/refine/expr/functions/strings/EscapeTests.java index 1da1a2d3c052..10733b3b3d6a 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/EscapeTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/EscapeTests.java @@ -32,9 +32,9 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; +import com.google.refine.grel.GrelTestBase; -public class EscapeTests extends RefineTest { +public class EscapeTests extends GrelTestBase { @Test public void testEscape() { diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/FindTests.java b/main/tests/server/src/com/google/refine/expr/functions/strings/FindTests.java index 3a0d7b7ded73..9895ec41f345 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/FindTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/FindTests.java @@ -36,12 +36,12 @@ import org.testng.annotations.Test; import com.google.refine.RefineServlet; -import com.google.refine.RefineTest; +import com.google.refine.grel.GrelTestBase; /** * Test cases for find function. */ -public class FindTests extends RefineTest { +public class FindTests extends GrelTestBase { static Properties bindings; diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/FingerprintTests.java b/main/tests/server/src/com/google/refine/expr/functions/strings/FingerprintTests.java index 5b5e9a2cd272..b10298dc69de 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/FingerprintTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/FingerprintTests.java @@ -33,14 +33,12 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT import java.util.Properties; -import org.slf4j.LoggerFactory; import org.testng.Assert; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.refine.RefineTest; +import com.google.refine.grel.GrelTestBase; -public class FingerprintTests extends RefineTest { +public class FingerprintTests extends GrelTestBase { static Properties bindings; @@ -58,12 +56,6 @@ public class FingerprintTests extends RefineTest { { "", "" }, }; - @Override - @BeforeTest - public void init() { - logger = LoggerFactory.getLogger(this.getClass()); - } - @Test public void testInvalidParams() { Assert.assertNull(invoke("fingerprint")); diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/ParseUriTest.java b/main/tests/server/src/com/google/refine/expr/functions/strings/ParseUriTest.java index 080f54da1a9f..f2f4cece529e 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/ParseUriTest.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/ParseUriTest.java @@ -7,11 +7,11 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; import com.google.refine.util.ParsingUtilities; -public class ParseUriTest extends RefineTest { +public class ParseUriTest extends GrelTestBase { private String sampleUri; diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/PhoneticTests.java b/main/tests/server/src/com/google/refine/expr/functions/strings/PhoneticTests.java index 15459812aa9f..973f7b5ff05e 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/PhoneticTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/PhoneticTests.java @@ -33,13 +33,13 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.clustering.binning.ColognePhoneticKeyer; import com.google.refine.clustering.binning.KeyerFactory; import com.google.refine.clustering.binning.Metaphone3Keyer; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class PhoneticTests extends RefineTest { +public class PhoneticTests extends GrelTestBase { @BeforeTest public void registerKeyers() { diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/RangeTests.java b/main/tests/server/src/com/google/refine/expr/functions/strings/RangeTests.java index be39e448d373..95f7d288e95a 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/RangeTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/RangeTests.java @@ -32,13 +32,13 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; /** * Tests for the range function. */ -public class RangeTests extends RefineTest { +public class RangeTests extends GrelTestBase { private static final Integer[] EMPTY_ARRAY = new Integer[0]; diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/ReplaceEachTest.java b/main/tests/server/src/com/google/refine/expr/functions/strings/ReplaceEachTest.java index 7914302eb17d..fb059070146e 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/ReplaceEachTest.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/ReplaceEachTest.java @@ -1,41 +1,43 @@ package com.google.refine.expr.functions.strings; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + import java.util.Properties; -import org.junit.Assert; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; import com.google.refine.expr.ParsingException; +import com.google.refine.grel.GrelTestBase; -public class ReplaceEachTest extends RefineTest { +public class ReplaceEachTest extends GrelTestBase { @Test public void replaceEachValidParams() { - Assert.assertTrue( + assertTrue( invoke("replaceEach", "abcdefghijklmnopqrstuvwxyz", new String[] { "a", "e", "i", "o", "u" }, "A") instanceof String); - Assert.assertEquals(invoke("replaceEach", "abcdefghijklmnopqrstuvwxyz", new String[] { "a", "e", "i", "o", "u" }, "A"), + assertEquals(invoke("replaceEach", "abcdefghijklmnopqrstuvwxyz", new String[] { "a", "e", "i", "o", "u" }, "A"), "AbcdAfghAjklmnApqrstAvwxyz"); - Assert.assertEquals( + assertEquals( invoke("replaceEach", "abcdefghijklmnopqrstuvwxyz", new String[] { "a", "e", "i", "o", "u" }, new String[] { "A" }), "AbcdAfghAjklmnApqrstAvwxyz"); - Assert.assertEquals(invoke("replaceEach", "abcdefghijklmnopqrstuvwxyz", new String[] { "a", "e", "i", "o", "u" }, + assertEquals(invoke("replaceEach", "abcdefghijklmnopqrstuvwxyz", new String[] { "a", "e", "i", "o", "u" }, new String[] { "A", "E", "I", "O", "U" }), "AbcdEfghIjklmnOpqrstUvwxyz"); } @Test public void replaceEachInvalidParams() { - Assert.assertTrue(invoke("replaceEach") instanceof EvalError); - Assert.assertTrue(invoke("replaceEach", "abcdefghijklmnopqrstuvwxyz") instanceof EvalError); - Assert.assertTrue( + assertTrue(invoke("replaceEach") instanceof EvalError); + assertTrue(invoke("replaceEach", "abcdefghijklmnopqrstuvwxyz") instanceof EvalError); + assertTrue( invoke("replaceEach", "abcdefghijklmnopqrstuvwxyz", new String[] { "a", "e", "i", "o", "u" }) instanceof EvalError); - Assert.assertTrue(invoke("replaceEach", "abcdefghijklmnopqrstuvwxyz", new String[] { "a", "e", "i", "o", "u" }, "A", + assertTrue(invoke("replaceEach", "abcdefghijklmnopqrstuvwxyz", new String[] { "a", "e", "i", "o", "u" }, "A", "B") instanceof EvalError); - Assert.assertTrue(invoke("replaceEach", new String[] { "a", "e", "i", "o", "u" }, new String[] { "A", "B" }, + assertTrue(invoke("replaceEach", new String[] { "a", "e", "i", "o", "u" }, new String[] { "A", "B" }, "abcdefghijklmnopqrstuvwxyz") instanceof EvalError); } diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/ReplaceTests.java b/main/tests/server/src/com/google/refine/expr/functions/strings/ReplaceTests.java index c4020a48cdd8..c80ef802196f 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/ReplaceTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/ReplaceTests.java @@ -32,10 +32,10 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class ReplaceTests extends RefineTest { +public class ReplaceTests extends GrelTestBase { @Test public void testReplace() { diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/SplitTests.java b/main/tests/server/src/com/google/refine/expr/functions/strings/SplitTests.java index e1a71c45c33e..3418e5734e43 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/SplitTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/SplitTests.java @@ -34,10 +34,10 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class SplitTests extends RefineTest { +public class SplitTests extends GrelTestBase { @Test public void testSplit() { diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/StartsWithTests.java b/main/tests/server/src/com/google/refine/expr/functions/strings/StartsWithTests.java index e8bd04500d15..d4240b1958ff 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/StartsWithTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/StartsWithTests.java @@ -32,9 +32,9 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; +import com.google.refine.grel.GrelTestBase; -public class StartsWithTests extends RefineTest { +public class StartsWithTests extends GrelTestBase { @Test public void testStartsWith() { diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/ToLowercaseTests.java b/main/tests/server/src/com/google/refine/expr/functions/strings/ToLowercaseTests.java index 2b0f731e70dc..f888fedf258e 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/ToLowercaseTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/ToLowercaseTests.java @@ -30,10 +30,10 @@ import org.testng.Assert; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class ToLowercaseTests extends RefineTest { +public class ToLowercaseTests extends GrelTestBase { @Test public void testtoLowercaseInvalidParams() { diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/ToTitlecaseTests.java b/main/tests/server/src/com/google/refine/expr/functions/strings/ToTitlecaseTests.java index 1c03fe605828..629d0b20e9d1 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/ToTitlecaseTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/ToTitlecaseTests.java @@ -30,10 +30,10 @@ import org.testng.Assert; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class ToTitlecaseTests extends RefineTest { +public class ToTitlecaseTests extends GrelTestBase { @Test public void testToTitlecaseInvalidParams() { diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/TrimTests.java b/main/tests/server/src/com/google/refine/expr/functions/strings/TrimTests.java index 9eab6685ea40..2e2c428a0617 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/TrimTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/TrimTests.java @@ -32,10 +32,10 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class TrimTests extends RefineTest { +public class TrimTests extends GrelTestBase { private static String NBSP = "\u00A0"; private static String ENQUAD = "\u2000"; diff --git a/main/tests/server/src/com/google/refine/expr/functions/strings/UnescapeTests.java b/main/tests/server/src/com/google/refine/expr/functions/strings/UnescapeTests.java index 2db76d4a2dd2..12c28cfc64ce 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/strings/UnescapeTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/strings/UnescapeTests.java @@ -31,9 +31,9 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; +import com.google.refine.grel.GrelTestBase; -public class UnescapeTests extends RefineTest { +public class UnescapeTests extends GrelTestBase { @Test public void testUnescape() { diff --git a/main/tests/server/src/com/google/refine/expr/functions/xml/ParseXmlTests.java b/main/tests/server/src/com/google/refine/expr/functions/xml/ParseXmlTests.java index f8f25197b332..6b17c071701c 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/xml/ParseXmlTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/xml/ParseXmlTests.java @@ -36,10 +36,10 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; -public class ParseXmlTests extends RefineTest { +public class ParseXmlTests extends GrelTestBase { static Properties bindings; static String x = "\n" + diff --git a/main/tests/server/src/com/google/refine/expr/functions/xml/WholeTextTests.java b/main/tests/server/src/com/google/refine/expr/functions/xml/WholeTextTests.java new file mode 100644 index 000000000000..f28a022f0b65 --- /dev/null +++ b/main/tests/server/src/com/google/refine/expr/functions/xml/WholeTextTests.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (C) 2018, OpenRefine contributors + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. 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. + * + * 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 HOLDER 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.expr.functions.xml; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; + +public class WholeTextTests extends GrelTestBase { + + @Test + public void testWholeText() { + Assert.assertTrue(invoke("wholeText") instanceof EvalError); + Assert.assertTrue(invoke("wholeText", "test") instanceof EvalError); + + EvalError evalError = (EvalError) invoke("wholeText", "test"); + Assert.assertEquals(evalError.toString(), + "wholeText() cannot work with this \'string\' and failed as the first parameter is not an XML or HTML Element. Please first use parseXml() or parseHtml() and select(query) prior to using this function"); + } +} diff --git a/main/tests/server/src/com/google/refine/expr/functions/xml/XmlTextTests.java b/main/tests/server/src/com/google/refine/expr/functions/xml/XmlTextTests.java new file mode 100644 index 000000000000..ffae7b112f91 --- /dev/null +++ b/main/tests/server/src/com/google/refine/expr/functions/xml/XmlTextTests.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (C) 2018, OpenRefine contributors + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. 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. + * + * 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 HOLDER 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.expr.functions.xml; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.google.refine.expr.EvalError; +import com.google.refine.grel.GrelTestBase; + +public class XmlTextTests extends GrelTestBase { + + @Test + public void testXmlText() { + Assert.assertTrue(invoke("xmlText") instanceof EvalError); + Assert.assertTrue(invoke("xmlText", "test") instanceof EvalError); + + EvalError evalError = (EvalError) invoke("xmlText", "test"); + Assert.assertEquals(evalError.toString(), + "xmlText() cannot work with this \'string\' and failed as the first parameter is not an XML or HTML Element. Please first use parseXml() or parseHtml() and select(query) prior to using this function"); + } +} diff --git a/main/tests/server/src/com/google/refine/grel/GrelTestBase.java b/main/tests/server/src/com/google/refine/grel/GrelTestBase.java new file mode 100644 index 000000000000..55bbadf27f99 --- /dev/null +++ b/main/tests/server/src/com/google/refine/grel/GrelTestBase.java @@ -0,0 +1,98 @@ + +package com.google.refine.grel; + +import java.util.Properties; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeTest; + +import com.google.refine.RefineTest; +import com.google.refine.expr.Evaluable; +import com.google.refine.expr.MetaParser; +import com.google.refine.expr.ParsingException; + +/** + * Base class for tests of GREL's functionalities + */ +public class GrelTestBase extends RefineTest { + + protected Logger logger = null; + + protected static Properties bindings = null; + + @BeforeTest + public void initLogger() { + logger = LoggerFactory.getLogger(this.getClass()); + } + + @BeforeMethod + public void setUp() { + bindings = new Properties(); + } + + @AfterMethod + public void tearDown() { + bindings = null; + } + + /** + * Lookup a control function by name and invoke it with a variable number of args + */ + protected static Object invoke(String name, Object... args) { + // registry uses static initializer, so no need to set it up + Function function = ControlFunctionRegistry.getFunction(name); + if (bindings == null) { + bindings = new Properties(); + } + if (function == null) { + throw new IllegalArgumentException("Unknown function " + name); + } + if (args == null) { + return function.call(bindings, new Object[0]); + } else { + return function.call(bindings, args); + } + } + + /** + * Parse and evaluate a GREL expression and compare the result to the expect value + * + * @param bindings + * @param test + * @throws ParsingException + */ + protected void parseEval(Properties bindings, String[] test) + throws ParsingException { + Evaluable eval = MetaParser.parse("grel:" + test[0]); + Object result = eval.evaluate(bindings); + if (test[1] != null) { + Assert.assertNotNull(result, "Expected " + test[1] + " for test " + test[0]); + Assert.assertEquals(result.toString(), test[1], "Wrong result for expression: " + test[0]); + } else { + Assert.assertNull(result, "Wrong result for expression: " + test[0]); + } + } + + /** + * Parse and evaluate a GREL expression and compare the result an expected type using instanceof + * + * @param bindings + * @param test + * @throws ParsingException + */ + protected void parseEvalType(Properties bindings, String test, @SuppressWarnings("rawtypes") Class clazz) + throws ParsingException { + Evaluable eval = MetaParser.parse("grel:" + test); + Object result = eval.evaluate(bindings); + Assert.assertTrue(clazz.isInstance(result), "Wrong result type for expression: " + test); + } + + @AfterMethod + public void TearDown() throws Exception { + bindings = null; + } +} diff --git a/main/tests/server/src/com/google/refine/grel/GrelTests.java b/main/tests/server/src/com/google/refine/grel/GrelTests.java index d7726dc6f41d..52a029fb575a 100644 --- a/main/tests/server/src/com/google/refine/grel/GrelTests.java +++ b/main/tests/server/src/com/google/refine/grel/GrelTests.java @@ -37,14 +37,11 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT import java.util.Properties; -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.RefineTest; import com.google.refine.expr.EvalError; import com.google.refine.expr.Evaluable; import com.google.refine.expr.ExpressionUtils; @@ -52,17 +49,11 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT import com.google.refine.expr.ParsingException; import com.google.refine.model.Project; -public class GrelTests extends RefineTest { +public class GrelTests extends GrelTestBase { Project project; Properties bindings; - @Override - @BeforeTest - public void init() { - logger = LoggerFactory.getLogger(this.getClass()); - } - @BeforeMethod public void SetUp() { project = new Project(); diff --git a/main/tests/server/src/com/google/refine/grel/controls/ForEachIndexTests.java b/main/tests/server/src/com/google/refine/grel/controls/ForEachIndexTests.java index 098b47932df9..e28274fa3d05 100644 --- a/main/tests/server/src/com/google/refine/grel/controls/ForEachIndexTests.java +++ b/main/tests/server/src/com/google/refine/grel/controls/ForEachIndexTests.java @@ -33,12 +33,12 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.MetaParser; import com.google.refine.expr.ParsingException; +import com.google.refine.grel.GrelTestBase; import com.google.refine.util.TestUtils; -public class ForEachIndexTests extends RefineTest { +public class ForEachIndexTests extends GrelTestBase { @Test public void serializeForEachIndex() { diff --git a/main/tests/server/src/com/google/refine/grel/controls/ForEachTests.java b/main/tests/server/src/com/google/refine/grel/controls/ForEachTests.java index 58754799811e..40cd495f995b 100644 --- a/main/tests/server/src/com/google/refine/grel/controls/ForEachTests.java +++ b/main/tests/server/src/com/google/refine/grel/controls/ForEachTests.java @@ -34,14 +34,14 @@ import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; import com.google.refine.expr.Evaluable; import com.google.refine.expr.MetaParser; import com.google.refine.expr.ParsingException; +import com.google.refine.grel.GrelTestBase; import com.google.refine.util.TestUtils; -public class ForEachTests extends RefineTest { +public class ForEachTests extends GrelTestBase { @Test public void serializeForEach() { diff --git a/main/tests/server/src/com/google/refine/grel/controls/ForRangeTests.java b/main/tests/server/src/com/google/refine/grel/controls/ForRangeTests.java index f9e53cae613c..e59ebbbfd188 100644 --- a/main/tests/server/src/com/google/refine/grel/controls/ForRangeTests.java +++ b/main/tests/server/src/com/google/refine/grel/controls/ForRangeTests.java @@ -34,14 +34,14 @@ import org.testng.Assert; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; import com.google.refine.expr.Evaluable; import com.google.refine.expr.MetaParser; import com.google.refine.expr.ParsingException; +import com.google.refine.grel.GrelTestBase; import com.google.refine.util.TestUtils; -public class ForRangeTests extends RefineTest { +public class ForRangeTests extends GrelTestBase { @Test public void serializeForRange() {