Update Cross tests to include tests for Wrapped cells/non-strings

This commit is contained in:
Owen Stephens 2018-11-22 17:54:14 +00:00
parent 5387e91493
commit 72be6e14a4

View File

@ -1,6 +1,9 @@
package com.google.refine.tests.expr.functions;
import java.io.IOException;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Properties;
@ -13,10 +16,12 @@ import org.testng.annotations.Test;
import com.google.refine.expr.EvalError;
import com.google.refine.expr.HasFieldsListImpl;
import com.google.refine.expr.WrappedRow;
import com.google.refine.expr.WrappedCell;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
import com.google.refine.model.Project;
import com.google.refine.model.Row;
import com.google.refine.model.Cell;
import com.google.refine.tests.RefineTest;
/**
@ -24,6 +29,9 @@ import com.google.refine.tests.RefineTest;
*/
public class CrossFunctionTests extends RefineTest {
static Properties bindings;
private static OffsetDateTime dateTimeValue = OffsetDateTime.parse("2017-05-12T05:45:00+00:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME);
private static int integerValue = 1600;
private static Boolean booleanValue = true;
@Override
@BeforeTest
@ -45,16 +53,31 @@ public class CrossFunctionTests extends RefineTest {
+ "john,120 Main St.\n"
+ "mary,50 Broadway Ave.\n"
+ "john,999 XXXXXX St.\n" // john's 2nd address
+ "anne,17 Morning Crescent\n";
+ "anne,17 Morning Crescent\n"
+ "2017-05-12T05:45:00Z,dateTime\n"
+ "1600,integer\n"
+ "true,boolean\n";
projectAddress = createCSVProject(projectName, input);
projectName = "Christmas Gifts";
input = "gift,recipient\n"
+ "lamp,mary\n"
+ "clock,john\n";
+ "clock,john\n"
+ "dateTime,2017-05-12T05:45:00Z\n"
+ "integer,1600\n"
+ "boolean,true\n";
projectGift = createCSVProject(projectName, input);
bindings.put("project", projectGift);
//Add some non-string value cells to each project
projectAddress.rows.get(4).cells.set(0, new Cell(dateTimeValue, null));
projectAddress.rows.get(5).cells.set(0, new Cell(1600, null));
projectAddress.rows.get(6).cells.set(0, new Cell(true, null));
projectGift.rows.get(2).cells.set(1, new Cell(dateTimeValue, null));
projectGift.rows.get(3).cells.set(1, new Cell(1600, null));
projectGift.rows.get(4).cells.set(1, new Cell(true, null));
// add a column address based on column recipient
bindings.put("columnName", "recipient");
}
@ -82,6 +105,37 @@ public class CrossFunctionTests extends RefineTest {
Assert.assertNull(invoke("cross", "Anne", "My Address Book", "friend"));
}
@Test
public void crossFunctionDateTimeTest() throws Exception {
Project project = (Project) bindings.get("project");
Cell c = project.rows.get(2).cells.get(1);
WrappedCell lookup = new WrappedCell(project, "recipient", c);
Row row = ((Row)((WrappedRow) ((HasFieldsListImpl) invoke("cross", lookup, "My Address Book", "friend")).get(0)).row);
String address = row.getCell(1).value.toString();
Assert.assertEquals(address, "dateTime");
}
@Test
public void crossFunctionIntegerTest() throws Exception {
Project project = (Project) bindings.get("project");
Cell c = project.rows.get(3).cells.get(1);
WrappedCell lookup = new WrappedCell(project, "recipient", c);
Row row = ((Row)((WrappedRow) ((HasFieldsListImpl) invoke("cross", lookup, "My Address Book", "friend")).get(0)).row);
String address = row.getCell(1).value.toString();
Assert.assertEquals(address, "integer");
}
@Test
public void crossFunctionBooleanTest() throws Exception {
Project project = (Project) bindings.get("project");
Cell c = project.rows.get(4).cells.get(1);
WrappedCell lookup = new WrappedCell(project, "recipient", c);
Row row = ((Row)((WrappedRow) ((HasFieldsListImpl) invoke("cross", lookup, "My Address Book", "friend")).get(0)).row);
String address = row.getCell(1).value.toString();
Assert.assertEquals(address, "boolean");
}
/**
* If no match, return null.
*