Migrate recent PRs to Jackson

This commit is contained in:
Antonin Delpeuch 2018-11-22 10:13:42 +00:00
parent f26d62dc4d
commit f667a78657
6 changed files with 10 additions and 13 deletions

View File

@ -4,12 +4,12 @@ import java.io.IOException;
import java.io.Writer;
import java.util.Properties;
import org.json.JSONWriter;
import org.openrefine.wikidata.schema.WikibaseSchema;
import com.google.refine.browsing.Engine;
import com.google.refine.exporters.WriterExporter;
import com.google.refine.model.Project;
import com.google.refine.util.ParsingUtilities;
public class SchemaExporter implements WriterExporter {
@ -24,8 +24,7 @@ public class SchemaExporter implements WriterExporter {
if (schema == null) {
schema = new WikibaseSchema();
}
JSONWriter jsonWriter = new JSONWriter(writer);
schema.write(jsonWriter, new Properties());
ParsingUtilities.mapper.writeValue(writer, schema);
}
}

View File

@ -1,7 +1,5 @@
package org.openrefine.wikidata.exporters;
import static org.openrefine.wikidata.testing.JacksonSerializationTest.assertJsonEquals;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Properties;
@ -11,6 +9,7 @@ import org.testng.annotations.Test;
import com.google.refine.browsing.Engine;
import com.google.refine.model.Project;
import com.google.refine.tests.RefineTest;
import com.google.refine.tests.util.TestUtils;
public class SchemaExporterTest extends RefineTest {
@ -24,7 +23,7 @@ public class SchemaExporterTest extends RefineTest {
StringWriter writer = new StringWriter();
Properties properties = new Properties();
exporter.export(project, properties, engine, writer);
assertJsonEquals("{\"itemDocuments\":[]}", writer.toString());
TestUtils.assertEqualAsJson("{\"itemDocuments\":[]}", writer.toString());
}
}

View File

@ -95,15 +95,14 @@ public class ListFacetTests extends RefineTest {
}
@Test
public void testSelectedEmptyChoice() {
public void testSelectedEmptyChoice() throws IOException {
Project project = createCSVProject("Column A\n" +
"a\n" +
"c\n" +
"e");
Engine engine = new Engine(project);
ListFacetConfig facetConfig = new ListFacetConfig();
facetConfig.initializeFromJSON(new JSONObject(jsonConfig));
ListFacetConfig facetConfig = ParsingUtilities.mapper.readValue(jsonConfig, ListFacetConfig.class);
Facet facet = facetConfig.apply(project);
facet.computeChoices(project, engine.getAllFilteredRows());
TestUtils.isSerializedTo(facet, selectedEmptyChoiceFacet);

View File

@ -101,7 +101,7 @@ public class BlankDownTests extends RefineTest {
project.columnModel.update();
AbstractOperation op = new BlankDownOperation(
EngineConfig.reconstruct(new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}")),
EngineConfig.reconstruct("{\"mode\":\"record-based\",\"facets\":[]}"),
"second");
Process process = op.createProcess(project, new Properties());
process.performImmediate();

View File

@ -117,7 +117,7 @@ public class FillDownTests extends RefineTest {
project.columnModel.update();
AbstractOperation op = new FillDownOperation(
EngineConfig.reconstruct(new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}")),
EngineConfig.reconstruct("{\"mode\":\"record-based\",\"facets\":[]}"),
"second");
Process process = op.createProcess(project, new Properties());
process.performImmediate();

View File

@ -273,8 +273,8 @@ public class ExtendDataOperationTests extends RefineTest {
Assert.assertFalse(process.isRunning(), "The data extension process took longer than expected.");
// Test to be updated as countries change currencies!
Assert.assertTrue(Math.round((float)project.rows.get(2).getCellValue(1)) == 2, "Incorrect number of currencies returned for Tajikistan.");
Assert.assertTrue(Math.round((float)project.rows.get(3).getCellValue(1)) == 1, "Incorrect number of currencies returned for United States.");
Assert.assertTrue(Math.round((double)project.rows.get(2).getCellValue(1)) == 2, "Incorrect number of currencies returned for Tajikistan.");
Assert.assertTrue(Math.round((double)project.rows.get(3).getCellValue(1)) == 1, "Incorrect number of currencies returned for United States.");
// Make sure we did not create any recon stats for that column (no reconciled value)
Assert.assertTrue(project.columnModel.getColumnByName("currency").getReconStats() == null);