Unify JSON testing in Wikidata extension

This commit is contained in:
Antonin Delpeuch 2018-10-12 15:32:41 +01:00
parent 0698b9c84e
commit 1c34b237e4
2 changed files with 5 additions and 13 deletions

View File

@ -31,6 +31,7 @@ import java.util.Properties;
import org.json.JSONObject;
import org.openrefine.wikidata.schema.WikibaseSchema;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.refine.history.Change;
@ -42,7 +43,8 @@ import com.google.refine.util.Pool;
public class SaveWikibaseSchemaOperation extends AbstractOperation {
final public String operationDescription = "Save Wikibase schema";
@JsonIgnore
final public static String operationDescription = "Save Wikibase schema";
@JsonProperty("schema")
final protected WikibaseSchema _schema;

View File

@ -33,6 +33,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.refine.tests.util.TestUtils;
import com.google.refine.util.ParsingUtilities;
public class JacksonSerializationTest {
@ -44,7 +45,7 @@ public class JacksonSerializationTest {
try {
String actualJson = ParsingUtilities.defaultWriter.writeValueAsString(pojo);
assertJsonEquals(expectedJson, actualJson);
TestUtils.assertEqualAsJson(expectedJson, actualJson);
} catch (JsonProcessingException e) {
e.printStackTrace();
Assert.fail("Failed to serialize object");
@ -68,15 +69,4 @@ public class JacksonSerializationTest {
testSerialize(pojo, json);
testDeserialize(targetClass, pojo, json);
}
public static void assertJsonEquals(String expectedJson, String actualJson) {
JsonNode parsedExpectedJson;
try {
parsedExpectedJson = mapper.readValue(expectedJson, JsonNode.class);
JsonNode parsedActualJson = mapper.readValue(actualJson, JsonNode.class);
assertEquals(parsedExpectedJson, parsedActualJson);
} catch (IOException e) {
Assert.fail("Invalid JSON");
}
}
}