More JSON tests for operations

This commit is contained in:
Antonin Delpeuch 2018-08-12 15:48:52 +01:00
parent b4bcf7a1b6
commit 73171755f3
11 changed files with 358 additions and 2 deletions

View File

@ -0,0 +1,34 @@
package com.google.refine.tests.operations.column;
import static org.mockito.Mockito.mock;
import org.json.JSONException;
import org.json.JSONObject;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import com.google.refine.model.Project;
import com.google.refine.operations.OperationRegistry;
import com.google.refine.operations.column.ColumnAdditionOperation;
import com.google.refine.tests.RefineTest;
import com.google.refine.tests.util.TestUtils;
public class ColumnAdditionOperationTests extends RefineTest {
@BeforeSuite
public void registerOperation() {
OperationRegistry.registerOperation(getCoreModule(), "column-addition", ColumnAdditionOperation.class);
}
@Test
public void serializeColumnAdditionOperation() throws JSONException, Exception {
String json = "{"
+ " \"op\":\"core/column-addition\","
+ " \"description\":\"Create column organization_json at index 3 based on column employments using expression grel:value.parseJson()[\\\"employment-summary\\\"].join('###')\",\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]},\"newColumnName\":\"organization_json\",\"columnInsertIndex\":3,\"baseColumnName\":\"employments\","
+ " \"expression\":\"grel:value.parseJson()[\\\"employment-summary\\\"].join('###')\","
+ " \"onError\":\"set-to-blank\""
+ "}";
Project project = mock(Project.class);
TestUtils.isSerializedTo(ColumnAdditionOperation.reconstruct(project, new JSONObject(json)), json);
}
}

View File

@ -0,0 +1,42 @@
package com.google.refine.tests.operations.column;
import static org.mockito.Mockito.mock;
import org.json.JSONException;
import org.json.JSONObject;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import com.google.refine.model.Project;
import com.google.refine.operations.OperationRegistry;
import com.google.refine.operations.column.ColumnSplitOperation;
import com.google.refine.tests.RefineTest;
import com.google.refine.tests.util.TestUtils;
public class ColumnSplitOperationTests extends RefineTest {
@BeforeSuite
public void registerOperation() {
OperationRegistry.registerOperation(getCoreModule(), "column-split", ColumnSplitOperation.class);
}
@Test
public void serializeColumnSplitOperation() throws JSONException, Exception {
String json = "{\n" +
" \"op\": \"core/column-split\",\n" +
" \"description\": \"Split column ea by separator\",\n" +
" \"engineConfig\": {\n" +
" \"mode\": \"row-based\",\n" +
" \"facets\": []\n" +
" },\n" +
" \"columnName\": \"ea\",\n" +
" \"guessCellType\": true,\n" +
" \"removeOriginalColumn\": true,\n" +
" \"mode\": \"separator\",\n" +
" \"separator\": \"e\",\n" +
" \"regex\": false,\n" +
" \"maxColumns\": 0\n" +
" }";
Project project = mock(Project.class);
TestUtils.isSerializedTo(ColumnSplitOperation.reconstruct(project, new JSONObject(json)), json);
}
}

View File

@ -0,0 +1,30 @@
package com.google.refine.tests.operations.recon;
import static org.mockito.Mockito.mock;
import org.json.JSONObject;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import com.google.refine.model.Project;
import com.google.refine.operations.OperationRegistry;
import com.google.refine.operations.recon.ReconClearSimilarCellsOperation;
import com.google.refine.tests.RefineTest;
import com.google.refine.tests.util.TestUtils;
public class ReconClearSimilarCellsOperationTests extends RefineTest {
@BeforeSuite
public void registerOperation() {
OperationRegistry.registerOperation(getCoreModule(), "recon-clear-similar-cells", ReconClearSimilarCellsOperation.class);
}
@Test
public void serializeReconClearSimilarCellsOperation() throws Exception {
String json = "{\"op\":\"core/recon-clear-similar-cells\","
+ "\"description\":\"Clear recon data for cells containing \\\"some value\\\" in column my column\","
+ "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]},"
+ "\"columnName\":\"my column\","
+ "\"similarValue\":\"some value\"}";
Project project = mock(Project.class);
TestUtils.isSerializedTo(ReconClearSimilarCellsOperation.reconstruct(project, new JSONObject(json)), json);
}
}

View File

@ -0,0 +1,32 @@
package com.google.refine.tests.operations.recon;
import static org.mockito.Mockito.mock;
import org.json.JSONObject;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import com.google.refine.model.Project;
import com.google.refine.operations.OperationRegistry;
import com.google.refine.operations.recon.ReconCopyAcrossColumnsOperation;
import com.google.refine.tests.RefineTest;
import com.google.refine.tests.util.TestUtils;
public class ReconCopyAcrossColumnsOperationTests extends RefineTest {
@BeforeSuite
public void registerOperation() {
OperationRegistry.registerOperation(getCoreModule(), "recon-copy-across-columns", ReconCopyAcrossColumnsOperation.class);
}
@Test
public void serializeReconCopyAcrossColumnsOperation() throws Exception {
String json = "{\"op\":\"core/recon-copy-across-columns\","
+ "\"description\":\"Copy recon judgments from column source column to firstsecond\","
+ "\"engineConfig\":{\"mode\":\"row-based\"},"
+ "\"fromColumnName\":\"source column\","
+ "\"toColumnNames\":[\"first\",\"second\"],"
+ "\"judgments\":[\"matched\",\"new\"],"
+ "\"applyToJudgedCells\":true}";
Project project = mock(Project.class);
TestUtils.isSerializedTo(ReconCopyAcrossColumnsOperation.reconstruct(project, new JSONObject(json)), json);
}
}

View File

@ -0,0 +1,35 @@
package com.google.refine.tests.operations.recon;
import static org.mockito.Mockito.mock;
import org.json.JSONObject;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import com.google.refine.model.Project;
import com.google.refine.operations.OperationRegistry;
import com.google.refine.operations.recon.ReconDiscardJudgmentsOperation;
import com.google.refine.tests.RefineTest;
import com.google.refine.tests.util.TestUtils;
public class ReconDiscardJudgmentsOperationTests extends RefineTest {
@BeforeSuite
public void registerOperation() {
OperationRegistry.registerOperation(getCoreModule(), "recon-discard-judgments", ReconDiscardJudgmentsOperation.class);
}
@Test
public void serializeReconDiscardJudgmentsOperation() throws Exception {
String json = "{\n" +
" \"op\": \"core/recon-discard-judgments\",\n" +
" \"description\": \"Discard recon judgments and clear recon data for cells in column researcher\",\n" +
" \"engineConfig\": {\n" +
" \"mode\": \"record-based\",\n" +
" \"facets\": []\n" +
" },\n" +
" \"columnName\": \"researcher\",\n" +
" \"clearData\": true\n" +
" }";
Project project = mock(Project.class);
TestUtils.isSerializedTo(ReconDiscardJudgmentsOperation.reconstruct(project, new JSONObject(json)), json);
}
}

View File

@ -0,0 +1,33 @@
package com.google.refine.tests.operations.recon;
import static org.mockito.Mockito.mock;
import org.json.JSONObject;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import com.google.refine.model.Project;
import com.google.refine.operations.OperationRegistry;
import com.google.refine.operations.recon.ReconJudgeSimilarCellsOperation;
import com.google.refine.tests.RefineTest;
import com.google.refine.tests.util.TestUtils;
public class ReconJudgeSimilarCellsOperationTests extends RefineTest {
@BeforeSuite
public void registerOperation() {
OperationRegistry.registerOperation(getCoreModule(), "recon-judge-similar-cells", ReconJudgeSimilarCellsOperation.class);
}
@Test
public void serializeReconJudgeSimilarCellsOperation() throws Exception {
String json = "{\"op\":\"core/recon-judge-similar-cells\","
+ "\"description\":\"Match item Unicef Indonesia (Q7884717) for cells containing \\\"UNICEF Indonesia\\\" in column organization_name\","
+ "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]},"
+ "\"columnName\":\"organization_name\","
+ "\"similarValue\":\"UNICEF Indonesia\","
+ "\"judgment\":\"matched\","
+ "\"match\":{\"id\":\"Q7884717\",\"name\":\"Unicef Indonesia\",\"score\":71.42857142857143,\"types\":[\"Q43229\"]},"
+ "\"shareNewTopics\":false}";
Project project = mock(Project.class);
TestUtils.isSerializedTo(ReconJudgeSimilarCellsOperation.reconstruct(project, new JSONObject(json)), json);
}
}

View File

@ -8,7 +8,6 @@ import java.util.Properties;
import org.json.JSONObject;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -20,7 +19,6 @@ import com.google.refine.model.Recon;
import com.google.refine.model.recon.ReconConfig;
import com.google.refine.model.recon.StandardReconConfig;
import com.google.refine.operations.OperationRegistry;
import com.google.refine.operations.column.ColumnMoveOperation;
import com.google.refine.operations.recon.ReconJudgeSimilarCellsOperation;
import com.google.refine.process.Process;
import com.google.refine.tests.RefineTest;

View File

@ -0,0 +1,32 @@
package com.google.refine.tests.operations.recon;
import static org.mockito.Mockito.mock;
import org.json.JSONObject;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import com.google.refine.model.Project;
import com.google.refine.operations.OperationRegistry;
import com.google.refine.operations.recon.ReconMarkNewTopicsOperation;
import com.google.refine.tests.RefineTest;
import com.google.refine.tests.util.TestUtils;
public class ReconMarkNewTopicsOperationTests extends RefineTest {
@BeforeSuite
public void registerOperation() {
OperationRegistry.registerOperation(getCoreModule(), "recon-mark-new-topics", ReconMarkNewTopicsOperation.class);
}
@Test
public void serializeReconMarkNewTopicsOperation() throws Exception {
String json = "{"
+ "\"op\":\"core/recon-mark-new-topics\","
+ "\"engineConfig\":{\"mode\":\"row-based\"},"
+ "\"columnName\":\"my column\","
+ "\"shareNewTopics\":true,"
+ "\"description\":\"Mark to create new items for cells in column my column, one item for each group of similar cells\""
+ "}";
Project project = mock(Project.class);
TestUtils.isSerializedTo(ReconMarkNewTopicsOperation.reconstruct(project, new JSONObject(json)), json);
}
}

View File

@ -0,0 +1,34 @@
package com.google.refine.tests.operations.recon;
import static org.mockito.Mockito.mock;
import org.json.JSONObject;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import com.google.refine.model.Project;
import com.google.refine.operations.OperationRegistry;
import com.google.refine.operations.recon.ReconMatchBestCandidatesOperation;
import com.google.refine.tests.RefineTest;
import com.google.refine.tests.util.TestUtils;
public class ReconMatchBestCandidatesOperationTests extends RefineTest {
@BeforeSuite
public void registerOperation() {
OperationRegistry.registerOperation(getCoreModule(), "recon-match-best-candidates", ReconMatchBestCandidatesOperation.class);
}
@Test
public void serializeReconMatchBestCandidatesOperation() throws Exception {
String json = "{"
+ "\"op\":\"core/recon-match-best-candidates\","
+ "\"description\":\"Match each cell to its best recon candidate in column organization_name\","
+ "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":["
+ " {\"selectNumeric\":true,\"expression\":\"cell.recon.best.score\",\"selectBlank\":false,\"selectNonNumeric\":true,\"selectError\":true,\"name\":\"organization_name: best candidate's score\",\"from\":13,\"to\":101,\"type\":\"range\",\"columnName\":\"organization_name\"},"
+ " {\"selectNonTime\":true,\"expression\":\"grel:toDate(value)\",\"selectBlank\":true,\"selectError\":true,\"selectTime\":true,\"name\":\"start_year\",\"from\":410242968000,\"to\":1262309184000,\"type\":\"timerange\",\"columnName\":\"start_year\"}"
+ "]},"
+ "\"columnName\":\"organization_name\""
+ "}";
Project project = mock(Project.class);
TestUtils.isSerializedTo(ReconMatchBestCandidatesOperation.reconstruct(project, new JSONObject(json)), json);
}
}

View File

@ -0,0 +1,43 @@
package com.google.refine.tests.operations.recon;
import static org.mockito.Mockito.mock;
import org.json.JSONObject;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import com.google.refine.model.Project;
import com.google.refine.operations.OperationRegistry;
import com.google.refine.operations.recon.ReconMatchSpecificTopicOperation;
import com.google.refine.tests.RefineTest;
import com.google.refine.tests.util.TestUtils;
public class ReconMatchSpecificTopicOperationTests extends RefineTest {
@BeforeSuite
public void registerOperation() {
OperationRegistry.registerOperation(getCoreModule(), "recon-match-specific-topic-to-cells", ReconMatchSpecificTopicOperation.class);
}
@Test
public void serializeReconMatchSpecificTopicOperation() throws Exception {
String json = "{\n" +
" \"op\": \"core/recon-match-specific-topic-to-cells\",\n" +
" \"description\": \"Match specific item Gangnam (Q489941) to cells in column researcher\",\n" +
" \"engineConfig\": {\n" +
" \"mode\": \"record-based\",\n" +
" \"facets\": []\n" +
" },\n" +
" \"columnName\": \"researcher\",\n" +
" \"match\": {\n" +
" \"id\": \"Q489941\",\n" +
" \"name\": \"Gangnam\",\n" +
" \"types\": [\n" +
" \"Q5\"\n" +
" ]\n" +
" },\n" +
" \"identifierSpace\": \"http://www.wikidata.org/entity/\",\n" +
" \"schemaSpace\": \"http://www.wikidata.org/prop/direct/\"\n" +
" }";
Project project = mock(Project.class);
TestUtils.isSerializedTo(ReconMatchSpecificTopicOperation.reconstruct(project, new JSONObject(json)), json);
}
}

View File

@ -0,0 +1,43 @@
package com.google.refine.tests.operations.recon;
import static org.mockito.Mockito.mock;
import org.json.JSONException;
import org.json.JSONObject;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import com.google.refine.model.Project;
import com.google.refine.operations.OperationRegistry;
import com.google.refine.operations.recon.ReconOperation;
import com.google.refine.tests.RefineTest;
import com.google.refine.tests.util.TestUtils;
public class ReconOperationTests extends RefineTest {
@BeforeSuite
public void registerOperation() {
OperationRegistry.registerOperation(getCoreModule(), "recon", ReconOperation.class);
}
@Test
public void serializeReconOperation() throws JSONException, Exception {
String json = "{"
+ "\"op\":\"core/recon\","
+ "\"description\":\"Reconcile cells in column researcher to type Q5\","
+ "\"columnName\":\"researcher\","
+ "\"config\":{"
+ " \"mode\":\"standard-service\","
+ " \"service\":\"https://tools.wmflabs.org/openrefine-wikidata/en/api\","
+ " \"identifierSpace\":\"http://www.wikidata.org/entity/\","
+ " \"schemaSpace\":\"http://www.wikidata.org/prop/direct/\","
+ " \"type\":{\"id\":\"Q5\",\"name\":\"human\"},"
+ " \"autoMatch\":true,"
+ " \"columnDetails\":[],"
+ " \"limit\":0"
+ "},"
+ "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]}}";
Project project = mock(Project.class);
TestUtils.isSerializedTo(ReconOperation.reconstruct(project, new JSONObject(json)), json);
}
}