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>
</resources>
<testSourceDirectory>tests/src</testSourceDirectory>
<testResources>
<testResource>
<directory>tests/data</directory>
</testResource>
</testResources>
<outputDirectory>module/MOD-INF/classes</outputDirectory>
<plugins>
<plugin>
@ -151,6 +156,16 @@
<version>0.9.0-SNAPSHOT</version>
</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>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>

View File

@ -52,7 +52,7 @@ public class PreviewWikibaseSchemaCommandTest extends SchemaCommandTest {
@Test
public void testValidSchema()
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);
command.doPost(request, response);

View File

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

View File

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

View File

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

View File

@ -53,13 +53,13 @@ public class SaveWikibaseSchemaOperationTest extends OperationTest {
@Override
public JSONObject getJson()
throws Exception {
return TestingData.jsonFromFile("data/operations/save-schema.json");
return TestingData.jsonFromFile("operations/save-schema.json");
}
@Test
public void testLoadChange()
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/";
WikibaseSchema schema = WikibaseSchema.reconstruct(schemaJson);

View File

@ -100,7 +100,7 @@ public class WikibaseSchemaTest extends RefineTest {
@Test
public void testSerialize()
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);
StringWriter writer = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(writer);
@ -108,7 +108,7 @@ public class WikibaseSchemaTest extends RefineTest {
writer.close();
JSONObject newSerialized = ParsingUtilities.evaluateJsonStringToObject(writer.toString());
// 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());
}
@ -117,14 +117,14 @@ public class WikibaseSchemaTest extends RefineTest {
throws JSONException, IOException {
// this json file was generated by an earlier version of the software
// 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);
}
@Test
public void testEvaluate()
throws JSONException, IOException {
JSONObject serialized = TestingData.jsonFromFile("data/schema/inception.json");
JSONObject serialized = TestingData.jsonFromFile("schema/inception.json");
WikibaseSchema schema = WikibaseSchema.reconstruct(serialized);
Engine engine = new Engine(project);
List<ItemUpdate> updates = schema.evaluate(project, engine);
@ -146,7 +146,7 @@ public class WikibaseSchemaTest extends RefineTest {
@Test
public void testEvaluateRespectsFacets()
throws JSONException, IOException {
JSONObject serialized = TestingData.jsonFromFile("data/schema/inception.json");
JSONObject serialized = TestingData.jsonFromFile("schema/inception.json");
WikibaseSchema schema = WikibaseSchema.reconstruct(serialized);
Engine engine = new Engine(project);
JSONObject engineConfig = new JSONObject("{\n" + " \"mode\": \"row-based\",\n" + " \"facets\": [\n"

View File

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