Search in sources :

Example 1 with LongRunningProcessStub

use of com.google.refine.process.LongRunningProcessStub in project OpenRefine by OpenRefine.

the class ExtendDataOperationTests method testFetchCurrent.

/**
 * Test fetch only the best statements
 */
@Test
public void testFetchCurrent() throws Exception {
    DataExtensionConfig extension = DataExtensionConfig.reconstruct("{\"properties\":[{\"id\":\"P38\",\"name\":\"currency\",\"settings\":{\"rank\":\"best\"}}]}");
    mockHttpCall("{\"ids\":[\"Q863\",\"Q794\",\"Q17\",\"Q30\"],\"properties\":[{\"id\":\"P38\",\"settings\":{\"rank\":\"best\"}}]}", "{\"rows\":{" + "   \"Q794\": {\"P38\": [{\"name\": \"Iranian rial\", \"id\": \"Q188608\"}]}," + "   \"Q863\": {\"P38\": [{\"name\": \"Tajikistani somoni\", \"id\": \"Q199886\"}]}," + "   \"Q30\": {\"P38\": [{\"name\": \"United States dollar\", \"id\": \"Q4917\"}]}," + "   \"Q17\": {\"P38\": [{\"name\": \"Japanese yen\", \"id\": \"Q8146\"}]}" + "}, \"meta\": [" + "     {\"settings\": {\"rank\": \"best\"}, \"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();
        /*
             * Tajikistan has one "preferred" currency and one "normal" one (in terms of statement ranks). But thanks to
             * our setting in the extension configuration, we only fetch the current one, so the one just after it is
             * the one for the US (USD).
             */
        Assert.assertTrue("Tajikistani somoni".equals(project.rows.get(2).getCellValue(1)));
        Assert.assertTrue("United States dollar".equals(project.rows.get(3).getCellValue(1)));
        // Make sure all the values are reconciled
        Assert.assertTrue(project.columnModel.getColumnByName("currency").getReconStats().matchedTopics == 4);
    }
}
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 2 with LongRunningProcessStub

use of com.google.refine.process.LongRunningProcessStub in project OpenRefine by OpenRefine.

the class ExtendDataOperationTests method testFetchRecord.

/**
 * Test fetch records (multiple values per reconciled cell)
 */
@Test
public void testFetchRecord() throws Exception {
    DataExtensionConfig extension = DataExtensionConfig.reconstruct("{\"properties\":[{\"id\":\"P38\",\"name\":\"currency\",\"settings\":{\"rank\":\"any\"}}]}");
    mockHttpCall("{\"ids\":[\"Q863\",\"Q794\",\"Q17\",\"Q30\"],\"properties\":[{\"id\":\"P38\",\"settings\":{\"rank\":\"any\"}}]}", "{\"rows\": {" + "   \"Q794\": {\"P38\": [{\"name\": \"Iranian rial\", \"id\": \"Q188608\"}]}," + "   \"Q863\": {\"P38\": [{\"name\": \"Tajikistani somoni\", \"id\": \"Q199886\"}, {\"name\": \"Tajikistani ruble\", \"id\": \"Q2423956\"}]}," + "   \"Q30\": {\"P38\": [{\"name\": \"United States dollar\", \"id\": \"Q4917\"}]}," + "   \"Q17\": {\"P38\": [{\"name\": \"Japanese yen\", \"id\": \"Q8146\"}]}" + "}," + "\"meta\": [" + "    {\"settings\": {\"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();
        /*
             * Tajikistan has one "preferred" currency and one "normal" one (in terms of statement ranks). The second
             * currency is fetched as well, which creates a record (the cell to the left of it is left blank).
             */
        Assert.assertTrue("Tajikistani somoni".equals(project.rows.get(2).getCellValue(1)), "Bad currency name for Tajikistan");
        Assert.assertTrue("Tajikistani ruble".equals(project.rows.get(3).getCellValue(1)), "Bad currency name for Tajikistan");
        Assert.assertTrue(null == project.rows.get(3).getCellValue(0));
        // Make sure all the values are reconciled
        Assert.assertTrue(project.columnModel.getColumnByName("currency").getReconStats().matchedTopics == 5);
    }
}
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 3 with LongRunningProcessStub

use of com.google.refine.process.LongRunningProcessStub 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 4 with LongRunningProcessStub

use of com.google.refine.process.LongRunningProcessStub 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

RefineTest (com.google.refine.RefineTest)4 DataExtensionConfig (com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtensionConfig)4 EngineDependentOperation (com.google.refine.operations.EngineDependentOperation)4 LongRunningProcessStub (com.google.refine.process.LongRunningProcessStub)4 MockWebServer (okhttp3.mockwebserver.MockWebServer)4 BeforeTest (org.testng.annotations.BeforeTest)4 Test (org.testng.annotations.Test)4