From fdf742b052d11fc839d9f0850534eb2aaa4367e5 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Thu, 12 Sep 2019 10:24:25 +0100 Subject: [PATCH] Unlink wikidata extension from RefineTest --- .../wikidata/commands/CommandTest.java | 5 +- .../editing/EditBatchProcessorTest.java | 7 +-- .../wikidata/editing/NewItemLibraryTest.java | 3 +- .../QuickStatementsExporterTest.java | 3 +- .../exporters/SchemaExporterTest.java | 3 +- .../wikidata/operations/OperationTest.java | 4 +- .../schema/ExpressionContextTest.java | 4 +- .../wikidata/schema/WbExpressionTest.java | 4 +- .../wikidata/schema/WikibaseSchemaTest.java | 4 +- .../wikidata/testing/WikidataRefineTest.java | 63 +++++++++++++++++++ .../src/com/google/refine/RefineTest.java | 2 +- 11 files changed, 84 insertions(+), 18 deletions(-) create mode 100644 extensions/wikidata/tests/src/org/openrefine/wikidata/testing/WikidataRefineTest.java diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/commands/CommandTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/commands/CommandTest.java index df0265ae8..b14644a4b 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/commands/CommandTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/commands/CommandTest.java @@ -34,14 +34,14 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.openrefine.wikidata.testing.TestingData; +import org.openrefine.wikidata.testing.WikidataRefineTest; import org.testng.Assert; import org.testng.annotations.BeforeMethod; -import com.google.refine.RefineTest; import com.google.refine.commands.Command; import com.google.refine.model.Project; -public abstract class CommandTest extends RefineTest { +public abstract class CommandTest extends WikidataRefineTest { protected Project project = null; protected HttpServletRequest request = null; @@ -49,6 +49,7 @@ public abstract class CommandTest extends RefineTest { protected StringWriter writer = null; protected Command command = null; + @BeforeMethod(alwaysRun = true) public void setUpProject() { diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/editing/EditBatchProcessorTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/editing/EditBatchProcessorTest.java index 5bcaf5a87..d6f4be0ef 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/editing/EditBatchProcessorTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/editing/EditBatchProcessorTest.java @@ -23,11 +23,11 @@ ******************************************************************************/ package org.openrefine.wikidata.editing; -import static org.testng.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.ArrayList; @@ -37,6 +37,7 @@ import java.util.Map; import java.util.stream.Collectors; import org.openrefine.wikidata.testing.TestingData; +import org.openrefine.wikidata.testing.WikidataRefineTest; import org.openrefine.wikidata.updates.ItemUpdate; import org.openrefine.wikidata.updates.ItemUpdateBuilder; import org.testng.annotations.BeforeMethod; @@ -51,9 +52,7 @@ import org.wikidata.wdtk.wikibaseapi.WikibaseDataEditor; import org.wikidata.wdtk.wikibaseapi.WikibaseDataFetcher; import org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException; -import com.google.refine.RefineTest; - -public class EditBatchProcessorTest extends RefineTest { +public class EditBatchProcessorTest extends WikidataRefineTest { private WikibaseDataFetcher fetcher = null; private WikibaseDataEditor editor = null; diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/editing/NewItemLibraryTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/editing/NewItemLibraryTest.java index 7cb9d8222..4774b038b 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/editing/NewItemLibraryTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/editing/NewItemLibraryTest.java @@ -30,6 +30,7 @@ import java.util.Collections; import org.openrefine.wikidata.testing.JacksonSerializationTest; import org.openrefine.wikidata.testing.TestingData; +import org.openrefine.wikidata.testing.WikidataRefineTest; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -39,7 +40,7 @@ import com.google.refine.model.Project; import com.google.refine.model.Recon; import com.google.refine.model.recon.StandardReconConfig; -public class NewItemLibraryTest extends RefineTest { +public class NewItemLibraryTest extends WikidataRefineTest { private NewItemLibrary library; diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/exporters/QuickStatementsExporterTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/exporters/QuickStatementsExporterTest.java index 0b4968327..e93f31349 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/exporters/QuickStatementsExporterTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/exporters/QuickStatementsExporterTest.java @@ -33,6 +33,7 @@ import java.util.Properties; import org.openrefine.wikidata.schema.WikibaseSchema; import org.openrefine.wikidata.testing.TestingData; +import org.openrefine.wikidata.testing.WikidataRefineTest; import org.openrefine.wikidata.updates.ItemUpdate; import org.openrefine.wikidata.updates.ItemUpdateBuilder; import org.testng.annotations.Test; @@ -48,7 +49,7 @@ import com.google.refine.RefineTest; import com.google.refine.browsing.Engine; import com.google.refine.model.Project; -public class QuickStatementsExporterTest extends RefineTest { +public class QuickStatementsExporterTest extends WikidataRefineTest { private QuickStatementsExporter exporter = new QuickStatementsExporter(); private ItemIdValue newIdA = TestingData.newIdA; diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/exporters/SchemaExporterTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/exporters/SchemaExporterTest.java index fe535b183..28a51169d 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/exporters/SchemaExporterTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/exporters/SchemaExporterTest.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.io.StringWriter; import java.util.Properties; +import org.openrefine.wikidata.testing.WikidataRefineTest; import org.testng.annotations.Test; import com.google.refine.RefineTest; @@ -11,7 +12,7 @@ import com.google.refine.browsing.Engine; import com.google.refine.model.Project; import com.google.refine.util.TestUtils; -public class SchemaExporterTest extends RefineTest { +public class SchemaExporterTest extends WikidataRefineTest { private SchemaExporter exporter = new SchemaExporter(); diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/operations/OperationTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/operations/OperationTest.java index ca9f773e7..ae6987b02 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/operations/OperationTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/operations/OperationTest.java @@ -32,10 +32,10 @@ import java.io.StringReader; import java.io.StringWriter; import java.util.Properties; +import org.openrefine.wikidata.testing.WikidataRefineTest; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.history.Change; import com.google.refine.model.AbstractOperation; import com.google.refine.model.Project; @@ -46,7 +46,7 @@ import com.google.refine.util.TestUtils; import edu.mit.simile.butterfly.ButterflyModule; -public abstract class OperationTest extends RefineTest { +public abstract class OperationTest extends WikidataRefineTest { protected Project project = null; protected ButterflyModule module = null; diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/ExpressionContextTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/ExpressionContextTest.java index 98486812b..c0f7b5f57 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/ExpressionContextTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/ExpressionContextTest.java @@ -26,13 +26,13 @@ package org.openrefine.wikidata.schema; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; +import org.openrefine.wikidata.testing.WikidataRefineTest; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import com.google.refine.RefineTest; import com.google.refine.model.Project; -public class ExpressionContextTest extends RefineTest { +public class ExpressionContextTest extends WikidataRefineTest { Project project = null; diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbExpressionTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbExpressionTest.java index 97e69a9ce..7a84a19f9 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbExpressionTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbExpressionTest.java @@ -29,17 +29,17 @@ import java.io.Serializable; import org.openrefine.wikidata.qa.QAWarningStore; import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException; import org.openrefine.wikidata.testing.TestingData; +import org.openrefine.wikidata.testing.WikidataRefineTest; import org.testng.Assert; import org.testng.annotations.BeforeMethod; -import com.google.refine.RefineTest; import com.google.refine.model.Cell; import com.google.refine.model.ModelException; import com.google.refine.model.Project; import com.google.refine.model.Recon; import com.google.refine.model.Row; -public class WbExpressionTest extends RefineTest { +public class WbExpressionTest extends WikidataRefineTest { protected Project project; protected Row row; diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WikibaseSchemaTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WikibaseSchemaTest.java index f5965c338..3bae4d83c 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WikibaseSchemaTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WikibaseSchemaTest.java @@ -32,6 +32,7 @@ import java.util.Collections; import java.util.List; import org.openrefine.wikidata.testing.TestingData; +import org.openrefine.wikidata.testing.WikidataRefineTest; import org.openrefine.wikidata.updates.ItemUpdate; import org.openrefine.wikidata.updates.ItemUpdateBuilder; import org.testng.annotations.BeforeMethod; @@ -47,13 +48,12 @@ import org.wikidata.wdtk.datamodel.interfaces.StatementRank; import org.wikidata.wdtk.datamodel.interfaces.StringValue; import org.wikidata.wdtk.datamodel.interfaces.TimeValue; -import com.google.refine.RefineTest; import com.google.refine.browsing.Engine; import com.google.refine.browsing.EngineConfig; import com.google.refine.model.Project; import com.google.refine.util.TestUtils; -public class WikibaseSchemaTest extends RefineTest { +public class WikibaseSchemaTest extends WikidataRefineTest { private ItemIdValue qid1 = Datamodel.makeWikidataItemIdValue("Q1377"); private ItemIdValue qid2 = Datamodel.makeWikidataItemIdValue("Q865528"); diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/testing/WikidataRefineTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/testing/WikidataRefineTest.java new file mode 100644 index 000000000..93245384c --- /dev/null +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/testing/WikidataRefineTest.java @@ -0,0 +1,63 @@ +package org.openrefine.wikidata.testing; + +import static org.mockito.Mockito.mock; + +import java.io.File; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; + +import org.testng.annotations.BeforeMethod; + +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.refine.ProjectManager; +import com.google.refine.ProjectManagerStub; +import com.google.refine.ProjectMetadata; +import com.google.refine.RefineServlet; +import com.google.refine.RefineServletStub; +import com.google.refine.RefineTest; +import com.google.refine.importers.SeparatorBasedImporter; +import com.google.refine.importing.ImportingJob; +import com.google.refine.importing.ImportingManager; +import com.google.refine.model.Project; + +public class WikidataRefineTest { + protected File workspaceDir; + protected RefineServlet servlet; + private List projects = new ArrayList(); + private List importingJobs = new ArrayList(); + + public Project createCSVProject(String input) { + return createCSVProject("test project", input); + } + + protected Project createCSVProject(String projectName, String input) { + Project project = new Project(); + + ProjectMetadata metadata = new ProjectMetadata(); + metadata.setName(projectName); + + ObjectNode options = mock(ObjectNode.class); + RefineTest.prepareImportOptions(options, ",", -1, 0, 0, 1, false, false); + + ImportingJob job = ImportingManager.createJob(); + + SeparatorBasedImporter importer = new SeparatorBasedImporter(); + + List exceptions = new ArrayList(); + importer.parseOneFile(project, metadata, job, "filesource", new StringReader(input), -1, options, exceptions); + project.update(); + ProjectManager.singleton.registerProject(project, metadata); + + projects.add(project); + importingJobs.add(job); + return project; + } + + @BeforeMethod(alwaysRun = true) + public void initServlet() { + servlet = new RefineServletStub(); + ProjectManager.singleton = new ProjectManagerStub(); + ImportingManager.initialize(servlet); + } +} diff --git a/main/tests/server/src/com/google/refine/RefineTest.java b/main/tests/server/src/com/google/refine/RefineTest.java index fc65af2e4..2a57e2371 100644 --- a/main/tests/server/src/com/google/refine/RefineTest.java +++ b/main/tests/server/src/com/google/refine/RefineTest.java @@ -195,7 +195,7 @@ public class RefineTest extends PowerMockTestCase { * @param guessValueType * @param ignoreQuotes */ - private void prepareImportOptions(ObjectNode options, + public static void prepareImportOptions(ObjectNode options, String sep, int limit, int skip, int ignoreLines, int headerLines, boolean guessValueType, boolean ignoreQuotes) {