Add deserialization tests for operations
This commit is contained in:
parent
2edf83bdf7
commit
8896636017
@ -4,6 +4,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
@ -45,14 +46,13 @@ public class BlankDownTests extends RefineTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeBlankDownOperation() {
|
||||
AbstractOperation op = new BlankDownOperation(
|
||||
new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}"),
|
||||
"my column");
|
||||
TestUtils.isSerializedTo(op, "{\"op\":\"core/blank-down\","
|
||||
public void serializeBlankDownOperation() throws JSONException, Exception {
|
||||
String json = "{\"op\":\"core/blank-down\","
|
||||
+ "\"description\":\"Blank down cells in column my column\","
|
||||
+ "\"engineConfig\":{\"mode\":\"record-based\",\"facets\":[]},"
|
||||
+ "\"columnName\":\"my column\"}");
|
||||
+ "\"columnName\":\"my column\"}";
|
||||
AbstractOperation op = BlankDownOperation.reconstruct(project, new JSONObject(json));
|
||||
TestUtils.isSerializedTo(op, json);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2,6 +2,7 @@ package com.google.refine.tests.operations.cell;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
@ -43,14 +44,12 @@ public class FillDownTests extends RefineTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeFillDownOperation() {
|
||||
AbstractOperation op = new FillDownOperation(
|
||||
new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}"),
|
||||
"my key");
|
||||
TestUtils.isSerializedTo(op, "{\"op\":\"core/fill-down\","
|
||||
public void serializeFillDownOperation() throws JSONException, Exception {
|
||||
String json = "{\"op\":\"core/fill-down\","
|
||||
+ "\"description\":\"Fill down cells in column my key\","
|
||||
+ "\"engineConfig\":{\"mode\":\"record-based\",\"facets\":[]},"
|
||||
+ "\"columnName\":\"my key\"}");
|
||||
+ "\"columnName\":\"my key\"}";
|
||||
TestUtils.isSerializedTo(FillDownOperation.reconstruct(project, new JSONObject(json)), json);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -35,9 +35,11 @@ package com.google.refine.tests.operations.cell;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
@ -53,6 +55,8 @@ import com.google.refine.tests.util.TestUtils;
|
||||
|
||||
|
||||
public class JoinMultiValuedCellsTests extends RefineTest {
|
||||
|
||||
Project project;
|
||||
|
||||
@Override
|
||||
@BeforeTest
|
||||
@ -65,17 +69,24 @@ public class JoinMultiValuedCellsTests extends RefineTest {
|
||||
OperationRegistry.registerOperation(getCoreModule(), "multivalued-cell-join", MultiValuedCellJoinOperation.class);
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
public void createProject() {
|
||||
project = createCSVProject(
|
||||
"Key,Value\n"
|
||||
+ "Record_1,one\n"
|
||||
+ ",two\n"
|
||||
+ ",three\n"
|
||||
+ ",four\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeMultiValuedCellJoinOperation() {
|
||||
AbstractOperation op = new MultiValuedCellJoinOperation(
|
||||
"value column",
|
||||
"key column",
|
||||
",");
|
||||
TestUtils.isSerializedTo(op, "{\"op\":\"core/multivalued-cell-join\","
|
||||
public void serializeMultiValuedCellJoinOperation() throws JSONException, Exception {
|
||||
String json = "{\"op\":\"core/multivalued-cell-join\","
|
||||
+ "\"description\":\"Join multi-valued cells in column value column\","
|
||||
+ "\"columnName\":\"value column\","
|
||||
+ "\"keyColumnName\":\"key column\","
|
||||
+ "\"separator\":\",\"}");
|
||||
+ "\"separator\":\",\"}";
|
||||
TestUtils.isSerializedTo(MultiValuedCellJoinOperation.reconstruct(project, new JSONObject(json)), json);
|
||||
}
|
||||
|
||||
|
||||
@ -85,13 +96,6 @@ public class JoinMultiValuedCellsTests extends RefineTest {
|
||||
|
||||
@Test
|
||||
public void testJoinMultiValuedCells() throws Exception {
|
||||
Project project = createCSVProject(
|
||||
"Key,Value\n"
|
||||
+ "Record_1,one\n"
|
||||
+ ",two\n"
|
||||
+ ",three\n"
|
||||
+ ",four\n");
|
||||
|
||||
AbstractOperation op = new MultiValuedCellJoinOperation(
|
||||
"Value",
|
||||
"Key",
|
||||
@ -108,14 +112,6 @@ public class JoinMultiValuedCellsTests extends RefineTest {
|
||||
|
||||
@Test
|
||||
public void testJoinMultiValuedCellsMultipleSpaces() throws Exception {
|
||||
Project project = createCSVProject(
|
||||
"Key,Value\n"
|
||||
+ "Record_1,one\n"
|
||||
+ ",two\n"
|
||||
+ ",three\n"
|
||||
+ ",four\n");
|
||||
|
||||
|
||||
AbstractOperation op = new MultiValuedCellJoinOperation(
|
||||
"Value",
|
||||
"Key",
|
||||
|
@ -114,15 +114,20 @@ public class KeyValueColumnizeTests extends RefineTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeKeyValueColumnizeOperation() {
|
||||
AbstractOperation op = new KeyValueColumnizeOperation("key column", "value column", null);
|
||||
TestUtils.isSerializedTo(op, "{\"op\":\"core/key-value-columnize\",\"description\":\"Columnize by key column key column and value column value column\",\"keyColumnName\":\"key column\",\"valueColumnName\":\"value column\",\"noteColumnName\":null}");
|
||||
op = new KeyValueColumnizeOperation("key column", "value column", "note column");
|
||||
TestUtils.isSerializedTo(op, "{\"op\":\"core/key-value-columnize\","
|
||||
public void serializeKeyValueColumnizeOperation() throws JSONException, Exception {
|
||||
String json = "{\"op\":\"core/key-value-columnize\","
|
||||
+ "\"description\":\"Columnize by key column key column and value column value column\","
|
||||
+ "\"keyColumnName\":\"key column\","
|
||||
+ "\"valueColumnName\":\"value column\","
|
||||
+ "\"noteColumnName\":null}";
|
||||
TestUtils.isSerializedTo(KeyValueColumnizeOperation.reconstruct(project, new JSONObject(json)), json);
|
||||
|
||||
String jsonFull = "{\"op\":\"core/key-value-columnize\","
|
||||
+ "\"description\":\"Columnize by key column key column and value column value column with note column note column\","
|
||||
+ "\"keyColumnName\":\"key column\","
|
||||
+ "\"valueColumnName\":\"value column\","
|
||||
+ "\"noteColumnName\":\"note column\"}");
|
||||
+ "\"noteColumnName\":\"note column\"}";
|
||||
TestUtils.isSerializedTo(KeyValueColumnizeOperation.reconstruct(project, new JSONObject(jsonFull)), jsonFull);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,8 +7,9 @@ import org.json.JSONObject;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.Test;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import com.google.refine.model.AbstractOperation;
|
||||
import com.google.refine.model.Project;
|
||||
import com.google.refine.operations.OperationRegistry;
|
||||
import com.google.refine.operations.cell.MassEditOperation;
|
||||
import com.google.refine.operations.cell.MassEditOperation.Edit;
|
||||
@ -28,16 +29,13 @@ public class MassOperationTests extends RefineTest {
|
||||
|
||||
@Test
|
||||
public void serializeMassEditOperation() throws JSONException, Exception {
|
||||
editsString = "[{\"from\":[\"String\"],\"to\":\"newString\",\"type\":\"text\"}]";
|
||||
|
||||
editList = MassEditOperation.reconstructEdits(ParsingUtilities.evaluateJsonStringToArray(editsString));
|
||||
JSONObject engineConfig = new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}");
|
||||
AbstractOperation op = new MassEditOperation(engineConfig, "my column", "value", editList);
|
||||
TestUtils.isSerializedTo(op, "{\"op\":\"core/mass-edit\","
|
||||
Project project = mock(Project.class);
|
||||
String json = "{\"op\":\"core/mass-edit\","
|
||||
+ "\"description\":\"Mass edit cells in column my column\","
|
||||
+ "\"engineConfig\":{\"mode\":\"record-based\",\"facets\":[]},"
|
||||
+ "\"columnName\":\"my column\",\"expression\":\"value\","
|
||||
+ "\"edits\":[{\"fromBlank\":false,\"fromError\":false,\"from\":[\"String\"],\"to\":\"newString\"}]}");
|
||||
+ "\"edits\":[{\"fromBlank\":false,\"fromError\":false,\"from\":[\"String\"],\"to\":\"newString\"}]}";
|
||||
TestUtils.isSerializedTo(MassEditOperation.reconstruct(project, new JSONObject(json)), json);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -36,8 +36,11 @@ package com.google.refine.tests.operations.cell;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@ -52,6 +55,8 @@ import com.google.refine.tests.util.TestUtils;
|
||||
|
||||
|
||||
public class SplitMultiValuedCellsTests extends RefineTest {
|
||||
|
||||
Project project;
|
||||
|
||||
@Override
|
||||
@BeforeTest
|
||||
@ -60,20 +65,23 @@ public class SplitMultiValuedCellsTests extends RefineTest {
|
||||
OperationRegistry.registerOperation(getCoreModule(), "multivalued-cell-split", MultiValuedCellSplitOperation.class);
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
public void createProject() {
|
||||
project = createCSVProject(
|
||||
"Key,Value\n"
|
||||
+ "Record_1,one:two;three four\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeMultiValuedCellSplitOperation() {
|
||||
AbstractOperation op = new MultiValuedCellSplitOperation(
|
||||
"Value",
|
||||
"Key",
|
||||
":",
|
||||
false);
|
||||
TestUtils.isSerializedTo(op, "{\"op\":\"core/multivalued-cell-split\","
|
||||
public void serializeMultiValuedCellSplitOperation() throws JSONException, Exception {
|
||||
String json = "{\"op\":\"core/multivalued-cell-split\","
|
||||
+ "\"description\":\"Split multi-valued cells in column Value\","
|
||||
+ "\"columnName\":\"Value\","
|
||||
+ "\"keyColumnName\":\"Key\","
|
||||
+ "\"mode\":\"separator\","
|
||||
+ "\"separator\":\":\","
|
||||
+ "\"regex\":false}");
|
||||
+ "\"regex\":false}";
|
||||
TestUtils.isSerializedTo(MultiValuedCellSplitOperation.reconstruct(project, new JSONObject(json)), json);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,10 +91,6 @@ public class SplitMultiValuedCellsTests extends RefineTest {
|
||||
|
||||
@Test
|
||||
public void testSplitMultiValuedCellsTextSeparator() throws Exception {
|
||||
Project project = createCSVProject(
|
||||
"Key,Value\n"
|
||||
+ "Record_1,one:two;three four\n");
|
||||
|
||||
AbstractOperation op = new MultiValuedCellSplitOperation(
|
||||
"Value",
|
||||
"Key",
|
||||
@ -106,10 +110,6 @@ public class SplitMultiValuedCellsTests extends RefineTest {
|
||||
|
||||
@Test
|
||||
public void testSplitMultiValuedCellsRegExSeparator() throws Exception {
|
||||
Project project = createCSVProject(
|
||||
"Key,Value\n"
|
||||
+ "Record_1,one:two;three four\n");
|
||||
|
||||
AbstractOperation op = new MultiValuedCellSplitOperation(
|
||||
"Value",
|
||||
"Key",
|
||||
@ -133,10 +133,6 @@ public class SplitMultiValuedCellsTests extends RefineTest {
|
||||
|
||||
@Test
|
||||
public void testSplitMultiValuedCellsLengths() throws Exception {
|
||||
Project project = createCSVProject(
|
||||
"Key,Value\n"
|
||||
+ "Record_1,one:two;three four\n");
|
||||
|
||||
int[] lengths = {4,4,6,4};
|
||||
|
||||
AbstractOperation op = new MultiValuedCellSplitOperation(
|
||||
|
@ -33,13 +33,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package com.google.refine.tests.operations.cell;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.refine.model.AbstractOperation;
|
||||
import com.google.refine.model.Project;
|
||||
import com.google.refine.operations.OperationRegistry;
|
||||
import com.google.refine.operations.cell.BlankDownOperation;
|
||||
import com.google.refine.operations.cell.TransposeRowsIntoColumnsOperation;
|
||||
@ -57,12 +61,13 @@ public class TransposeTests extends RefineTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransposeRowsIntoColumnsOperation() {
|
||||
AbstractOperation op = new TransposeRowsIntoColumnsOperation("start column", 3);
|
||||
TestUtils.isSerializedTo(op, "{\"op\":\"core/transpose-rows-into-columns\","
|
||||
public void testTransposeRowsIntoColumnsOperation() throws JSONException, Exception {
|
||||
String json = "{\"op\":\"core/transpose-rows-into-columns\","
|
||||
+ "\"description\":\"Transpose every 3 cells in column start column into separate columns\","
|
||||
+ "\"columnName\":\"start column\","
|
||||
+ "\"rowCount\":3}");
|
||||
+ "\"rowCount\":3}";
|
||||
Project project = mock(Project.class);
|
||||
TestUtils.isSerializedTo(TransposeRowsIntoColumnsOperation.reconstruct(project , new JSONObject(json)), json);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,14 @@
|
||||
package com.google.refine.tests.operations.column;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.refine.model.AbstractOperation;
|
||||
import com.google.refine.model.Project;
|
||||
import com.google.refine.operations.OperationRegistry;
|
||||
import com.google.refine.operations.cell.BlankDownOperation;
|
||||
import com.google.refine.operations.column.ColumnMoveOperation;
|
||||
@ -18,11 +23,12 @@ public class ColumnMoveOperationTests extends RefineTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeColumnMoveOperation() {
|
||||
AbstractOperation op = new ColumnMoveOperation("my column", 3);
|
||||
TestUtils.isSerializedTo(op, "{\"op\":\"core/column-move\","
|
||||
public void serializeColumnMoveOperation() throws JSONException, Exception {
|
||||
String json = "{\"op\":\"core/column-move\","
|
||||
+ "\"description\":\"Move column my column to position 3\","
|
||||
+ "\"columnName\":\"my column\","
|
||||
+ "\"index\":3}");
|
||||
+ "\"index\":3}";
|
||||
Project project = mock(Project.class);
|
||||
TestUtils.isSerializedTo(ColumnMoveOperation.reconstruct(project , new JSONObject(json)), json);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
package com.google.refine.tests.operations.column;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.refine.model.AbstractOperation;
|
||||
import com.google.refine.model.Project;
|
||||
import com.google.refine.operations.OperationRegistry;
|
||||
import com.google.refine.operations.column.ColumnMoveOperation;
|
||||
import com.google.refine.operations.column.ColumnRemovalOperation;
|
||||
import com.google.refine.tests.RefineTest;
|
||||
import com.google.refine.tests.util.TestUtils;
|
||||
@ -19,10 +22,11 @@ public class ColumnRemovalOperationTests extends RefineTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeColumnRemovalOperation() {
|
||||
AbstractOperation op = new ColumnRemovalOperation("my column");
|
||||
TestUtils.isSerializedTo(op, "{\"op\":\"core/column-removal\","
|
||||
public void serializeColumnRemovalOperation() throws JSONException, Exception {
|
||||
String json = "{\"op\":\"core/column-removal\","
|
||||
+ "\"description\":\"Remove column my column\","
|
||||
+ "\"columnName\":\"my column\"}");
|
||||
+ "\"columnName\":\"my column\"}";
|
||||
Project project = mock(Project.class);
|
||||
TestUtils.isSerializedTo(ColumnRemovalOperation.reconstruct(project, new JSONObject(json)), json);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
package com.google.refine.tests.operations.column;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.refine.model.AbstractOperation;
|
||||
import com.google.refine.model.Project;
|
||||
import com.google.refine.operations.OperationRegistry;
|
||||
import com.google.refine.operations.column.ColumnMoveOperation;
|
||||
import com.google.refine.operations.column.ColumnRenameOperation;
|
||||
import com.google.refine.tests.RefineTest;
|
||||
import com.google.refine.tests.util.TestUtils;
|
||||
@ -19,11 +22,12 @@ public class ColumnRenameOperationTests extends RefineTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeColumnRenameOperation() {
|
||||
AbstractOperation op = new ColumnRenameOperation("old name", "new name");
|
||||
TestUtils.isSerializedTo(op, "{\"op\":\"core/column-rename\","
|
||||
public void serializeColumnRenameOperation() throws JSONException, Exception {
|
||||
String json = "{\"op\":\"core/column-rename\","
|
||||
+ "\"description\":\"Rename column old name to new name\","
|
||||
+ "\"oldColumnName\":\"old name\","
|
||||
+ "\"newColumnName\":\"new name\"}");
|
||||
+ "\"newColumnName\":\"new name\"}";
|
||||
Project project = mock(Project.class);
|
||||
TestUtils.isSerializedTo(ColumnRenameOperation.reconstruct(project, new JSONObject(json)), json);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.google.refine.tests.operations.column;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.google.refine.tests.operations.row;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user