Cleanup StandardReconConfigTests

This commit is contained in:
Antonin Delpeuch 2018-08-08 11:46:05 +01:00
parent b12b29b393
commit 2b57350adf

View File

@ -2,6 +2,7 @@ package com.google.refine.tests.model.recon;
import java.util.ArrayList; import java.util.ArrayList;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testng.Assert; import org.testng.Assert;
@ -11,8 +12,9 @@ import org.testng.annotations.Test;
import com.google.refine.model.recon.ReconConfig; import com.google.refine.model.recon.ReconConfig;
import com.google.refine.model.recon.StandardReconConfig; import com.google.refine.model.recon.StandardReconConfig;
import com.google.refine.tests.RefineTest; import com.google.refine.tests.RefineTest;
import com.google.refine.tests.util.TestUtils;
public class ReconTests extends RefineTest { public class StandardReconConfigTests extends RefineTest {
@Override @Override
@BeforeTest @BeforeTest
@ -20,8 +22,8 @@ public class ReconTests extends RefineTest {
logger = LoggerFactory.getLogger(this.getClass()); logger = LoggerFactory.getLogger(this.getClass());
} }
private class StandardReconConfigTest extends StandardReconConfig { private class StandardReconConfigStub extends StandardReconConfig {
public StandardReconConfigTest() { public StandardReconConfigStub() {
super("", "", "", "", "", false, new ArrayList<ColumnDetail>()); super("", "", "", "", "", false, new ArrayList<ColumnDetail>());
} }
@ -32,30 +34,24 @@ public class ReconTests extends RefineTest {
@Test @Test
public void wordDistance() { public void wordDistance() {
StandardReconConfigTest t = new StandardReconConfigTest(); StandardReconConfigStub t = new StandardReconConfigStub();
double r = t.wordDistanceTest("Foo", "Foo bar"); double r = t.wordDistanceTest("Foo", "Foo bar");
Assert.assertEquals(r,0.5); Assert.assertEquals(0.5, r);
} }
@Test @Test
public void wordDistanceOnlyStopwords() { public void wordDistanceOnlyStopwords() {
StandardReconConfigTest t = new StandardReconConfigTest(); StandardReconConfigStub t = new StandardReconConfigStub();
double r = t.wordDistanceTest("On and On", "On and On and On"); double r = t.wordDistanceTest("On and On", "On and On and On");
Assert.assertTrue(!Double.isInfinite(r)); Assert.assertTrue(!Double.isInfinite(r));
Assert.assertTrue(!Double.isNaN(r)); Assert.assertTrue(!Double.isNaN(r));
} }
/**
* Regression for issue #1517:
* JSON deserialization exception due to the upgrade of org.json library in data package PR
* @throws Exception
*/
@Test @Test
public void limitJSONKeyTest() throws Exception { public void serializeStandardReconConfig() throws Exception {
JSONObject obj = new JSONObject( String json = " {\n" +
" {\n" +
" \"mode\": \"standard-service\",\n" + " \"mode\": \"standard-service\",\n" +
" \"service\": \"https://tools.wmflabs.org/openrefine-wikidata/en/api\",\n" + " \"service\": \"https://tools.wmflabs.org/openrefine-wikidata/en/api\",\n" +
" \"identifierSpace\": \"http://www.wikidata.org/entity/\",\n" + " \"identifierSpace\": \"http://www.wikidata.org/entity/\",\n" +
@ -65,13 +61,21 @@ public class ReconTests extends RefineTest {
" \"name\": \"scientific article\"\n" + " \"name\": \"scientific article\"\n" +
" },\n" + " },\n" +
" \"autoMatch\": true,\n" + " \"autoMatch\": true,\n" +
" \"columnDetails\": [],\n" + " \"columnDetails\": [\n" +
" {\n" +
" \"column\": \"organization_country\",\n" +
" \"propertyName\": \"SPARQL: P17/P297\",\n" +
" \"propertyID\": \"P17/P297\"\n" +
" },\n" +
" {\n" +
" \"column\": \"organization_id\",\n" +
" \"propertyName\": \"SPARQL: P3500|P2427\",\n" +
" \"propertyID\": \"P3500|P2427\"\n" +
" }\n" +
" ],\n" +
" \"limit\": 0\n" + " \"limit\": 0\n" +
" }"); " }";
ReconConfig config = StandardReconConfig.reconstruct(new JSONObject(json));
ReconConfig config = StandardReconConfig.reconstruct(obj); TestUtils.isSerializedTo(config, json);
// Assert the object is created
Assert.assertTrue(config != null);
} }
} }