use of com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtensionConfig in project OpenRefine by OpenRefine.
the class ExtendDataOperationTests method testFetchCounts.
/**
* Test to fetch counts of values
*/
@Test
public void testFetchCounts() throws Exception {
DataExtensionConfig extension = DataExtensionConfig.reconstruct("{\"properties\":[{\"id\":\"P38\",\"name\":\"currency\",\"settings\":{\"count\":\"on\",\"rank\":\"any\"}}]}");
mockHttpCall("{\"ids\":[\"Q863\",\"Q794\",\"Q17\",\"Q30\"],\"properties\":[{\"id\":\"P38\",\"settings\":{\"count\":\"on\",\"rank\":\"any\"}}]}", "{" + "\"rows\": {" + " \"Q794\": {\"P38\": [{\"float\": 1}]}," + " \"Q863\": {\"P38\": [{\"float\": 2}]}," + " \"Q30\": {\"P38\": [{\"float\": 1}]}," + " \"Q17\": {\"P38\": [{\"float\": 1}]}" + "}," + "\"meta\": [" + " {\"settings\": {\"count\": \"on\", \"rank\": \"any\"}, \"name\": \"currency\", \"id\": \"P38\"}" + "]}");
try (MockWebServer server = new MockWebServer()) {
server.start();
server.setDispatcher(dispatcher);
EngineDependentOperation op = new ExtendDataOperation(engine_config, "country", server.url("/reconcile").url().toString(), RECON_IDENTIFIER_SPACE, RECON_SCHEMA_SPACE, extension, 1);
LongRunningProcessStub process = new LongRunningProcessStub(op.createProcess(project, options));
process.run();
// Test to be updated as countries change currencies!
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);
}
}
use of com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtensionConfig in project OpenRefine by OpenRefine.
the class ExtendDataOperationTests method testFetchStrings.
@Test
public void testFetchStrings() throws Exception {
DataExtensionConfig extension = DataExtensionConfig.reconstruct("{\"properties\":[{\"id\":\"P297\",\"name\":\"ISO 3166-1 alpha-2 code\"}]}");
try (MockWebServer server = new MockWebServer()) {
server.start();
server.setDispatcher(dispatcher);
mockHttpCall("{\"ids\":[\"Q863\",\"Q794\",\"Q17\",\"Q30\"],\"properties\":[{\"id\":\"P297\"}]}", "{" + "\"rows\": {" + " \"Q794\": {\"P297\": [{\"str\": \"IR\"}]}," + " \"Q863\": {\"P297\": []}," + " \"Q30\": {\"P297\": [{\"str\": \"US\"}]}," + " \"Q17\": {\"P297\": [{\"str\": \"JP\"}]}" + "}," + "\"meta\": [" + " {\"name\": \"ISO 3166-1 alpha-2 code\", \"id\": \"P297\"}" + "]}");
EngineDependentOperation op = new ExtendDataOperation(engine_config, "country", server.url("/reconcile").url().toString(), RECON_IDENTIFIER_SPACE, RECON_SCHEMA_SPACE, extension, 1);
LongRunningProcessStub process = new LongRunningProcessStub(op.createProcess(project, options));
process.run();
// Inspect rows
Assert.assertTrue("IR".equals(project.rows.get(0).getCellValue(1)), "Bad country code for Iran.");
Assert.assertTrue("JP".equals(project.rows.get(1).getCellValue(1)), "Bad country code for Japan.");
Assert.assertNull(project.rows.get(2).getCell(1), "Expected a null country code.");
Assert.assertTrue("US".equals(project.rows.get(3).getCellValue(1)), "Bad country code for United States.");
// Make sure we did not create any recon stats for that column (no reconciled value)
Assert.assertTrue(project.columnModel.getColumnByName("ISO 3166-1 alpha-2 code").getReconStats() == null);
}
}
Aggregations