Search in sources :

Example 6 with DataExtensionConfig

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);
    }
}
Also used : LongRunningProcessStub(com.google.refine.process.LongRunningProcessStub) EngineDependentOperation(com.google.refine.operations.EngineDependentOperation) MockWebServer(okhttp3.mockwebserver.MockWebServer) DataExtensionConfig(com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtensionConfig) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 7 with DataExtensionConfig

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);
    }
}
Also used : LongRunningProcessStub(com.google.refine.process.LongRunningProcessStub) EngineDependentOperation(com.google.refine.operations.EngineDependentOperation) MockWebServer(okhttp3.mockwebserver.MockWebServer) DataExtensionConfig(com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtensionConfig) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

DataExtensionConfig (com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtensionConfig)7 RefineTest (com.google.refine.RefineTest)5 BeforeTest (org.testng.annotations.BeforeTest)5 Test (org.testng.annotations.Test)5 EngineDependentOperation (com.google.refine.operations.EngineDependentOperation)4 LongRunningProcessStub (com.google.refine.process.LongRunningProcessStub)4 MockWebServer (okhttp3.mockwebserver.MockWebServer)4 Cell (com.google.refine.model.Cell)1 Column (com.google.refine.model.Column)1 Project (com.google.refine.model.Project)1 ReconCandidate (com.google.refine.model.ReconCandidate)1 Row (com.google.refine.model.Row)1 ReconConfig (com.google.refine.model.recon.ReconConfig)1 ReconciledDataExtensionJob (com.google.refine.model.recon.ReconciledDataExtensionJob)1 DataExtension (com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtension)1 StandardReconConfig (com.google.refine.model.recon.StandardReconConfig)1 ExtendDataOperation (com.google.refine.operations.recon.ExtendDataOperation)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1