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)
}
}
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\"}");
}
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();
}
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\"}");
}
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());
}
Aggregations