diff --git a/main/tests/server/src/com/google/refine/RefineTest.java b/main/tests/server/src/com/google/refine/RefineTest.java index 7ff47a97c..22b29ec6c 100644 --- a/main/tests/server/src/com/google/refine/RefineTest.java +++ b/main/tests/server/src/com/google/refine/RefineTest.java @@ -43,6 +43,7 @@ import java.io.IOException; import java.io.StringReader; import java.util.ArrayList; import java.util.List; +import java.util.Properties; import org.apache.commons.io.FileUtils; import org.powermock.modules.testng.PowerMockTestCase; @@ -57,6 +58,8 @@ import com.fasterxml.jackson.databind.node.BooleanNode; import com.fasterxml.jackson.databind.node.IntNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.TextNode; +import com.google.refine.grel.ControlFunctionRegistry; +import com.google.refine.grel.Function; import com.google.refine.importers.SeparatorBasedImporter; import com.google.refine.importing.ImportingJob; import com.google.refine.importing.ImportingManager; @@ -75,6 +78,8 @@ import edu.mit.simile.butterfly.ButterflyModule; */ public class RefineTest extends PowerMockTestCase { + protected static Properties bindings = null; + protected Logger logger; boolean testFailed; @@ -308,6 +313,30 @@ public class RefineTest extends PowerMockTestCase { verify(options, times(1)).get(name); } + /** + * 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); + } + } + + @AfterMethod + public void TearDown() throws Exception { + bindings = null; + } + protected ButterflyModule getCoreModule() { ButterflyModule coreModule = mock(ButterflyModule.class); when(coreModule.getName()).thenReturn("core"); 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 04893f12e..f545e3d5d 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 @@ -44,15 +44,11 @@ import org.testng.annotations.Test; import com.google.refine.RefineTest; 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.util.TestUtils; public class CoalesceTests extends RefineTest { - private static Properties bindings; private static final Integer[] ZERO_TO_TWO = new Integer[] {0, 1, 2}; @Override @@ -71,22 +67,6 @@ public class CoalesceTests extends RefineTest { bindings = null; } - /** - * Lookup a control function by name and invoke it with a variable number of args - */ - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } - @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 068cf0131..a8638e36f 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 @@ -41,8 +41,6 @@ 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.ControlFunctionRegistry; -import com.google.refine.grel.Function; import com.google.refine.model.Cell; import com.google.refine.model.Project; import com.google.refine.model.Row; @@ -52,7 +50,6 @@ import com.google.refine.util.TestUtils; * Test cases for cross function. */ public class CrossTests extends RefineTest { - static Properties bindings; private static OffsetDateTime dateTimeValue = OffsetDateTime.parse("2017-05-12T05:45:00+00:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME); @Override @@ -374,22 +371,6 @@ public class CrossTests extends RefineTest { "cross expects a cell or value, a project name to look up (optional), and a column name in that project (optional)"); } - /** - * Lookup a control function by name and invoke it with a variable number of args - */ - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } - @Test public void serializeCross() { String json = "{\"description\":\"Looks up the given value in the target column of the target project, returns an array of matched rows. Two values match if and only if they have the same string representation. " + 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 4e18408ea..56b4baab7 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 @@ -42,14 +42,10 @@ import java.util.Properties; import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; -import com.google.refine.expr.functions.Type; -import com.google.refine.grel.ControlFunctionRegistry; -import com.google.refine.grel.Function; import com.google.refine.util.TestUtils; public class TypeTests extends RefineTest { - private static Properties bindings; 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); @@ -69,22 +65,6 @@ public class TypeTests extends RefineTest { bindings = null; } - /** - * Lookup a control function by name and invoke it with a variable number of args - */ - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } - @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 5d3e0dcea..09e7549a6 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 @@ -32,16 +32,11 @@ import java.util.List; import java.util.Properties; import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import com.fasterxml.jackson.databind.node.ArrayNode; import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; -import com.google.refine.expr.functions.arrays.InArray; -import com.google.refine.grel.ControlFunctionRegistry; -import com.google.refine.grel.Function; import com.google.refine.util.TestUtils; public class InArrayTests extends RefineTest { @@ -51,16 +46,6 @@ public class InArrayTests extends RefineTest { static final String stringArray[] = {"v1","v2","v3"}; - @BeforeMethod - public void SetUp() { - bindings = new Properties(); - } - - @AfterMethod - public void TearDown() { - bindings = null; - } - @Test public void serializeInArray() { String json = "{\"description\":\"Checks if array a contains string s\",\"params\":\"array a, string s\",\"returns\":\"boolean\"}"; @@ -93,18 +78,5 @@ public class InArrayTests extends RefineTest { Assert.assertTrue((boolean) invoke("inArray", arrayNode, "v1")); Assert.assertFalse((boolean) invoke("inArray", arrayNode, "v4")); } - - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } } 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 0aecb1e05..ca8d79978 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 @@ -33,24 +33,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.expr.functions.booleans; -import java.io.IOException; -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.ControlFunctionRegistry; -import com.google.refine.grel.Function; -import com.google.refine.model.Cell; -import com.google.refine.model.ModelException; -import com.google.refine.model.Project; -import com.google.refine.model.Row; public class BooleanTests extends RefineTest { @@ -72,54 +61,12 @@ public class BooleanTests extends RefineTest { {"xor","false","true","false","true"}, }; - - static private Properties bindings; - private Project project; - - @Override @BeforeTest public void init() { logger = LoggerFactory.getLogger(this.getClass()); } - @BeforeMethod - public void SetUp() throws IOException, ModelException { - bindings = new Properties(); - project = createProjectWithColumns("BooleanTests", "Column A"); - - bindings.put("project", project); - - // Five rows of a's and five of 1s - for (int i = 0; i < 10; i++) { - Row row = new Row(1); - row.setCell(0, new Cell(i < 5 ? "a":new Integer(1), null)); - project.rows.add(row); - } - } - - - @AfterMethod - public void TearDown() { - bindings = null; - } - - /** - * Lookup a control function by name and invoke it with a variable number of args - */ - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } - @Test public void testInvalidParams() { for (String op : new String[] {"and","or","xor"}) { 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 d480c38c3..5fbbd2e97 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 @@ -35,15 +35,10 @@ import java.util.TimeZone; 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.functions.date.DatePart; -import com.google.refine.grel.ControlFunctionRegistry; -import com.google.refine.grel.Function; import com.google.refine.util.TestUtils; @@ -57,32 +52,6 @@ public class DatePartTests extends RefineTest { 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 - */ - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } - private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd-HH:mm:ss.SSSSSSSSSX"); @Test 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 a9e9a8525..81f42e71d 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 @@ -29,25 +29,18 @@ package com.google.refine.expr.functions.date; import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; -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.functions.date.Inc; -import com.google.refine.grel.ControlFunctionRegistry; -import com.google.refine.grel.Function; import com.google.refine.util.TestUtils; public class IncTests extends RefineTest { - private static Properties bindings; private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd-HH:mm:ss.SSSSSSSSSX"); @Override @@ -55,33 +48,7 @@ public class IncTests extends RefineTest { public void init() { 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 - */ - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } - @Test public void testInc() { OffsetDateTime source = OffsetDateTime.parse("20180510-23:55:44.000789000Z", 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 45ad6218a..22516d123 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 @@ -28,24 +28,17 @@ package com.google.refine.expr.functions.date; import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; -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.functions.date.Now; -import com.google.refine.grel.ControlFunctionRegistry; -import com.google.refine.grel.Function; import com.google.refine.util.TestUtils; public class NowTests extends RefineTest { - private static Properties bindings; private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd-HH:mm:ss.SSSSSSSSSX"); @Override @@ -53,33 +46,7 @@ public class NowTests extends RefineTest { public void init() { 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 - */ - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } - @Test public void testNow() { // 2018-4-30 23:55:44 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 7c5294f66..d81a78b39 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 @@ -33,15 +33,10 @@ 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 com.google.refine.RefineTest; import com.google.refine.expr.EvalError; -import com.google.refine.expr.functions.html.ParseHtml; -import com.google.refine.grel.ControlFunctionRegistry; -import com.google.refine.grel.Function; import com.google.refine.util.TestUtils; public class ParseHtmlTests extends RefineTest { @@ -65,32 +60,6 @@ public class ParseHtmlTests extends RefineTest { 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 - */ - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } - @Test public void serializeParseHtml() { String json = "{\"description\":\"Parses a string as HTML\",\"params\":\"string s\",\"returns\":\"HTML object\"}"; diff --git a/main/tests/server/src/com/google/refine/expr/functions/math/RandomNumberTests.java b/main/tests/server/src/com/google/refine/expr/functions/math/RandomNumberTests.java index 287611984..3fb5b93b3 100644 --- a/main/tests/server/src/com/google/refine/expr/functions/math/RandomNumberTests.java +++ b/main/tests/server/src/com/google/refine/expr/functions/math/RandomNumberTests.java @@ -29,31 +29,15 @@ package com.google.refine.expr.functions.math; import java.util.Properties; import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import com.google.refine.expr.functions.math.RandomNumber; import com.google.refine.RefineTest; import com.google.refine.expr.EvalError; -import com.google.refine.expr.functions.arrays.InArray; -import com.google.refine.grel.ControlFunctionRegistry; -import com.google.refine.grel.Function; import com.google.refine.util.TestUtils; public class RandomNumberTests extends RefineTest { static Properties bindings; - @BeforeMethod - public void SetUp() { - bindings = new Properties(); - } - - @AfterMethod - public void TearDown() { - bindings = null; - } - @Test public void serializeRandomNumber() { String json = "{\"description\":\"Returns a pseudo-random integer between the lower and upper bound (inclusive)\",\"params\":\"number lower bound, number upper bound\",\"returns\":\"number\"}"; @@ -73,18 +57,5 @@ public class RandomNumberTests extends RefineTest { Object a = invoke("randomNumber", 1, 10); Assert.assertTrue((int) a < 11 && (int) a > 0); } - - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } } 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 ea70f882a..76f288eca 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 @@ -26,33 +26,20 @@ ******************************************************************************/ package com.google.refine.expr.functions.strings; -import org.testng.annotations.Test; - -import com.google.refine.expr.functions.strings.Contains; -import com.google.refine.util.TestUtils; - -import java.util.Properties; import java.util.regex.Pattern; 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.RefineServlet; -import com.google.refine.RefineServletStub; import com.google.refine.RefineTest; -import com.google.refine.grel.ControlFunctionRegistry; -import com.google.refine.grel.Function; +import com.google.refine.util.TestUtils; /** * Test cases for find function. */ public class ContainsTests extends RefineTest { - - static Properties bindings; @Override @BeforeTest @@ -60,21 +47,6 @@ public class ContainsTests extends RefineTest { logger = LoggerFactory.getLogger(this.getClass()); } - // dependencies - RefineServlet servlet; - - @BeforeMethod - public void SetUp() { - bindings = new Properties(); - - servlet = new RefineServletStub(); - } - - @AfterMethod - public void TearDown() { - } - - @Test public void testContainsFunction() { String value = "rose is a rose"; @@ -84,27 +56,11 @@ public class ContainsTests extends RefineTest { Assert.assertEquals(invoke("contains", value, "$"),false); Assert.assertEquals(invoke("contains", value, "r.se"),false); Assert.assertEquals(invoke("contains", value, "\\s+"),false); - // Input regex pattern in UI with : "/ /" , is intepreted as Pattern + // Input regex pattern in UI with : "/ /" , is interpreted as Pattern Assert.assertEquals(invoke("contains", value, Pattern.compile("$")),true); Assert.assertEquals(invoke("contains", value, Pattern.compile("\\s+")),true); } - /** - * Lookup a control function by name and invoke it with a variable number of args - */ - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } - @Test public void serializeContains() { String json = "{\"description\":\"Returns whether s contains frag\",\"params\":\"string s, string frag\",\"returns\":\"boolean\"}"; 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 37c5971ff..7e60d1034 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 @@ -33,16 +33,11 @@ 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.functions.strings.Diff; -import com.google.refine.grel.ControlFunctionRegistry; -import com.google.refine.grel.Function; import com.google.refine.util.TestUtils; @@ -73,32 +68,6 @@ public class DiffTests extends RefineTest { odt8 = OffsetDateTime.of(1923, 4, 21, 12, 0, 0, 0, ZoneOffset.UTC); } - @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 - */ - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } - @Test public void testDiffInvalidParams() { Assert.assertTrue(invoke("diff") instanceof EvalError); 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 530fffa25..06ca39da4 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 @@ -31,17 +31,11 @@ import java.util.regex.Pattern; 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.RefineServlet; -import com.google.refine.RefineServletStub; import com.google.refine.RefineTest; -import com.google.refine.expr.functions.strings.Find; -import com.google.refine.grel.ControlFunctionRegistry; -import com.google.refine.grel.Function; import com.google.refine.util.TestUtils; /** @@ -59,18 +53,6 @@ public class FindTests extends RefineTest { // dependencies RefineServlet servlet; - @BeforeMethod - public void SetUp() { - bindings = new Properties(); - - servlet = new RefineServletStub(); - } - - @AfterMethod - public void TearDown() { - } - - @Test public void findFunctionFindAllTest() throws Exception { String[] matches = (String[]) invoke("find", "This is a test string for testing find.", "test"); @@ -96,20 +78,4 @@ public class FindTests extends RefineTest { 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); } - - /** - * Lookup a control function by name and invoke it with a variable number of args - */ - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } } 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 8fdd2aeed..66138c9a8 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 @@ -35,15 +35,10 @@ 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.functions.strings.Fingerprint; -import com.google.refine.grel.ControlFunctionRegistry; -import com.google.refine.grel.Function; import com.google.refine.util.TestUtils; @@ -71,32 +66,6 @@ public class FingerprintTests extends RefineTest { 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 - */ - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } - @Test public void testInvalidParams() { Assert.assertNull(invoke("fingerprint")); 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 7f770ce3a..71ead4605 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 @@ -26,20 +26,13 @@ ******************************************************************************/ package com.google.refine.expr.functions.strings; -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.functions.strings.Range; -import com.google.refine.grel.ControlFunctionRegistry; -import com.google.refine.grel.Function; import com.google.refine.util.TestUtils; /** @@ -47,8 +40,6 @@ import com.google.refine.util.TestUtils; */ public class RangeTests extends RefineTest { - private static Properties bindings; - private static final Integer[] EMPTY_ARRAY = new Integer[0]; private static final Integer[] ONE_AND_THREE = new Integer[] {1, 3}; @@ -67,32 +58,6 @@ public class RangeTests extends RefineTest { 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 - */ - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } - @Test public void testRangeInvalidParams() { // Test number of arguments 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 54bfb47ed..41c7d45c8 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 @@ -30,16 +30,11 @@ 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.functions.strings.Trim; -import com.google.refine.grel.ControlFunctionRegistry; -import com.google.refine.grel.Function; import com.google.refine.util.TestUtils; @@ -85,32 +80,6 @@ public class TrimTests extends RefineTest { 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 - */ - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } - @Test public void testInvalidParams() { Assert.assertTrue(invoke("trim") instanceof EvalError); 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 189e41804..213da6dae 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 @@ -34,15 +34,10 @@ 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 com.google.refine.RefineTest; import com.google.refine.expr.EvalError; -import com.google.refine.expr.functions.xml.ParseXml; -import com.google.refine.grel.ControlFunctionRegistry; -import com.google.refine.grel.Function; import com.google.refine.util.TestUtils; @@ -72,32 +67,6 @@ public class ParseXmlTests extends RefineTest { 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 - */ - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } - @Test public void serializeParseXml() { String json = "{\"description\":\"Parses a string as XML\",\"params\":\"string s\",\"returns\":\"XML object\"}"; diff --git a/main/tests/server/src/com/google/refine/grel/FunctionTests.java b/main/tests/server/src/com/google/refine/grel/FunctionTests.java index 5e671e5c2..1bf04b96e 100644 --- a/main/tests/server/src/com/google/refine/grel/FunctionTests.java +++ b/main/tests/server/src/com/google/refine/grel/FunctionTests.java @@ -54,8 +54,6 @@ import org.testng.annotations.Test; import com.google.refine.RefineTest; import com.google.refine.browsing.Engine; import com.google.refine.expr.EvalError; -import com.google.refine.grel.ControlFunctionRegistry; -import com.google.refine.grel.Function; import com.google.refine.model.Cell; import com.google.refine.model.ModelException; import com.google.refine.model.Project; @@ -63,12 +61,9 @@ import com.google.refine.model.Row; public class FunctionTests extends RefineTest { - - static Properties bindings; Project project; Engine engine; - @Override @BeforeTest public void init() { @@ -77,11 +72,10 @@ public class FunctionTests extends RefineTest { @BeforeMethod public void SetUp() throws IOException, ModelException { - project = createProjectWithColumns("FunctionTests", "Column A"); bindings = new Properties(); bindings.put("project", project); - + // Five rows of a's and five of 1s for (int i = 0; i < 10; i++) { Row row = new Row(1); @@ -95,31 +89,14 @@ public class FunctionTests extends RefineTest { public void TearDown() { bindings = null; } - - /** - * Lookup a control function by name and invoke it with a variable number of args - */ - private static Object invoke(String name,Object... args) { - // registry uses static initializer, so no need to set it up - Function function = ControlFunctionRegistry.getFunction(name); - 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); - } - } - + @Test public void testInvalidParams() { Assert.assertTrue(invoke("facetCount") instanceof EvalError); Assert.assertTrue(invoke("facetCount", "one","two","three") instanceof EvalError); Assert.assertTrue(invoke("facetCount", "one","bad(","Column A") instanceof EvalError); - } - + @Test public void testFacetCount() { Assert.assertEquals(invoke("facetCount", "a", "value", "Column A"),Integer.valueOf(5)); diff --git a/main/tests/server/src/com/google/refine/importers/XmlImportUtilitiesTests.java b/main/tests/server/src/com/google/refine/importers/XmlImportUtilitiesTests.java index b42e5d9c8..419546427 100644 --- a/main/tests/server/src/com/google/refine/importers/XmlImportUtilitiesTests.java +++ b/main/tests/server/src/com/google/refine/importers/XmlImportUtilitiesTests.java @@ -49,7 +49,6 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.refine.RefineTest; -import com.google.refine.importers.JsonImporter; import com.google.refine.importers.JsonImporter.JSONTreeReader; import com.google.refine.importers.XmlImporter.XmlParser; import com.google.refine.importers.tree.ImportColumn;