Fix Wikidata extension testing for Maven

This commit is contained in:
Antonin Delpeuch 2018-09-10 11:27:14 +01:00
parent 60d4656176
commit 2f2fa86800
8 changed files with 30 additions and 13 deletions

View File

@ -24,6 +24,11 @@
</resource> </resource>
</resources> </resources>
<testSourceDirectory>tests/src</testSourceDirectory> <testSourceDirectory>tests/src</testSourceDirectory>
<testResources>
<testResource>
<directory>tests/data</directory>
</testResource>
</testResources>
<outputDirectory>module/MOD-INF/classes</outputDirectory> <outputDirectory>module/MOD-INF/classes</outputDirectory>
<plugins> <plugins>
<plugin> <plugin>
@ -151,6 +156,16 @@
<version>0.9.0-SNAPSHOT</version> <version>0.9.0-SNAPSHOT</version>
</dependency> </dependency>
<!-- testing dependencies -->
<dependency>
<groupId>org.openrefine</groupId>
<artifactId>main</artifactId>
<version>3.0-SNAPSHOT</version>
<classifier>tests</classifier>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.testng</groupId> <groupId>org.testng</groupId>
<artifactId>testng</artifactId> <artifactId>testng</artifactId>

View File

@ -52,7 +52,7 @@ public class PreviewWikibaseSchemaCommandTest extends SchemaCommandTest {
@Test @Test
public void testValidSchema() public void testValidSchema()
throws JSONException, IOException, ServletException { throws JSONException, IOException, ServletException {
String schemaJson = jsonFromFile("data/schema/inception.json").toString(); String schemaJson = jsonFromFile("schema/inception.json").toString();
when(request.getParameter("schema")).thenReturn(schemaJson); when(request.getParameter("schema")).thenReturn(schemaJson);
command.doPost(request, response); command.doPost(request, response);

View File

@ -44,7 +44,7 @@ public class SaveWikibaseSchemaCommandTest extends SchemaCommandTest {
@Test @Test
public void testValidSchema() public void testValidSchema()
throws ServletException, IOException { throws ServletException, IOException {
String schemaJson = jsonFromFile("data/schema/inception.json").toString(); String schemaJson = jsonFromFile("schema/inception.json").toString();
when(request.getParameter("schema")).thenReturn(schemaJson); when(request.getParameter("schema")).thenReturn(schemaJson);
command.doPost(request, response); command.doPost(request, response);

View File

@ -70,7 +70,7 @@ public class QuickStatementsExporterTest extends RefineTest {
throws JSONException, IOException { throws JSONException, IOException {
Project project = this.createCSVProject(TestingData.inceptionWithNewCsv); Project project = this.createCSVProject(TestingData.inceptionWithNewCsv);
TestingData.reconcileInceptionCells(project); TestingData.reconcileInceptionCells(project);
JSONObject serialized = TestingData.jsonFromFile("data/schema/inception.json"); JSONObject serialized = TestingData.jsonFromFile("schema/inception.json");
WikibaseSchema schema = WikibaseSchema.reconstruct(serialized); WikibaseSchema schema = WikibaseSchema.reconstruct(serialized);
project.overlayModels.put("wikibaseSchema", schema); project.overlayModels.put("wikibaseSchema", schema);
Engine engine = new Engine(project); Engine engine = new Engine(project);

View File

@ -53,7 +53,7 @@ public class PerformWikibaseEditsOperationTest extends OperationTest {
@Override @Override
public JSONObject getJson() public JSONObject getJson()
throws Exception { throws Exception {
return TestingData.jsonFromFile("data/operations/perform-edits.json"); return TestingData.jsonFromFile("operations/perform-edits.json");
} }
@Test(expectedExceptions=IllegalArgumentException.class) @Test(expectedExceptions=IllegalArgumentException.class)

View File

@ -53,13 +53,13 @@ public class SaveWikibaseSchemaOperationTest extends OperationTest {
@Override @Override
public JSONObject getJson() public JSONObject getJson()
throws Exception { throws Exception {
return TestingData.jsonFromFile("data/operations/save-schema.json"); return TestingData.jsonFromFile("operations/save-schema.json");
} }
@Test @Test
public void testLoadChange() public void testLoadChange()
throws Exception { throws Exception {
JSONObject schemaJson = TestingData.jsonFromFile("data/schema/inception.json"); JSONObject schemaJson = TestingData.jsonFromFile("schema/inception.json");
String changeString = "newSchema=" + schemaJson.toString() + "\n" + "oldSchema=\n" + "/ec/"; String changeString = "newSchema=" + schemaJson.toString() + "\n" + "oldSchema=\n" + "/ec/";
WikibaseSchema schema = WikibaseSchema.reconstruct(schemaJson); WikibaseSchema schema = WikibaseSchema.reconstruct(schemaJson);

View File

@ -100,7 +100,7 @@ public class WikibaseSchemaTest extends RefineTest {
@Test @Test
public void testSerialize() public void testSerialize()
throws JSONException, IOException { throws JSONException, IOException {
JSONObject serialized = TestingData.jsonFromFile("data/schema/history_of_medicine.json"); JSONObject serialized = TestingData.jsonFromFile("schema/history_of_medicine.json");
WikibaseSchema parsed = WikibaseSchema.reconstruct(serialized); WikibaseSchema parsed = WikibaseSchema.reconstruct(serialized);
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(writer); JSONWriter jsonWriter = new JSONWriter(writer);
@ -108,7 +108,7 @@ public class WikibaseSchemaTest extends RefineTest {
writer.close(); writer.close();
JSONObject newSerialized = ParsingUtilities.evaluateJsonStringToObject(writer.toString()); JSONObject newSerialized = ParsingUtilities.evaluateJsonStringToObject(writer.toString());
// toString because it looks like JSONObject equality isn't great // toString because it looks like JSONObject equality isn't great
assertEquals(TestingData.jsonFromFile("data/schema/history_of_medicine_normalized.json").toString(), assertEquals(TestingData.jsonFromFile("schema/history_of_medicine_normalized.json").toString(),
newSerialized.toString()); newSerialized.toString());
} }
@ -117,14 +117,14 @@ public class WikibaseSchemaTest extends RefineTest {
throws JSONException, IOException { throws JSONException, IOException {
// this json file was generated by an earlier version of the software // this json file was generated by an earlier version of the software
// it contains extra "type" fields that are now ignored. // it contains extra "type" fields that are now ignored.
JSONObject serialized = TestingData.jsonFromFile("data/schema/roarmap.json"); JSONObject serialized = TestingData.jsonFromFile("schema/roarmap.json");
WikibaseSchema.reconstruct(serialized); WikibaseSchema.reconstruct(serialized);
} }
@Test @Test
public void testEvaluate() public void testEvaluate()
throws JSONException, IOException { throws JSONException, IOException {
JSONObject serialized = TestingData.jsonFromFile("data/schema/inception.json"); JSONObject serialized = TestingData.jsonFromFile("schema/inception.json");
WikibaseSchema schema = WikibaseSchema.reconstruct(serialized); WikibaseSchema schema = WikibaseSchema.reconstruct(serialized);
Engine engine = new Engine(project); Engine engine = new Engine(project);
List<ItemUpdate> updates = schema.evaluate(project, engine); List<ItemUpdate> updates = schema.evaluate(project, engine);
@ -146,7 +146,7 @@ public class WikibaseSchemaTest extends RefineTest {
@Test @Test
public void testEvaluateRespectsFacets() public void testEvaluateRespectsFacets()
throws JSONException, IOException { throws JSONException, IOException {
JSONObject serialized = TestingData.jsonFromFile("data/schema/inception.json"); JSONObject serialized = TestingData.jsonFromFile("schema/inception.json");
WikibaseSchema schema = WikibaseSchema.reconstruct(serialized); WikibaseSchema schema = WikibaseSchema.reconstruct(serialized);
Engine engine = new Engine(project); Engine engine = new Engine(project);
JSONObject engineConfig = new JSONObject("{\n" + " \"mode\": \"row-based\",\n" + " \"facets\": [\n" JSONObject engineConfig = new JSONObject("{\n" + " \"mode\": \"row-based\",\n" + " \"facets\": [\n"

View File

@ -24,10 +24,12 @@
package org.openrefine.wikidata.testing; package org.openrefine.wikidata.testing;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Collections; import java.util.Collections;
import org.apache.commons.io.IOUtils;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.openrefine.wikidata.schema.WbLanguageConstant; import org.openrefine.wikidata.schema.WbLanguageConstant;
@ -133,8 +135,8 @@ public class TestingData {
public static JSONObject jsonFromFile(String filename) public static JSONObject jsonFromFile(String filename)
throws IOException, JSONException { throws IOException, JSONException {
byte[] contents = Files.readAllBytes(Paths.get(filename)); InputStream f = TestingData.class.getClassLoader().getResourceAsStream(filename);
String decoded = new String(contents, "utf-8"); String decoded = IOUtils.toString(f);
return ParsingUtilities.evaluateJsonStringToObject(decoded); return ParsingUtilities.evaluateJsonStringToObject(decoded);
} }