Start serialization tests

This commit is contained in:
Antonin Delpeuch 2018-08-08 14:38:38 +01:00
parent d9bff34411
commit c6d2b003b1
5 changed files with 108 additions and 6 deletions

View File

@ -0,0 +1,18 @@
package com.google.refine.tests.model;
import org.testng.annotations.Test;
import com.google.refine.model.ReconCandidate;
import com.google.refine.tests.util.TestUtils;
public class ReconCandidateTests {
@Test
public void serializeReconCandidate() throws Exception {
String json = "{\"id\":\"Q49213\","
+ "\"name\":\"University of Texas at Austin\","
+ "\"score\":100,"
+ "\"types\":[\"Q875538\",\"Q15936437\",\"Q20971972\",\"Q23002039\"]}";
ReconCandidate rc = ReconCandidate.loadStreaming(json);
TestUtils.isSerializedTo(rc, json);
}
}

View File

@ -0,0 +1,15 @@
package com.google.refine.tests.model;
import org.testng.annotations.Test;
import com.google.refine.model.ReconStats;
import com.google.refine.tests.util.TestUtils;
public class ReconStatsTests {
@Test
public void serializeReconStats() {
ReconStats rs = new ReconStats(3, 1, 2);
TestUtils.isSerializedTo(rs,"{\"nonBlanks\":3,\"newTopics\":1,\"matchedTopics\":2}");
}
}

View File

@ -0,0 +1,56 @@
package com.google.refine.tests.model;
import java.util.Properties;
import org.testng.annotations.Test;
import com.google.refine.model.Recon;
import com.google.refine.tests.util.TestUtils;
public class ReconTests {
@Test
public void serializeRecon() throws Exception {
Properties options = new Properties();
options.put("mode", "save");
String fullJson = "{\"id\":1533651559492945033,"
+ "\"judgmentHistoryEntry\":1533651616890,"
+ "\"service\":\"https://tools.wmflabs.org/openrefine-wikidata/en/api\","
+ "\"identifierSpace\":\"http://www.wikidata.org/entity/\","
+ "\"schemaSpace\":\"http://www.wikidata.org/prop/direct/\","
+ "\"j\":\"matched\","
+ "\"m\":{"
+ " \"id\":\"Q2892284\","
+ " \"name\":\"Baylor College of Medicine\","
+ " \"score\":98.57142857142858,"
+ " \"types\":[\"Q16917\",\"Q23002054\",\"Q494230\"]"
+ "},"
+ "\"c\":["
+ " {\"id\":\"Q2892284\",\"name\":\"Baylor College of Medicine\",\"score\":98.57142857142858,\"types\":[\"Q16917\",\"Q23002054\",\"Q494230\"]},"
+ " {\"id\":\"Q16165943\",\"name\":\"Baylor College of Medicine Academy at Ryan\",\"score\":82.14285714285715,\"types\":[\"Q149566\"]},"
+ " {\"id\":\"Q30284245\",\"name\":\"Baylor College of Medicine Children\\u2019s Foundation\",\"score\":48.57142857142858,\"types\":[\"Q163740\"]}"
+ "],"
+ "\"f\":[false,false,1,0.6666666666666666],"
+ "\"judgmentAction\":\"mass\","
+ "\"judgmentBatchSize\":1,"
+ "\"matchRank\":0}";
Recon r = Recon.loadStreaming(fullJson, null);
TestUtils.isSerializedTo(r, fullJson, options);
String shortJson = "{\"id\":1533651559492945033,"
+ "\"service\":\"https://tools.wmflabs.org/openrefine-wikidata/en/api\","
+ "\"identifierSpace\":\"http://www.wikidata.org/entity/\","
+ "\"schemaSpace\":\"http://www.wikidata.org/prop/direct/\","
+ "\"j\":\"matched\","
+ "\"m\":{"
+ " \"id\":\"Q2892284\","
+ " \"name\":\"Baylor College of Medicine\","
+ " \"score\":98.57142857142858,"
+ " \"types\":[\"Q16917\",\"Q23002054\",\"Q494230\"]"
+ "}}";
options.put("mode", "normal");
TestUtils.isSerializedTo(r, shortJson, options);
}
}

View File

@ -0,0 +1,17 @@
package com.google.refine.tests.model;
import org.json.JSONException;
import org.json.JSONObject;
import org.testng.annotations.Test;
import com.google.refine.model.ReconType;
import com.google.refine.tests.util.TestUtils;
public class ReconTypeTest {
@Test
public void serializeReconType() throws JSONException, Exception {
String json = "{\"id\":\"Q7540126\",\"name\":\"headquarters\"}";
ReconType rt = ReconType.load(new JSONObject(json));
TestUtils.isSerializedTo(rt, json);
}
}

View File

@ -50,12 +50,8 @@ public class TestUtils {
JsonNode jsonA = mapper.readValue(expected, JsonNode.class); JsonNode jsonA = mapper.readValue(expected, JsonNode.class);
JsonNode jsonB = mapper.readValue(actual, JsonNode.class); JsonNode jsonB = mapper.readValue(actual, JsonNode.class);
assertEquals(jsonA, jsonB); assertEquals(jsonA, jsonB);
} catch(JsonMappingException e) { } catch(Exception e) {
fail(e.getMessage()); fail("\""+expected+"\" and \""+actual+"\" are not equal as JSON strings.");
} catch (JsonParseException e) {
fail(e.getMessage());
} catch (IOException e) {
fail(e.getMessage());
} }
} }