Search in sources :

Example 56 with Project

use of com.google.refine.model.Project in project OpenRefine by OpenRefine.

the class StandardReconConfigTests method reconNonJsonTest.

@Test
public void reconNonJsonTest() throws Exception {
    Project project = createCSVProject("title,director\n" + "mulholland drive,david lynch");
    String nonJsonResponse = "<!DOCTYPE html>\n" + "<html lang=\"en\">\n" + "  <head>\n" + "    <meta charset=\"utf-8\">\n" + "    <title>Error</title>\n" + "  </head>\n" + "  <body>\n" + "    You have reached an error page.\n" + "  </body>\n" + "</html>";
    try (MockWebServer server = new MockWebServer()) {
        server.start();
        HttpUrl url = server.url("/openrefine-wikidata/en/api");
        server.enqueue(new MockResponse().setBody(nonJsonResponse));
        server.enqueue(new MockResponse());
        String configJson = " {\n" + "        \"mode\": \"standard-service\",\n" + "        \"service\": \"" + url + "\",\n" + "        \"identifierSpace\": \"http://www.wikidata.org/entity/\",\n" + "        \"schemaSpace\": \"http://www.wikidata.org/prop/direct/\",\n" + "        \"type\": {\n" + "                \"id\": \"Q11424\",\n" + "                \"name\": \"film\"\n" + "        },\n" + "        \"autoMatch\": true,\n" + "        \"columnDetails\": [\n" + "           {\n" + "             \"column\": \"director\",\n" + "             \"propertyName\": \"Director\",\n" + "             \"propertyID\": \"P57\"\n" + "           }\n" + "        ]}";
        StandardReconConfig config = StandardReconConfig.reconstruct(configJson);
        ReconOperation op = new ReconOperation(EngineConfig.reconstruct(null), "director", config);
        Process process = op.createProcess(project, new Properties());
        ProcessManager pm = project.getProcessManager();
        process.startPerforming(pm);
        Assert.assertTrue(process.isRunning());
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            Assert.fail("Test interrupted");
        }
        Assert.assertFalse(process.isRunning());
        RecordedRequest request1 = server.takeRequest();
        assertNotNull(request1);
        // We won't have gotten a result, but we want to make sure things didn't die.
        Row row = project.rows.get(0);
        Cell cell = row.cells.get(1);
        assertNotNull(cell.value);
        assertNull(cell.recon);
    // the recon object is left null, so that it can be told apart from
    // empty recon objects (the service legitimally did not return any candidate)
    }
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Process(com.google.refine.process.Process) ReconOperation(com.google.refine.operations.recon.ReconOperation) Properties(java.util.Properties) HttpUrl(okhttp3.HttpUrl) Project(com.google.refine.model.Project) MockWebServer(okhttp3.mockwebserver.MockWebServer) Row(com.google.refine.model.Row) Cell(com.google.refine.model.Cell) ProcessManager(com.google.refine.process.ProcessManager) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 57 with Project

use of com.google.refine.model.Project in project OpenRefine by OpenRefine.

the class StandardReconConfigTests method formulateQueryTest.

@Test
public void formulateQueryTest() throws IOException {
    Project project = createCSVProject("title,director\n" + "mulholland drive,david lynch");
    String config = " {\n" + "        \"mode\": \"standard-service\",\n" + "        \"service\": \"https://tools.wmflabs.org/openrefine-wikidata/en/api\",\n" + "        \"identifierSpace\": \"http://www.wikidata.org/entity/\",\n" + "        \"schemaSpace\": \"http://www.wikidata.org/prop/direct/\",\n" + "        \"type\": {\n" + "                \"id\": \"Q1234\",\n" + "                \"name\": \"movie\"\n" + "        },\n" + "        \"autoMatch\": true,\n" + "        \"columnDetails\": [\n" + "           {\n" + "             \"column\": \"director\",\n" + "             \"propertyName\": \"Director\",\n" + "             \"propertyID\": \"P123\"\n" + "           }\n" + "        ]}";
    StandardReconConfig r = StandardReconConfig.reconstruct(config);
    Row row = project.rows.get(0);
    ReconJob job = r.createJob(project, 0, row, "title", row.getCell(0));
    TestUtils.assertEqualsAsJson(job.toString(), "{" + "\"query\":\"mulholland drive\"," + "\"type\":\"Q1234\"," + "\"properties\":[" + "     {\"pid\":\"P123\",\"v\":\"david lynch\"}" + "]," + "\"type_strict\":\"should\"}");
}
Also used : Project(com.google.refine.model.Project) Row(com.google.refine.model.Row) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 58 with Project

use of com.google.refine.model.Project in project OpenRefine by OpenRefine.

the class KeyValueColumnizeTests method SetUp.

@BeforeMethod
public void SetUp() throws IOException, ModelException {
    servlet = new RefineServletStub();
    File dir = TestUtils.createTempDirectory("openrefine-test-workspace-dir");
    FileProjectManager.initialize(dir);
    project = new Project();
    pm = new ProjectMetadata();
    pm.setName("KeyValueColumnize test");
    ProjectManager.singleton.registerProject(project, pm);
    options = mock(ObjectNode.class);
    OperationRegistry.registerOperation(getCoreModule(), "key-value-columnize", KeyValueColumnizeOperation.class);
    ImportingManager.initialize(servlet);
    job = ImportingManager.createJob();
    importer = new SeparatorBasedImporter();
}
Also used : Project(com.google.refine.model.Project) RefineServletStub(com.google.refine.RefineServletStub) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProjectMetadata(com.google.refine.ProjectMetadata) SeparatorBasedImporter(com.google.refine.importers.SeparatorBasedImporter) File(java.io.File) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 59 with Project

use of com.google.refine.model.Project in project OpenRefine by OpenRefine.

the class QuickHistoryEntryProcessTests method serializeQuickHistoryEntryProcess.

@Test
public void serializeQuickHistoryEntryProcess() {
    Project project = mock(Project.class);
    Process process = new QuickHistoryEntryProcessStub(project, "quick description");
    int hashCode = process.hashCode();
    TestUtils.isSerializedTo(process, "{" + "\"id\":" + hashCode + "," + "\"description\":" + "\"quick description\"," + "\"immediate\":true," + "\"status\":\"pending\"}");
}
Also used : Project(com.google.refine.model.Project) Test(org.testng.annotations.Test)

Example 60 with Project

use of com.google.refine.model.Project in project OpenRefine by OpenRefine.

the class QuickStatementsExporterTest method testSimpleProject.

@Test
public void testSimpleProject() throws IOException {
    Project project = this.createCSVProject(TestingData.inceptionWithNewCsv);
    TestingData.reconcileInceptionCells(project);
    String serialized = TestingData.jsonFromFile("schema/inception.json");
    WikibaseSchema schema = WikibaseSchema.reconstruct(serialized);
    project.overlayModels.put("wikibaseSchema", schema);
    Engine engine = new Engine(project);
    StringWriter writer = new StringWriter();
    Properties properties = new Properties();
    exporter.export(project, properties, engine, writer);
    assertEquals(TestingData.inceptionWithNewQS, writer.toString());
}
Also used : Project(com.google.refine.model.Project) StringWriter(java.io.StringWriter) WikibaseSchema(org.openrefine.wikidata.schema.WikibaseSchema) Properties(java.util.Properties) Engine(com.google.refine.browsing.Engine) Test(org.testng.annotations.Test) WikidataRefineTest(org.openrefine.wikidata.testing.WikidataRefineTest)

Aggregations

Project (com.google.refine.model.Project)146 Properties (java.util.Properties)46 IOException (java.io.IOException)40 Engine (com.google.refine.browsing.Engine)37 Test (org.testng.annotations.Test)37 ServletException (javax.servlet.ServletException)35 ProjectMetadata (com.google.refine.ProjectMetadata)33 BeforeMethod (org.testng.annotations.BeforeMethod)31 Cell (com.google.refine.model.Cell)29 Row (com.google.refine.model.Row)29 RefineTest (com.google.refine.RefineTest)25 Column (com.google.refine.model.Column)25 BeforeTest (org.testng.annotations.BeforeTest)18 Process (com.google.refine.process.Process)17 AbstractOperation (com.google.refine.model.AbstractOperation)14 StringWriter (java.io.StringWriter)13 RowVisitor (com.google.refine.browsing.RowVisitor)11 ArrayList (java.util.ArrayList)11 File (java.io.File)10 WrappedCell (com.google.refine.expr.WrappedCell)9